Getting certain codeblock languages to syntax highlight / colorize in preview mode?

Small test in the Sandbox vault… Obsidian Installer 1.4.16 / macOS

Code

=IF(ISNUMBER(SEARCH("A-", A2)), "Valid", "")

Screenshot (←source mode / preview mode →)

Any way that we can have the syntax highlights show up in Preview?

Yes both source view live preview support colors, but if you try, you’ll see that not all strings will take the same colors as in live preview.

If you write code, switching back and fourth looks messy. Maybe the Vscode editor or similar plugins are able to modify code syntax highlights the right way, but I hadn’t time to test this.


Yes, I noticed the same thing – things like JavaScript, JSON, or python generally do colorize (although somewhat differently) but overall very inconsistent results between languages in Source vs Preview panes. Why is this?

Obsidian uses Prism for syntax highlighting. For more information, refer to Supported languages.

Note
Live Preview mode doesn’t support PrismJS and may render syntax highlighting differently.

https://help.obsidian.md/Editing+and+formatting/Basic+formatting+syntax#Code+blocks


Editing view (Source and Live Preview) use CodeMirror’s syntax highlighting, which seems fine with excel ? :melting_face:

https://prismjs.com/#supported-languages lists:
Excel Formula - excel-formula, xlsx, xls but those don’t work in Editing view.

Maybe find a random language in the above link that looks alright in both modes?

1 Like

Ok didn’t realize the modes use different renderers, although that does explain why it’s very often different. Is this quirk documented anywhere?

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