Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Idea: improve/change grammar matching #384

Open
burodepeper opened this issue Mar 19, 2016 · 2 comments
Open

Idea: improve/change grammar matching #384

burodepeper opened this issue Mar 19, 2016 · 2 comments

Comments

@burodepeper
Copy link
Contributor

I'm planning to change the default scope used in language-markdown from text.md to source.text.md (see burodepeper/language-markdown#83) for wider support by syntax themes. This will break the markdown-preview:toggle command, because it doesn't match with the default grammars anymore.

Currently a match counts as valid when it is a 100% match (see https://github.com/atom/markdown-preview/blob/master/lib/main.coffee#L67-L68). I'd like to submit a PR to address this issue, but I'm considering whether to just add another grammar to the config (see https://github.com/atom/markdown-preview/blob/master/package.json#L46-L53) or to change the matching algorithm to allow partial matches.

I'm leaning towards the latter, because I've always interpreted scope names as css classes (and not ids) so a partial match seems to make sense. I would like your input on this, especially how a partial match could cause new issues that I might have overlooked in my naivety.

I reckon that the scope text.md in the config should match with text.md, md.text, source.text.md, source.md.text, etc. as long as both text and md are present in the current grammar. Obviously, this would be the case for all default grammars in the config (which could be simplified as a result of this).

@winstliu
Copy link
Contributor

source.text.md

The top-level scope should really only be source OR text, not both. Unfortunately there's no documentation regarding that right now. Out of curiosity, which syntax themes are you trying to support?

@burodepeper
Copy link
Contributor Author

@50Wliu Thanks for your response.

The main issue with syntax themes is that most of them haven't any proper support for markup (related) classes. I've pieced together parts from the default themes and mostly extended conventions set by language-gfm, but this leaves not much more than a loosely defined non-standard. Besides that, most themes are primarily focused on source and/or derived from another theme with limited support/love for markup.

To patch this, I thought of assigning source related scopes to elements in addition to existing markup related scopes. I believe this to be valid, because there is a certain level of semantic overlap. In my tests, this approach has significantly improved how Markdown files are styled.

In addition, I've planned to create PRs for each default syntax theme to add a bare minimum of markup styling (as referenced in burodepeper/language-markdown#83), but my experience is that this is a slow process (besides not a fun chore), so that's why I'm "attacking" it from multiple angles.

Slightly off-topic, I think Markdown can be considered both text and source, although if I had to choose it would be text. The issue with that however is that syntax themes often have general usage scopes (such as meta or variable) assigned as children of source, with text being quite "useless". However, switching to top-level scope source.md would limit access to markup styles which happy to be often assigned as children of text if I remember correctly.

So, tl;dr: no proper standardization of scopes, so I'd like to use source.text.md as top-level scope to to take advantage of both source and markup scopes. That would break integration with markdown-preview however. The underlying issue is more complex, but a more flexible grammar matching would create possibilities for a workaround until proper standards are defined (and implemented across "all" syntax themes).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants