Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using custom highlight style (.theme file) not working #6704

Closed
pck1980 opened this issue Sep 27, 2020 · 15 comments
Closed

Using custom highlight style (.theme file) not working #6704

pck1980 opened this issue Sep 27, 2020 · 15 comments

Comments

@pck1980
Copy link

pck1980 commented Sep 27, 2020

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?

@jgm
Copy link
Owner

jgm commented Sep 28, 2020

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

@jgm
Copy link
Owner

jgm commented Sep 28, 2020

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?

@jgm
Copy link
Owner

jgm commented Sep 28, 2020

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?

@pck1980
Copy link
Author

pck1980 commented Sep 28, 2020

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

@tarleb
Copy link
Collaborator

tarleb commented Sep 28, 2020

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?

@pck1980
Copy link
Author

pck1980 commented Sep 28, 2020

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.

@tarleb
Copy link
Collaborator

tarleb commented Sep 28, 2020

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.

@jgm
Copy link
Owner

jgm commented Sep 28, 2020

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.

@caressofsteel
Copy link

I ran into this issue today. I converted to UTF-8 with Powershell as per the docs but Pandoc stil reports "Could not read the highlighing theme X". Working with Markdown to PDF with Pandoc has been like hiking through 5ft of snow. It's no supposed to be this hard or this bad.

pandoc.exe 2.11.4
Compiled with pandoc-types 1.22, texmath 0.12.1, skylighting 0.10.2,
citeproc 0.3.0.5, ipynb 0.1.0.1

@jgm
Copy link
Owner

jgm commented Feb 17, 2021

@caressofsteel - can you upload your custom theme so we can test with it?
With the OP's issue, the problem was UTF-8 encoding, but your custom theme may have a different problem.

@GiuseppeDiPalma
Copy link

GiuseppeDiPalma commented May 1, 2021

I have the same problem too.
Reading here I converted my file from utf-16 to utf-8, but the problem still persists:
Could not read highlighting theme testMyStyleUTF8.theme

I run this command:
pandoc file.md --highlight-style testMyStyleUTF8.theme -o file.html

pandoc --version:(windows10)

pandoc.exe 2.13
Compiled with pandoc-types 1.22, texmath 0.12.2, skylighting 0.10.5,
citeproc 0.3.0.9, ipynb 0.1.0.1

@jgm
Copy link
Owner

jgm commented May 3, 2021

If you upload the file we can take a look.

@GiuseppeDiPalma
Copy link

These are the two files. The first one created is in utf16, the second is converted to utf8:

files.zip

@jgm
Copy link
Owner

jgm commented May 4, 2021

The problem is that your file has a BOM (byte order mark) at the beginning:

testMyStyleUTF8.theme: UTF-8 Unicode (with BOM) text, with CRLF line terminators

The BOM is illegal in JSON (see e.g. https://stackoverflow.com/questions/4990095/json-specification-and-usage-of-bom-charset-encoding). If you remove it, this theme will work.
I was able to remove it by copying the text and saving as a separate file in my editor (which does not use a BOM). If your editor is inserting a BOM, you'll have to find an option to disable that.

@GiuseppeDiPalma
Copy link

Thank you very much, I copied and pasted in notepad++ and then copied again in VSCode, and now it works 💯

@jgm jgm closed this as completed May 6, 2021
yakatz added a commit to yakatz/pandoc that referenced this issue Sep 18, 2024
Suggest documentation to preemptively address user issues like jgm#6704
yakatz added a commit to yakatz/pandoc that referenced this issue Sep 18, 2024
Suggest documentation to preemptively address user issues like jgm#6704
yakatz added a commit to yakatz/pandoc that referenced this issue Sep 18, 2024
Suggest documentation to preemptively address user issues like jgm#6704
yakatz added a commit to yakatz/pandoc that referenced this issue Sep 18, 2024
Suggest documentation to preemptively address user issues like jgm#6704
jgm pushed a commit that referenced this issue Sep 18, 2024
Suggest documentation to preemptively address user issues like #6704
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants