From 225338e9b7f037e02cc97bb67f8d133f59ac2719 Mon Sep 17 00:00:00 2001 From: Sencer Selcuk Date: Sun, 24 Jan 2016 11:52:05 -0500 Subject: [PATCH 1/4] Fold YAML front matter --- ftplugin/markdown.vim | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/ftplugin/markdown.vim b/ftplugin/markdown.vim index e8627cc..d0fc41a 100644 --- a/ftplugin/markdown.vim +++ b/ftplugin/markdown.vim @@ -22,6 +22,11 @@ endif function! MarkdownFold() let line = getline(v:lnum) + " Front matter + if v:lnum == 1 && line == '---' + return ">20" + endif + " Regular headers let depth = match(line, '\(^#\+\)\@<=\( .*$\)\@=') if depth > 0 @@ -38,6 +43,12 @@ function! MarkdownFold() return ">2" endif + " End of front matter + let prevline = getline(v:lnum - 1) + if (prevline == '...') && (foldlevel(v:lnum-1) == 20) + return '>0' + endif + return "=" endfunction From 8817c773d7fe23f7a59f8112db45df0e1d8d2356 Mon Sep 17 00:00:00 2001 From: Sencer Selcuk Date: Sun, 24 Jan 2016 11:52:50 -0500 Subject: [PATCH 2/4] YAML front matter as comment --- syntax/markdown.vim | 3 +++ 1 file changed, 3 insertions(+) diff --git a/syntax/markdown.vim b/syntax/markdown.vim index 6aff90a..55f7dea 100644 --- a/syntax/markdown.vim +++ b/syntax/markdown.vim @@ -60,6 +60,8 @@ syn match markdownBlockquote ">\%(\s\|$\)" contained nextgroup=@markdownBlock syn region markdownCodeBlock start=" \|\t" end="$" contained +syntax match YAMLFrontMatter /\%^---\_.\{-}\.\.\.$/ + " TODO: real nesting syn match markdownListMarker "\%(\t\| \{0,4\}\)[-*+]\%(\s\+\S\)\@=" contained syn match markdownOrderedListMarker "\%(\t\| \{0,4}\)\<\d\+\.\%(\s\+\S\)\@=" contained @@ -145,6 +147,7 @@ hi def link markdownBoldDelimiter markdownBold hi def link markdownBoldItalic htmlBoldItalic hi def link markdownBoldItalicDelimiter markdownBoldItalic hi def link markdownCodeDelimiter Delimiter +hi def link YAMLFrontMatter Comment hi def link markdownEscape Special hi def link markdownError Error From 1a4686fce83345f85b4eee02f881c3c81071adcf Mon Sep 17 00:00:00 2001 From: Sencer Selcuk Date: Sun, 24 Jan 2016 12:01:20 -0500 Subject: [PATCH 3/4] Highlight YAML header --- syntax/markdown.vim | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/syntax/markdown.vim b/syntax/markdown.vim index 55f7dea..95cc5d2 100644 --- a/syntax/markdown.vim +++ b/syntax/markdown.vim @@ -60,7 +60,9 @@ syn match markdownBlockquote ">\%(\s\|$\)" contained nextgroup=@markdownBlock syn region markdownCodeBlock start=" \|\t" end="$" contained -syntax match YAMLFrontMatter /\%^---\_.\{-}\.\.\.$/ +syn include @yamlTop syntax/yaml.vim +syntax match YAMLFrontMatter /\%^---\_.\{-}\.\.\.$/ contains=@yamlTop +unlet! b:current_syntax " TODO: real nesting syn match markdownListMarker "\%(\t\| \{0,4\}\)[-*+]\%(\s\+\S\)\@=" contained @@ -147,7 +149,6 @@ hi def link markdownBoldDelimiter markdownBold hi def link markdownBoldItalic htmlBoldItalic hi def link markdownBoldItalicDelimiter markdownBoldItalic hi def link markdownCodeDelimiter Delimiter -hi def link YAMLFrontMatter Comment hi def link markdownEscape Special hi def link markdownError Error From b52db95b7c3b78cc6ca19086a877c097ee089ad4 Mon Sep 17 00:00:00 2001 From: Sencer Selcuk Date: Tue, 2 Feb 2016 12:14:07 -0500 Subject: [PATCH 4/4] better and more correct handling of front matter --- ftplugin/markdown.vim | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/ftplugin/markdown.vim b/ftplugin/markdown.vim index d0fc41a..812ff46 100644 --- a/ftplugin/markdown.vim +++ b/ftplugin/markdown.vim @@ -22,11 +22,6 @@ endif function! MarkdownFold() let line = getline(v:lnum) - " Front matter - if v:lnum == 1 && line == '---' - return ">20" - endif - " Regular headers let depth = match(line, '\(^#\+\)\@<=\( .*$\)\@=') if depth > 0 @@ -43,10 +38,16 @@ function! MarkdownFold() return ">2" endif + " Front matter + if v:lnum == 1 && line == '---' + let b:markdown_frontmatter = 1 + return ">1" + endif + " End of front matter - let prevline = getline(v:lnum - 1) - if (prevline == '...') && (foldlevel(v:lnum-1) == 20) - return '>0' + if (line == '...') && b:markdown_frontmatter + unlet b:markdown_frontmatter + return '<1' endif return "="