deathau / cm-editor-syntax-highlight-obsidian Goto Github PK
View Code? Open in Web Editor NEWA plugin for [Obsidian](https://obsidian.md) which allows syntax highlighting for code blocks in the editor.
A plugin for [Obsidian](https://obsidian.md) which allows syntax highlighting for code blocks in the editor.
Could you? The preview pane does it.
I haven't seen any issues posted where it's just straight up not working, but it for me all of the code text is white. I've tried installing from Obsidian and manually with the zip file. Restarted many times, tried on a new note.
In trying to get assembly highlighting to work, I added this file to this project, and imported it.
This is essentially a copy of the gas.js mode, which I couldn't figure out how to make work on its own, but the mode is renamed to "x86asm" and hardcoded to use x86 assembly.
Originally, I did try using something like
```gas
mov eax, -1
```
But that didn't work.
This file adds highlighting for register names and some other bits of syntax. It doesn't recognize assembly instructions, unfortunately, although it seems like that might have to be custom added or converted from (say) another format like https://github.com/13xforever/x86-assembly-textmate-bundle
In any case, this file does get me highlighting in the editor even though obsidian doesn't highlight assembly in the preview at all.
When you turn off the plugin, the highlighting stays until you restart the app.
I noticed that the editor doesn't do highlighting unless the full name of the language is used:
Both render correctly in preview mode:
Other languages don't seem to have this problem- Typescript code is highlighted in the editor for both ts
and typescript
. Python seems to be catching an odd case here.
Thanks for this much-needed plugin!
It would be nice to have the option to add line numbers to the code snippets.
Thanks in advance!
Would be much appreciated! This plugin is a godsend otherwise.
I have YAML frontmatter in some notes. I don't have any custom CSS, and they look like this in dark mode. It's basically unreadable.
Text color is the same in light mode, where it's not a problem.
The highlighting should be either aware of your theme (at least of dark and light mode) or use colors that are readable in both dark and light mode.
In the readme the link to the latest release links to the whitespace plugin and not the syntax highlighting plugin.
Hey there,
Fairly new to Obsidian, and just grabbed this plugin. I was wondering if there is there a way to change the overall highlighting color schema, or manually adjust colors for specific languages? I looked under the plugins menu, but it looks like you can only really enable and disable the plugins, not much for options to change? Is there a config file or similar I can adjust for this?
Thanks,
-MH
when I use matlab in code block, it can't be highlight
I tried the plugin on Android, and it loaded fine, but it seems to use the light mode colors in dark mode.
This is how it looks on desktop:
and this on mobile:
this is the suspected light colors on desktop:
Additionally I found this while loading inspecting with the Chrome adb debugger:
app.js:1 Uncaught TypeError: cm.getOption is not a function
at eval (eval at <anonymous> (app.js:1), <anonymous>:30245:99)
at app.js:1
at t.iterateLeaves (app.js:1)
at t.iterateLeaves (app.js:1)
at t.iterateAllLeaves (app.js:1)
at t.iterateCodeMirrors (app.js:1)
at CMSyntaxHighlightPlugin._this.refreshLeaves (eval at <anonymous> (app.js:1), <anonymous>:30245:33)
at CMSyntaxHighlightPlugin._this.layoutReady (eval at <anonymous> (app.js:1), <anonymous>:30241:19)
at t.e.tryTrigger (app.js:1)
at t.e.trigger (app.js:1)
thanks for the plugin. If a note is open in edit mode with code when obsidian starts it does not work (shows all white text) until toggling from edit->preview->edit.
You can trigger an update on the active leaf with something like this:
const view = this.app.workspace.activeLeaf.view as MarkdownView;
const editor = view.sourceMode.cmEditor;
// editor.refresh(); // DOESNT DO ANYTHING
editor.setOption("mode", "css");
editor.setOption("mode", "markdown");
i.e. by swapping the mode from markdown and then back. Maybe this can be applied in the onload()?
When I use this in Live Preview mode, the code blocks become blank and nothing shows up. When I turn off live preview and use source code mode, it will work in the separate preview pane. I disabled all other plugins besides this one to make sure nothing is conflicting. I have a video of the bug here:
https://i.imgur.com/XNCnf7D.mp4
EDIT: Meant to post this in a different plugin repo, accidentally posted it here because this plugin is also used with that one.
when i try to usejsp,this plugin will force me to change jsp into other characters, such as jspjsp if I force it to
jsp, the rendering of the entire editor will explode and nothing can be seen.
Frontmatter is a YAML code.
Now is shown as a plain text.
This is a markdown / script language and as other languages syntax could be coloured.
It would be fantastic to add syntax hightlight for data inside a frontmatter block
Hi! Thanks for making this plugin :) I'm using JSON frontmatter at the top of my md
files within a codeblock (so I get the syntax highlighting) and was wondering if you could somehow make keys/values within the JSON structure different colors? It seems to make all strings the same color, which is fine for keys OR values, but not preferrable for both:
{
"name":"Kjell",
"age":35,
"hometown":"Seattle"
}
In this example, there are only 3 colors:
The main problem I have with all strings being the same color is that in just the past 24 hours, I've accidentally highlighted and copied strings beyond one entire value for long strings (think several paragraphs of markdown which have been JSON.stringified
. Then I've deleted them and my JSON was all messed up because I removed too much text because I didn't see the dividing line between one key/value pair and the next.
If you can't, or it's just too much work, I understand. Just thought I'd ask :)
I use the obsidian-spaced-repetition
plugin to make flashcards to study programming topics, but when the flashcard content is displayed by the other plugin it doesn't have any syntax highlighting. It would be great if this plugin had an API which I could call from over in the obsidian-spaced-repetition
plugin to do something like syntaxHighlightApi.highlightMarkdown(codeFenceTextToHighlight)
which would return some HTML with inline styles, perhaps. Just spitballing here.
Raw note content with the syntax highlighting working:
What it looks like when rendered by the obsidian-spaced-repetition
plugin as a flashcard:
AFAIK there's no official syntax highlighting for mermaid? but could one be invented so we can highlight those code chunks ? 😅
It looks like there needs to be a new release created.
Although the current version is marked as 0.1.2, the bundle is marked as 0.1.1:
This means that the source code has been updated to include the elixir
mode, but it is missing from the release files.
Here is a screen grab using the release of 0.1.2:
And this is the same pages, but with a checked out version of the repo and the release files copied into the plugin directory:
Hi,
Really love this plugin.
It would be useful to see whether to language selected is supported.
So, it would be cool if the language identifier could change the color if it is recognized.
Just like Discord does:
Does this plug-in support HCL? HCL syntax highlighting doesn't seem to work.
terraform {
required_providers {
*****
}
Hello.
Obsidian has some missing languages, but this plugin does not, for example: Forth. Is it possible to override Obsidian's default syntax highlighting in Preview mode with your plugin?
Or if you know how to add Forth to Obsidian's syntax highlighting, that would be much appreciated. I think they use CodeMirror, but CodeMirror supports Forth though.
Hello
I was wondering if it would be possible to add G-code highlighting to the plugin.
Looks like this other repo may have what's needed:
https://github.com/oneislandearth/gcode-lang-codemirror
I'm not a developer so excuse my ignorance if that repo isn't helpful.
I'm trying to figure out a way to install more modes for the plugin.
Elixir: https://github.com/ianwalter/codemirror-mode-elixir/blob/master/index.js
I think maybe just putting index.js into the mode folder might work? I'll try it
Is their a known method for editing existing languages?
In short; I modified the code so that bash could recognize ;
as a comment and the program itself completely ignores it and only continues to recognize #
I then created a bogus language that isn't real (just to have a new unique language name); added the same rules, and it worked fine.
I then decided to decode the typescript source map (base64) and see that the same language definitions exist there too; and it seems like those are overriding the changes to the decoded tables. The only way to get a successful result is by creating an entirely unique language name.
Thanks
Obsidian already has full syntax highlighting in reading mode for AutoHotkey (AHK), but not in Edit mode (neither live preview nor source mode). So that is why I installed the Editor Syntax Highlight plugin. However it seems that Editor Syntax Highlight plugin does not support Autohotkey because there was no change to any AutoHotkey code fences after installation of the plugin.
AutoHotkey is pretty widely known and well used, so it would be great if you would consider adding syntax-highlighting support for this language.
Thanks!
It would be great if this could highlight dataviewjs
blocks. A quick and easy fix would be to just highlight them the same as Javascript. I managed to hack a fix together locally which will work, but in the hope that it's a little easier to maintain, I've created a PR against CodeMirror to add an alias to the Javascript mode: https://github.com/codemirror/CodeMirror/pull/6833/files
Hopefully if that merges it'll get included in the next release of this plugin? :)
If I want to write headings like this:
# After I typed `#`, Obsidian would trigger to refer a tag. I knew it ok.
## But Obsidian would render all headings even in editor mode
### If you toggled to preview mode, Obsidian would render everything very well
And if there was a YAML in Markdown code block would also render bad in editor mode.
Open Highlightr fails with "Focus must be in editor" message
All other commands work great!
This is a awesome Plugin! Thank you.
I had the Obsidianite theme on since it is my favourite one and the only way I could see the block of code was in view mode, when I go back to edit the whole note goes blank, yet I can still edit the text. I changed the theme and the plugin works just fine now. Might there be a problem with that theme in particular?
I would like to see ColdFusion Syntax Highlight added
cfml
<cfscript>
for (i=1;i LTE ArrayLen(array);i=i+1) {
WriteOutput(array[i]);
}
</cfscript>
I don't mind trying to do it if someone can point me in the right direction.
[Feature Request] YML/YAML highlighting
Really helpful. Please consider.
Hello,
This plugin has worked perfectly for me up until the newly released Obsidian v1.0.0. On Obsidian v1.0.0, the plugin doesn't seem to highlight shell and bash languages in the same way it used to; some text is highlighted, but most is not (it seems that python, javascript, css, and others do still work properly). Is anyone else experiencing the same behavior? Maybe it's just me and the syntax has changed for declaring these languages and I'm making the mistake?
While browsing plugin descriptions, in Version: 0.1.3 of this plugin I spotted a small typo:
Show syntax highlighing in code blocks the editor
Should be something like:
Show syntax highlighing in code blocks in the editor
Or even better:
Show syntax highlighting inside codeblocks while using the editor
Hahaha: and of course I misspell typo in thus bug report subject line. Lololol
This is great but I can only see a single line in editor view. When I press 'enter', the previous line disappears. Is there a way I can see the whole code block (previous lines and ones below)?
Hi,
Is it possible change so that {r} is recognised instead of
r? As the first is the way it's written in RMarkdown it would be great to be able to write in a coherent manner to that in obsidian.
Thank you.
Hi there thanks for the plugin!
It be awesome if you added graphql syntax highlighting! There is currently a 3rd party module available via NPM codemirror-graphql
.
It be a huge plus for me! Thanks
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.