Denis Kreshikhin


software development, computer science

2021 © Denis Kreshikhin

Sharing a code through social networks

There is a problem with formatting code in social networks. If you pass a piece of code ass a message, as result, you'll see a corrupted code with smiles and wrong indents.

This is an attempt to solve the problem by a web service which created by me for transforming a piece of code to a link with an image.


At first, I've written a small library code2image] which allows to create an image based on a piece of code.

var code = "var hello = 'hello';"

var styles = {}; // all are default

code2image.render(code, 'test.png', styles,

The result of execution:


Main dependencies of the libary is hightlight-js and node-canvas.

Because hightlight-js recognize a code not very well I've written also a library which uses Bayesian classifier tolmach implemented in natural. This approach works a little better.

The web service is lightweight wrapper of a library code2image which allows to place a piece of code and take a image with formatted and highlighted code. This image can be posted in social networks as typical media message.