[kramdown-users] Syntax for specifying code highlighting language | Github flavored code blocks style

Matt Neuburg matt at tidbits.com
Fri Aug 31 16:07:23 UTC 2012


I am someone who uses kramdown's fenced code block style and I agree with all three points: make no change to backticks, and go ahead and implement the other changes, even if there is breakage with "lang". m.

On Aug 31, 2012, at 7:17 AM, Thomas Leitner wrote:

> Hi everybody,
> 
> there is a [pull request][1] on Github which, among other things, wants
> to add 1) support for Github flavored code style and 2) support for
> setting the highlighting language on the delimiter line of a fenced code
> block.
> 
> [1]: https://github.com/gettalong/kramdown/pull/15
> 
> I also want to talk 3) about the current way of setting the highlighting
> language.
> 
> 
> ad 1) kramdown already has a fenced code block style:
> 
>    ~~~
>    some code here
>    ~~~
> 
> Github flavored code blocks use a backtick instead:
> 
>    ```
>    some code here
>    ```
> 
> I personally don't think that it is necessary or even good in this
> case to provide another syntax for fenced code blocks. Using the
> backtick currently only works on the Github website itself, as far as I
> know.
> 
> Also note that the kramdown (and php-markdown-extra and
> python-markdown) fenced code blocks *do* work on Github, too!
> 
> So, what do you think?
> 
> 
> ad 2) Providing the syntax highlighting language on the delimiter line
> is a rather nice idea and not only supported by Github but also by
> other markdown implementations (like python-markdown). It would look
> like this:
> 
>    ~~~~~~ ruby
>    class MyRuby
>    end
>    ~~~~~~~~~~~~
> 
> I would like to integrate this into kramdown -- does anyone have good
> reasons for not using this syntax?
> 
> 
> ad 3) The syntax highlighting language can currently be set by using an
> IAL to specify the attribute `lang`. However, the `lang` attribute in
> HTML elements is generally used for setting the natural language of the
> text inside an element...
> 
> I'm for removing this collision by following the HTML5 way of
> specifying the highlighting language, which is setting the class
> `language-CODELANG` on the `<code>` element.
> 
> This would mean that this kramdown document:
> 
>    ~~~
>    some code here
>    ~~~
>    {: .language-ruby .other attr="key"}
> 
> would be transformed to this HTML output (in case coderay was not used):
> 
>    <pre attr="key" class="other"><code class="language-ruby">some code here
>    </code></pre>
> 
> Note that the `language-ruby` class is set on the `<code>` element and
> not on the parent `<pre>` element!
> 
> This would be a backwards-incompatible change, what do you think?
> 
> 
> Best regards,
>  Thomas
> _______________________________________________
> kramdown-users mailing list
> kramdown-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/kramdown-users



More information about the kramdown-users mailing list