marky-markdown icon indicating copy to clipboard operation
marky-markdown copied to clipboard

GFM code blocks

Open fmvilas opened this issue 9 years ago • 4 comments

Hi, I think it would be nice to convert this:

```js

into a code block with a class called lang-js, for instance:

<code class="lang-js">
...
</code>

I'm trying to do syntax highlighting, but don't want to use the built-in one. Instead I prefer to use highlight.js. Even this library has an automatic language detection feature, it doesn't work properly all the time, so it took me to this feature request.

What do you think? If it sounds good I can submit a PR.

fmvilas avatar Oct 21 '16 19:10 fmvilas

@ashleygwilliams this one's up to you; it's not really github compat work, but it's also not hard to add to the case where marky's options are overridden with highlightSyntax: false, because we currently generate <pre><code>...</code></pre> in that case, and the markdown-it plugin required to add the class="lang-foo" attribute would be pretty straightforward.

revin avatar Oct 21 '16 19:10 revin

hi @fmvilas - our product roadmap consists solely in mimicking exactly what GitHub does. since github does not do this (AFAIK) this is out of scope for the project. is there a reason the highlighting that marky provides is not sufficient?

ashleygwilliams avatar Oct 21 '16 19:10 ashleygwilliams

The reason I'm not using it in my project is because we already have highlight.js all around, and we don't want to have two different highlighting libraries. In my opinion that's something that should be open to be overridden, because there are better libraries doing just that.

On the other hand, this is a feature that Github has, you can specify language this way. For instance, if you inspect my HTML example in the previous comment you will see the block has these classes: highlight highlight-text-html-basic.

Having the classes will enable people to choose another highlighting system, but it will also allow different sorts of use cases (not only CSS related). As an example, someone could add a "Run this code" button on every JS code piece. And the cool think is that if you just want to ignore this classes it will not break backward compatibility nor anything in the place the code is included.

fmvilas avatar Oct 21 '16 19:10 fmvilas

Ok! You've convinced me @fmvilas - we'd love a PR for something that mimic'd the exact behavior of GitHub highlighting :) thank you for bringing this up!

ashleygwilliams avatar Oct 21 '16 19:10 ashleygwilliams