-
-
Notifications
You must be signed in to change notification settings - Fork 192
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
YAML frontmatter #93
base: master
Are you sure you want to change the base?
YAML frontmatter #93
Conversation
Why isn't this merged? @tpope |
This would be really nice to have. I haven't been able to track down any other support for highlighting this frontmatter correctly in Vim. |
The reason it isn't merged is because it isn't Markdown! Every system I've seen that uses YAML frontmatter accepts HTML along side Markdown, yet I don't see support for it in html.vim. Setting aside semantics, I'm reticent to throw another syntax file into the hairiest syntax highlighter I've ever worked on, and that's before counting the embedded HTML, CSS, JavaScript, and custom highlighted languages in code blocks that I already have to contend with. I do support frontmatter in vim-liquid, which isn't exactly the right place to put it either, but it is closer to the right abstraction layer, supporting HTML, Markdown, and other markup languages in one go. I think it's common for a lot of these frontmatter using frameworks to pair it with Liquid? Jekyll does so, at least. |
Fair enough. After posting that, I found a one-liner to mark that area as comments, which I think is good enough for what I need. |
Here's are folding functions for markdown that also folds frontmatter yaml with nested nodes. I glued together code from https://habamax.github.io/2019/03/07/vim-markdown-frontmatter.html and https://github.com/pedrohdz/vim-yaml-folds. |
endif | ||
|
||
" End of front matter | ||
if (line == '...') && b:markdown_frontmatter |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this supposed to end with ---
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will cause an error if b:markdown_frontmatter
isn't defined.
Updating the code from this old pull request: tpope/vim-markdown#93
Following my attempt to PULL this functionality on vim/vim#9112, I come back here to defend the topic of including front matter support with Markdown. I revised the code since vim/vim#9112, the last version is in these 2 files: Basically, if there is a front matter in the Markdown file, written in YAML (most common) or TOML (competitor), the syntax highlighting and folding adapt to the front matter part without impacting the rest. The addition of these features has been stagnant since 2018 following the latest reply from @tpope. He suggested I change his mind before experimenting first here. Basically @tpope had 2 blockers:
I think that in the case of Vim this feature is special:
I use Markdown for taking notes and writing paper or web publications. In these three cases I use a front matter. I've had to deal with dozens of tools, many features were inconsistent but not this one. |
Easy to add, not easy to support. You have no idea what the support cost will be, and you won't be the one to pay it. But I'm not even sure "easy to add" is a given, since the very first line of your patch has a syntax error: VimL does not feature a
You are writing this on a site that hosts literally millions of README files written in Markdown, not a one of them using frontmatter. What's more, the text field you typed your comment into supports Markdown and I don't see you using any frontmatter. Your whole argument reeks of bad faith. |
@@ -38,6 +38,18 @@ function! MarkdownFold() | |||
return ">2" | |||
endif | |||
|
|||
" Front matter | |||
if v:lnum == 1 && line == '---' | |||
let b:markdown_frontmatter = 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This assumes the whole file is processed top to bottom, which isn't true.
@@ -60,6 +60,10 @@ syn match markdownBlockquote ">\%(\s\|$\)" contained nextgroup=@markdownBlock | |||
|
|||
syn region markdownCodeBlock start=" \|\t" end="$" contained | |||
|
|||
syn include @yamlTop syntax/yaml.vim | |||
syntax match YAMLFrontMatter /\%^---\_.\{-}\.\.\.$/ contains=@yamlTop |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should start with markdown
. Syntax groups are global.
Let me just add, for those unfamiliar, this feature can be implemented externally in |
Highlighting and folding for YAML frontmatter many people using in their markdown files.