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

YAML frontmatter #93

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

YAML frontmatter #93

wants to merge 5 commits into from

Conversation

sencer
Copy link
Contributor

@sencer sencer commented Jan 24, 2016

Highlighting and folding for YAML frontmatter many people using in their markdown files.

crazymaster referenced this pull request in vim-jp/vim-jp.github.io Apr 4, 2016
@kyoh86
Copy link
Contributor

kyoh86 commented Apr 10, 2018

Why isn't this merged? @tpope

@mjm
Copy link

mjm commented May 26, 2018

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.

@tpope
Copy link
Owner

tpope commented May 26, 2018

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.

@mjm
Copy link

mjm commented May 27, 2018

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.

@RichardDooling
Copy link

I found this one, which handles both --- and ... in 2nd boundary

syntax include @yaml syntax/yaml.vim
syntax region yamlFrontmatter start=/%^---$/ end=/\v^%(.{3}|-{3})$/ keepend contains=@yaml

@mipmip
Copy link

mipmip commented Jun 26, 2019

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
Copy link

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 --- ?

Copy link
Owner

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.

tkapias added a commit to tkapias/vim that referenced this pull request Nov 9, 2021
Updating the code from this old pull request: tpope/vim-markdown#93
@tkapias
Copy link

tkapias commented Nov 9, 2021

I corrected this code and added TOML too, I made a pull request to vim/vim #9112 .

I mentioned this place in my commit.

@tkapias
Copy link

tkapias commented Nov 11, 2021

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.

image
image

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:

  1. The syntax file was already complex to maintain. I think that this argument can be dismissed because of the small amount of modification needed at the end.

  2. The fact that the front matter would be out of the original scope of Markdown, comparing it to additional embedded semantics.

I think that in the case of Vim this feature is special:

  • Technically it is upstream of Markdown and does not mix with it, so it is easy to support without interfering with the core.
  • Unlike other features that are often tool specific and require a very custom plugin or pipeline, front matter in Yaml, Toml or Json (let's forget about that one) are common to many tools with a unique implementation for many usages.
  • But more deeply, I think there is little use for the vanilla Markdown plugin on Vim without this feature:
    • Developers use a lot of additional features and turn to Vim or VScode a lot, but they have to customize their configuration anyway, there is no unique plugin suitable to cover all the cases. Most of them would be for native front matter support since it doesn't disrupt anything.
    • People who edit vanilla Markdown content frequently do so for note-taking or short texts, in which case, on Vim they quickly find themselves lacking some feature for classification or metadata. Or they work on files that are organized by file system, but that often means they are using a note-taking tool or a dedicated CMS, not Vim.
    • People who write Markdown publications necessarily need features like those offered by exports to Pandoc, the most basic of which is the management of front matter values. And Vim may be the only platform that allows you to easily build a clean and light pipeline for that, but nobody knows that because a lot of poorly designed markdown editors have arrived in the last few years.

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.

@tpope
Copy link
Owner

tpope commented Nov 13, 2021

  • Technically it is upstream of Markdown and does not mix with it, so it is easy to support without interfering with the core.

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 not keyword. This is just the first of many mistakes.

  • But more deeply, I think there is little use for the vanilla Markdown plugin on Vim without this feature:

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
Copy link
Owner

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
Copy link
Owner

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.

@tpope
Copy link
Owner

tpope commented Nov 13, 2021

Let me just add, for those unfamiliar, this feature can be implemented externally in after/syntax/markdown.vim. I'm not standing in the way of anyone who wants to highlight frontmatter.

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.

8 participants