Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Markdown] Add YAML frontmatter highlighting #2339

Merged
merged 5 commits into from
Jul 22, 2020

Conversation

FichteFoll
Copy link
Collaborator

Because this may only match at the very beginning of the file, it cannot be tested. I tried.

Closes #1783.

2020-04-19_18-58-57

Because this may only match at the very beginning of the file, it cannot
be tested. I tried.

Closes sublimehq#1783.
@michaelblyons
Copy link
Collaborator

michaelblyons commented Apr 19, 2020

Can you make a test to ensure that it doesn't match further down in the file? Maybe this is taken care of by matching the "underlined" headers.

@FichteFoll
Copy link
Collaborator Author

There are a couple tests regarding the thematic-break token (which is what these would normally be matched as), but none specifically with exactly three hyphens. I guess I could add a test for that since I already verified this manually.

Copy link
Collaborator

@deathaxe deathaxe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd propose something like this...

contexts:
  main:
    - match: ---\n
      scope: meta.frontmatter.markdown punctuation.section.frontmatter.begin.markdown
      embed: scope:source.yaml
      embed_scope: meta.frontmatter.markdown source.yaml.embedded.markdown
      escape: ^---(?=\s)
      escape_captures:
        0: meta.frontmatter.markdown punctuation.section.frontmatter.end.markdown
    - match: ''
      set: markdown

  markdown:
    ...

Markdown/Markdown.sublime-syntax Outdated Show resolved Hide resolved
Markdown/Markdown.sublime-syntax Outdated Show resolved Hide resolved
Markdown/Markdown.sublime-syntax Outdated Show resolved Hide resolved
Markdown/Markdown.sublime-syntax Outdated Show resolved Hide resolved
Markdown/Markdown.sublime-syntax Outdated Show resolved Hide resolved
main:
- include: file-start
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if it is really worth adding a named context for just one match rule.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name of the context helps convey the semantic meaning of the match, imo, so I left that in.

- Better supports embedding by not anchoring to `^`.
- Since some newish release we can also set out of the main context.
@wbond
Copy link
Member

wbond commented Jul 22, 2020

One the test failure is fixed, this should be good to merge

@wbond
Copy link
Member

wbond commented Jul 22, 2020

LGTM, thanks!

@wbond wbond merged commit 0b498f9 into sublimehq:master Jul 22, 2020
@FichteFoll FichteFoll deleted the pr/markdown/yaml-frontmatter branch July 22, 2020 15:39
@@ -24,5 +25,5 @@ contexts:
scope: string.unquoted.multimarkdown
- match: ''
push:
- meta_scope: meta.content.multimarkdown
- include: scope:text.html.markdown
- - meta_scope: meta.content.multimarkdown
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that style a new feature in version 2?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, that was possible before.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, but Will told Thom not to do it for complicated stuff.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know about chaining anonymous contexts via - - .... I did not expect anonymous contexts with only a meta_scope derective to be valid.

deathaxe pushed a commit to deathaxe/sublime-packages that referenced this pull request Jul 25, 2021
* [Markdown] Add YAML frontmatter highlighting

Because this may only match at the very beginning of the file, it cannot
be tested. I tried.

Closes sublimehq#1783.

* [Markdown] Add test for normal `---` token

* [Markdown] Add `meta.formatter.markdown` scope

- Better supports embedding by not anchoring to `^`.
- Since some newish release we can also set out of the main context.

* [Markdown] Fix Multimarkdown tests by embedding

* [Markdown] Replace embed with multi-push
mitranim pushed a commit to mitranim/Packages that referenced this pull request Mar 25, 2022
* [Markdown] Add YAML frontmatter highlighting

Because this may only match at the very beginning of the file, it cannot
be tested. I tried.

Closes sublimehq#1783.

* [Markdown] Add test for normal `---` token

* [Markdown] Add `meta.formatter.markdown` scope

- Better supports embedding by not anchoring to `^`.
- Since some newish release we can also set out of the main context.

* [Markdown] Fix Multimarkdown tests by embedding

* [Markdown] Replace embed with multi-push
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Highlight Frontmatter in Markdown as YAML
4 participants