Editor: Syntax Highlighting in Code Blocks

This is one of the the reason why Roam is still top on my list, instead of obsidian

I think this plugin is the perfect solution https://github.com/deathau/cm-editor-syntax-highlight-obsidian

6 Likes

I think this shouldn’t be a third-party plugin. It should be a built-in feature. Any reasons it’s not added?

1 Like

+1. Would be a great addition to Obsidian

1 Like

Thanks for the plugin. Is there a way to make it work for R code syntax highlighting support?

Would love to see syntax highlighting available by default :pray:

1 Like

+1 for this

+1 for this :clap:

+1 Please add this function!

+1 :+1:

I’m also using this! It’s a bit disconcerting though that the preview syntax highlighting does not match the editor’s. As for me, I prefer the plugin’s highlighting to the native one. Are you able to sync them?

No I don’t think that is possible. Preview and edit mode uses completely different libraries for the highlighting. Source

+1 it is laughable that this is not supported

+1 for that feature

@death.au I might suggesting looking into how this markdown editor functions: GitHub - writewithocto/ink: A plain-text javascript markdown editor library that renders formatting live and in-place without the need for a preview pane. Built on CodeMirror 6. Powers https://octo.app.

It performs formatting of the markdown itself, which supports syntax highlighting in the editor.

I just released an early version of a plugin which will unify code block syntax highlighting between edit and preview modes. It has support for a few different syntax highlighting themes out of the box and support for importing your own themes.

I plan on submitting this to the official plugin repository in the near future but if anyone wants to test and provide feedback, you can check it out here: Release 0.0.2 · nothingislost/obsidian-codemirror-options · GitHub

@NothingIsLost Awesome plugin, 10/10. Came across what I think is a bug. Gif below shows the theme (solarized light) unapplied in preview mode but applied in edit mode.

My guess is that it’s probably caused by code block makers (```) in the markdown file having spaces to the left (highlighted with blue circle):

Screenshot 2021-09-28 at 5.12.58 PM

Notice that obsidian’s default code syntax highlighting renders just fine in Preview mode (default code theme is grey background one as seen in the .gif)

I also want this to be built-in.

this is implemented in 0.13.6

2 Likes

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