Background
Looking to apply syntax highlighting to source code snippets embedded within XHTML code elements, demarcated with a class attribute to indicate the language.
Using:
mtx-context | current version: 2021.11.30 19:49
Note: The XHTML is produced from a Markdown document, such as:
Here is an XML snippet:
<import src="constants.xml" />
<device type="web" uri="HOST">
<form ... />
</device>
Here is a Java snippet:
import java.net.*;
public class JavaClass {
// ...
}
Problem
There are a couple of issues:
- Calling
\xmlflushspacewise{#1}does not seem to afford the ability to apply syntax highlighting to the nested source code snippet. - Applying syntax highlighting dynamically based on the
codeelement'sclass, which follows the form "language-X" where X could be any well-known programming language (xml,python,java,ruby,javascript, and others).
Code
The following example typesets the source code snippet as expected:
\startbuffer[html]
<html>
<body>
<pre>
<code class="language-xml"><import src="constants.xml" />
<import src="tests/login.xml" />
<device type="web" uri="HOST">
<click id="device" />
<form id="upload-file">
<assign id="firmware" value="FILENAME.fw" />
<click id="upload-file-button" />
</form>
</device>
</code>
</pre>
</body>
</html>
\stopbuffer
\startxmlsetups xml:initialize
\xmlsetsetup{#1}{}{-}
\xmlsetsetup{#1}{html|body|pre|code}{xml:}
\stopxmlsetups
\xmlregistersetup{xml:initialize}
\startxmlsetups xml:html
\startdocument
\xmlflush{#1}
\stopdocument
\stopxmlsetups
\startxmlsetups xml:body
\xmlflush{#1}
\stopxmlsetups
\startxmlsetups xml:pre
\xmlflush{#1}
\stopxmlsetups
\startxmlsetups xml:code
\xmlflushspacewise{#1}
\stopxmlsetups
\xmlprocessbuffer{main}{html}{}
This produces:
Question
How would you apply syntax highlighting to the output in a way that is agnostic with respect to the code snippet language being coloured?
As a bonus, is it possible to do in a cross-platform way (that is, not relying on vim)?

vimmust be installed on all platforms and, presumably, its executable directory added to the PATH. Installation a bit painful on Windows, especially if you need to get IT's permission to install executables (self-contained versions notwithstanding). – Dave Jarvis Jul 29 '22 at 18:29