Reputation: 7142
I'm trying to write a code-block in Coq
(long story :)) inside pandoc
.
$ pandoc --list-highlight-languages | grep coq | wc -l
0
Since it doesn't exist, I wonder if there is an option to write my own user-defined code-block-language?
Upvotes: 1
Views: 1172
Reputation: 7142
For completeness reasons, I am pasting a minimal xml
syntax file for an html slideshow generated from a markdown file with pandoc. It is made as a skeleton for anyone writing a dsl and wants to easily mark specific words in a code block. See here many full syntax examples
<?xml version="1.0" encoding="UTF-8"?>
<language name="coq" extensions="*.v" indenter="haskell">
<highlighting>
<list name="kw_major">
<item>induction</item>
<item>Fixpoint</item>
<item>Theorem</item>
<item>Qed</item>
</list>
<list name="kw_minor">
<item>exists</item>
<item>forall</item>
<item>nat</item>
</list>
<contexts>
<context name="Normal" attribute="Normal" lineEndContext="#stay">
<keyword attribute="KwMajor" context="#stay" String="kw_major" />
<keyword attribute="KwMinor" context="#stay" String="kw_minor" />
<Int attribute="Decimal" context="#stay" />
<DetectChar attribute="String" context="String" char=""" />
</context>
<context name="String" attribute="String" lineEndContext="StringSyntaxError" >
<DetectChar attribute="String" context="#pop" char=""" />
<RegExpr attribute="String" context="#stay" String="[^"]*" />
</context>
</contexts>
<itemDatas>
<itemData name="KwMajor" defStyleNum="dsDataType"/>
<itemData name="KwMinor" defStyleNum="dsKeyword"/>
<itemData name="Decimal" defStyleNum="dsDecVal"/>
<itemData name="String" defStyleNum="dsString"/>
</itemDatas>
</highlighting>
<general><keywords casesensitive="1" /></general>
</language>
Upvotes: 0
Reputation: 22609
The answer depends a little on the output format that's being targeted. The most general solution is to define a syntax definition. Pandoc can parse XML syntax definitions for the Kate editor, see https://docs.kde.org/stable5/en/kate/katepart/highlight.html for more info on the format. If you have such an XML file, then pass it to pandoc via the --syntax-definition
command line option.
If the output format is LaTeX (or PDF via LaTeX), then using pandoc with the --listing
option should work, esp. when combined with the tips mentioned here:
https://tex.stackexchange.com/q/434523/
Likewise, minted can be used for highlighting, see the minted.lua filter.
Last but not least, using an external syntax highlighter would be possible via a filter. Lua filters are well suited for that task, as they do not require an additional tool-chain to be installed.
Upvotes: 2
Reputation: 33464
The pandoc
executable can be extended with custom filters: https://pandoc.org/filters.html
And for transforming Pandoc
documents directly in Haskell (without going through filters), a useful thing is the traversal Text.Pandoc.Walk.walkM
and other related functions in pandoc-types
.
For example I've used that in hakyll-alectryon
to process Coq code blocks using pandoc, in Hakyll.
Upvotes: 2