Pandoc: Using custom highlight style (.theme file) not working

Created on 27 Sep 2020  路  8Comments  路  Source: jgm/pandoc

pandoc exits with error when using a custom theme file, even when it's the unmodified output of --print-highlight

PS C:\test> pandoc --print-highlight kate > k.theme
PS C:\test> pandoc --highlight-style k.theme
Could not read highlighting theme k.theme

There's a different error message if the file does not exist, so it seems pandoc is unable to correctly parse it.

PS C:\test> pandoc --version
pandoc.exe 2.10.1
Compiled with pandoc-types 1.21, texmath 0.12.0.2, skylighting 0.8.5
[...]

Perhaps similar to issue #4133?

enhancement windows

All 8 comments

Hm, I cannot reproduce this. Maybe it works on non-windows platforms but not on windows?

One thing to check would be whether k.theme has CRLF line endings.
If so, does it help to change to LF line endings?
If not, does it help to change to CRLF line endings?

We just use aeson ToJSOn/FromJSON instances to parse and render the styles as themes, so it's hard to see how line endings could be mishandled. But I'm at a loss as to what else could be going wrong, without being able to reproduce. Does k.theme look okay? Can you upload it?

I just tried to use LF endings instead of CRLF, but with no success. Attached are both versions of the exported theme.
k.zip

The files seem to use the UTF-16 encoding, which is the default on Windows, while pandoc expects all input to use UTF-8. Can you try to convert your files with the methods described in this answer?

Converting the theme file to UTF-8 does indeed solve the problem. Thank you for your help.

Perhaps pandoc could print out a more helpful error message when it is provided with UTF-16 encoded input.

Maybe we could also support the -o/--output option to redirect the output of --print-highlighting-style. That should prevent this kind of problem for Windows users.

The problem is that we are passing a bytestring to aeson's eitherDecode function.

It does return an error message in this case, but it's so useless that we don't print it: "Error in $: Failed reading: not a valid json value." It would be nice if aeson reported that the input was not properly encoded, but it doesn't work that way.

@tarleb it does already work with --output; however, note the following from the manual:
"This option may be used with -o/--output to redirect output to a file, but -o/--output must come before --print-highlight-style on the command line." This is because pandoc immediately exits (and does no further option processing) after printing the theme.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

brainchild0 picture brainchild0  路  66Comments

jgm picture jgm  路  51Comments

elliottslaughter picture elliottslaughter  路  44Comments

jgm picture jgm  路  117Comments

dashed picture dashed  路  107Comments