foam
foam copied to clipboard
Syntax highlighting for tags in editor
Would it be possible to highlight tags in the editor, like they are in Markdown Notes? I see you mentioned this in #311, but weren't sure then whether it would negatively interact with Markdown Notes. Now that this extension is no longer recommended, would it be possible to add the functionality into Foam? Or is this out of scope?
If this change makes sense - what would be the best way to go about it? As a syntax grammar like for wikilinks? If you let me know I'd be happy to submit a PR.
Thanks!
@memeplex what's your take on this?
I think it would be possible to inject an html grammar, see the section about embedded languages in https://code.visualstudio.com/api/language-extensions/syntax-highlight-guide#injection-grammars. Here is an example of language embedding: https://github.com/mjbvz/vscode-fenced-code-block-grammar-injection-example. I guess you should look for the outer tags and embed the html grammar inside them.
Something similar could be done for latex (this would be useful if you're using pandoc to export/publish).
The fact that html (or latex) can be nested inside code blocks may complicate things.
I believe this could be a bit out of scope, but if it's simple enough maybe it's fine to add support for html.
Oh sorry, I think I wasn't clear enough. I didn't mean html tags, just whether #tags could be highlighted in the editor as well.
At the moment, tags are only highlighted when I use the Markdown Notes extension (see below). But because tags themselves are a core part of Foam, I thought it would make sense for this to be provided by Foam?
I hope that makes more sense. Thanks!
Ah LOL yes I indeed thought about that as of late. The most difficult part I can think of is to what existing scope tags should be mapped, so that colorization works with currently available themes. Other than that there's no way to set a default color.
We can think of tags as a kind of one-to-many link and hence map them to the same scope than wikilinks, then clicking on tags could trigger a search or perhaps show a references-like peek dialog.
OTOH by using a decorator you can contribute a color with a default value, but it's more heavyweight in the sense that decorations force reparsing and repainting of an unchanged document each time you switch to its editor, and there's a slight delay involved that's sometimes perceptible. Just minor issues nevertheless.
I like your default of matching the tag to the link scope.
Independently from this issue, I was actually thinking of turning tags into links which would trigger a search for the tag (like what happens when clicking on the "search" item in the tag explorer). I hadn't thought of the peek as an alternative to the search, that's an interesting option.
Thinking of it we can support both, just like we do for wikilinks. Clicking navigates, but it's also possible to peek references. But this is unrelated to the styling of tags, which is the point of this issue, I will create an issue to track what we are talking about here.
But this is unrelated to the styling of tags, which is the point of this issue, I will create an issue to track what we are talking about here.
Yes, sure, I just mentioned it in order to justify the choice of highlighting as if tags were a kind of link.
I was thinking that if we were to use a new scope, we still could set a default color in the settings file for the workspace template. But, of course, using a preexisting scope will leverage available themes.
I have an open PR with highlighting improvements, so I might as well include tag support.
I just encountered this bug with Markdown Notes that I thought I'd mention here preemptively.
Hierarchical tags are not highlighted correctly - eg. #tag-1/tag-2
. Just the first part is highlighted, as shown below.