3 ms·
If you're looking for this, but with an API, I built https://sourcecodeshots.com https://sourcecodeshots.com to power syntax highlighting and Open Graph images
by dwwoelfel 6y ago
If you're looking for this, but with an API, I built https://sourcecodeshots.com https://sourcecodeshots.com to power syntax highlighting and Open Graph images of code for https://essay.dev https://essay.dev.
I initially used carbon.now.sh, but they don't have an API, and the community-provided API is pretty slow because it uses a headless browser to generate the image.
Source Code Shots uses VSCode's syntax-highlighting engine, so the highlighting is about as good as you can get and I can fully support a lot of languages that CodeMirror or Highlight.js haven't gotten to.
The docs, https://sourcecodeshots.com/docs https://sourcecodeshots.com/docs, have plenty of examples of how to use it as an API. You can email me at daniel@onegraph.com if there's something you need that it doesn't support.
- notafraudster 6y agoThis is pretty cool but I notice the default R fibonacci code is like comically non-idiomatic (or poorly linted, even). Since I suspect the cause here is copy-pasting off of an algorithms/code gallery, my guess is that there are examples across other languages. I checked everything I feel idiomatically comfortable enough and the others all seemed fine, but there are a lot of options here so who knows.
- dwwoelfel 6y agoIf you have a good recursive version of Fibonacci for R, I'd love to swap it out for what I currently have. For the languages I don't know, I looked at the code people posted on rosettacode.org
- deleted 6y ago[deleted]
- solopov 6y agoHow do you create images without a headless browser?
- vermilingua 6y agoPoe’s Law hard at work here.
- dwwoelfel 6y agoThere are lots of different approaches you could take. For sourcecodeshots, I run it through VSCode's tokenizer (https://github.com/microsoft/vscode-textmate https://github.com/microsoft/vscode-textmate) and then use node-canvas to generate the image one line at a time. It's a very imperative process and fairly slow on a cpu, but the nice thing is that I can run the same code in the browser to speed up development. The Rust project, https://github.com/Aloxaf/silicon https://github.com/Aloxaf/silicon, mentioned in another part of the comments is probably faster, but I didn't find it when I was searching for a solution.
- amelius 6y agoWhat's the reason for the sideways traffic light in the top bar? Is it part of the final image?
- dwwoelfel 6y agoIt's supposed to resemble a mac app window. I can add a setting to remove it if you like. Email me at daniel@onegraph.com and I'll let you know when it's available.