developit / snarkdown

:smirk_cat: A snarky 1kb Markdown parser written in JavaScript
http://jsfiddle.net/developit/828w6t1x/
MIT License
2.29k stars 109 forks source link

JS Syntax Highlighting #79

Closed mesqueeb closed 4 years ago

mesqueeb commented 5 years ago

Hey! I love this small footprint!!

I'd love to be able to write: ```js console.log() // etc. ``` with javascript code and have syntax highlighting for the code block. ;)

I researched a bit and found out I'd need to use Prism https://prismjs.com

Is it possible to add a small example to the readme to show the best practice of how this could be done? 😄

Thanks so much!!

mesqueeb commented 5 years ago

I did some more research, and PrismJS is very bad at automatic treeshaking... It says you need an extra "babel-plugin-prismjs" to make the package smaller with just what you need...

image
tomByrer commented 4 years ago

You could just post-process the resulting HTML? You need to add a class="language-js" to each <code> block. Then read the "Usage with CDNs" section. I recommend jsDelivr, sin CDNjs future is up in the air.

mesqueeb commented 4 years ago

@tomByrer I'm not sure about CDN's I rather package my libraries together with the app via webpack. But if prismjs doesn't support simple tree-shaking, that's such a bummer. :D because it'll get big you see?

mesqueeb commented 4 years ago

@tomByrer how to add class="language-js" to the <pre> blocks that snarkdown gives?