simov / markdown-viewer

Markdown Viewer / Browser Extension
MIT License
1.01k stars 131 forks source link

[Feature Request] add highlight.js to auto detect code language #236

Open badrelmers opened 2 months ago

badrelmers commented 2 months ago

Hi, PrismJS does not autodetect code language https://github.com/PrismJS/prism/issues/1313 can you add an option to select between PrismJS and https://highlightjs.org/ because highlightjs can auto detect the language. if you do not like this idea can you please at least add the trick described here to add autodetect to PrismJS? it is only 3 lines of code:

<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/11.5.1/highlight.min.js"></script>
<script>
    document.addEventListener("DOMContentLoaded", function () {
        hljs.highlightAll();
    })
</script>

i open a lot of markdown files with code snippets without a defined language so autodetection will help a lot with that.

simov commented 2 months ago

Thanks for the feedback. I did not think about that use case. I thought that using fenced code blocks with language labels was something that most people do.

badrelmers commented 2 months ago

Thank you for looking into this.

I thought that using fenced code blocks with language labels was something that most people do.

Yes this is true when i create the markdown my self, but in general and most cases i just copy already made snippets found in internet which in a lot of cases does not include the language tag, see this example: say for example i found an interesting code in some site that i want to save as markdown, so i use Copy as Markdown , it is able to add the language if the site use language-* class, but a lot of sites does not add it or use a different class , see for example this mozilla snippet they use brush: js , so Copy as Markdown will create a fenced code without the language. this happens in a lot of sites so you end up with a lot of code snippets without language tag.