Skip to content

YAML frontmatter #93

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions ftplugin/markdown.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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.

return ">1"
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.

unlet b:markdown_frontmatter
return '<1'
endif

return "="
endfunction

Expand Down
4 changes: 4 additions & 0 deletions syntax/markdown.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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.

unlet! b:current_syntax

" TODO: real nesting
syn match markdownListMarker "\%(\t\| \{0,4\}\)[-*+]\%(\s\+\S\)\@=" contained
syn match markdownOrderedListMarker "\%(\t\| \{0,4}\)\<\d\+\.\%(\s\+\S\)\@=" contained
Expand Down