pandoc / lua-filters

A collection of lua filters for pandoc
MIT License
602 stars 165 forks source link

Add commonmark-code-blocks filter for producing CommonMark-suggested HTML for fenced code blocks #224

Open dmbaturin opened 2 years ago

dmbaturin commented 2 years ago

Pandoc's implementation of CommonMark code block rendering differs from that suggested by the spec and used by most other Markdown convertors.

The suggested behavior is to output <code class="language-$lang">, while Pandoc omits the language- prefix, which may cause problems for syntax highlighters that rely on that spec-suggested behavior.

I made a simple filter to bring the code block rendering in line with the spec and other implementations.

It's used in one of my project's website build process for example, where pandoc is used as a Markdown to HTML convertor, but syntax highlighting is delegated to an external tool, and *[class^="language-"] CSS selector is used to find code elements with language specified.

dmbaturin commented 2 years ago

Tests do pass in my environment (Fedora 35), so I'll need to find why the diff behavior is different in the CI container. I'll look into it today or tomorrow.

dmbaturin commented 2 years ago

Ok, found the issue. The cause was my use of DIFF ?= in the Makefile (which I copied from another Makefile in the same repo, which made me think it's a safe thing to do). In reality it wasn't because DIFF is set to diff -u globally in the container environment, so my options to ignore whitespace changes and trailing newlines were ignored.

I verified that the test passes in the docker test image.

tarleb commented 2 years ago

Thank you for this useful filter. We are currently not merging any new filters into this repo, please see #207 for details.

dmbaturin commented 2 years ago

@tarleb Maybe it's a good idea to add that information to the README and to CONTRIBUTING.md so that no one tries to open new pull requests.

There's no decision regarding the future structure yet?