1

Markdown and its different flavours have a number of interesting extensions, notably the [hl_lines attribute][0], which allows to highlight specific lines in a fenced code block, as illustrated here and here. This feature has actually been implemented in ox-hugo (export of org to Hugo-compatible markdown) by "hacking the org-babel-exp-code".


What I am trying to do is the following:

1. specify arbitrary attributes in a code block

I can't find anything in the documentation for org-mode or emacs about adding arbitrary attributes to a code block through some kind of header. The kind of syntax I would have expected:

#+begin_src python attr:"hl_lines='2'"
#+begin_src python :hl_line "2"
#+attr_markdown: :hl_lines 2
#+begin_src: python
2. export an org file to Markdown (either through org-md-export-to-markdown or org-pandoc-export-to-markdown/commonmark/etc.) in a way that keeps the attributes

pandoc does not support hl_lines, and cuts off anything that comes after python in #+begin_src python .... when exporting (tried both from emacs and from the pandoc CLI).

To be clear, I am trying to find a solution in pandoc to avoid having to deal with the many idiosyncrasies of org-md-export-to-markdown I have to face with my specific files.

3. deploy the Markdown files through a service that can understand the hl_line attribute

This last step is solved.


Is implementing this feature in pandoc the only way or is there some workaround I haven't found?

harabat
  • 31
  • 5

1 Answers1

0

I solved this issue by writing a pandoc filter that inserts any custom parameters into the markdown output. The code and the shell command are available here: Keep custom code block attributes in pandoc when converting to Markdown.

In theory, I can run org-pandoc-export-to-commonmark and specify my filter as a command option in the org file with the line below:

#+PANDOC_OPTIONS: filter:/full/path/to/pandoc/filters/keep_attributes_markdown.py

However, even though the command runs correctly and the filter is supposedly used, the output still corresponds to what it would be without the filter, but this is a separate bug that I will raise in https://github.com/kawabata/ox-pandoc.

harabat
  • 31
  • 5