PDF Export - Code Blocks Unreadable


I have recently started using Obsidian and I’m loving it so far! Much better than CherryTree that I was using before!

I use the application in the Dark theme (out of the box Obsidian, I have no additional or custom themes applied), because it is much easier on my eyes. However, doing so results in an issue when exporting my Obsidian files to PDF.

Currently, when I export a file to PDF that has a code block in it (marked with the <pre> and </pre> tags, the content is unreadable - this is because the PDF emulates the dark theme from the application and therefore makes the code block black (black text on black background).
(Similar situation to this post: PDF Export with Black Text just not using the Atom theming)

If I change the application theme to Light, this code block becomes readable (black text on slightly grey background).

Format of code in Obsidian Editor
This is what the page looks like in the Obsidian editor:

Format of the code block in exported PDF
This is what the code block looks like in the exported PDF:

Format of the code block in Obsidian Light Theme
If I change the Obsidian theme to “Light” and then export the PDF, the code block reads perfectly:

Is there a config change or something that I can make on PDF export, to export all code blocks (and any inline code marked with the back ticks (`)) in the light theme, but keep the dark theme within the editor?

Thanks very much :slight_smile:

UPDATE: 16th Sept '21 13:01 UTC
I have been playing around a little more this afternoon.

It looks like, if I specify the text area as a code block without the <pre> or <code> tags, then it appears to work correctly.

Format of the code in Obsidian Editor:

Format of the code in PDF Format:

While this resolves the issue at the moment, for me at least, I am interested to find out if anyone else has had the same kind of issues with using the <pre> or <code> tags, when exporting using the dark theme from Obsidian.


This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.