Add new options to enable front matter.
Fix #188, #242
mkdir -pv ${REGISTRY}
cp -v registry/markdown.yaml ${REGISTRY}/markdown.yaml
-test: build/tabular build/vader.vim
+test: build/tabular build/vim-toml build/vader.vim
test/run-tests.sh
.PHONY: test
-update: build/tabular build/vader.vim
+update: build/tabular build/vim-toml build/vader.vim
cd build/tabular && git pull
+ cd build/vim-toml && git pull
cd build/vader.vim && git pull
.PHONY: update
build/tabular: | build
git clone https://github.com/godlygeek/tabular build/tabular
+build/vim-toml: | build
+ git clone https://github.com/cespare/vim-toml build/vim-toml
+
build/vader.vim: | build
git clone https://github.com/junegunn/vader.vim build/vader.vim
let g:vim_markdown_math = 1
```
-#### YAML frontmatter
+#### YAML Front Matter
-Highlight YAML frontmatter as used by Jekyll:
+Highlight YAML front matter as used by Jekyll or [Hugo](https://gohugo.io/content/front-matter/).
```vim
let g:vim_markdown_frontmatter = 1
```
+#### TOML Front Matter
+
+Highlight TOML front matter as used by [Hugo](https://gohugo.io/content/front-matter/).
+
+TOML syntax highlight requires [vim-toml](https://github.com/cespare/vim-toml).
+
+```vim
+let g:vim_markdown_toml_frontmatter = 1
+```
+
+#### JSON Front Matter
+
+Highlight JSON front matter as used by [Hugo](https://gohugo.io/content/front-matter/).
+
+```vim
+let g:vim_markdown_json_frontmatter = 1
+```
+
## Mappings
The following work on normal and visual modes:
if get(g:, 'vim_markdown_frontmatter', 0)
syn include @yamlTop syntax/yaml.vim
syn region Comment matchgroup=mkdDelimiter start="\%^---$" end="^---$" contains=@yamlTop
+ unlet! b:current_syntax
+endif
+
+if get(g:, 'vim_markdown_toml_frontmatter', 0)
+ try
+ syn include @tomlTop syntax/toml.vim
+ syn region Comment matchgroup=mkdDelimiter start="\%^+++$" end="^+++$" transparent contains=@tomlTop
+ unlet! b:current_syntax
+ catch /E484/
+ syn region Comment matchgroup=mkdDelimiter start="\%^+++$" end="^+++$"
+ endtry
+endif
+
+if get(g:, 'vim_markdown_json_frontmatter', 0)
+ syn include @jsonTop syntax/json.vim
+ syn region Comment matchgroup=mkdDelimiter start="\%^{$" end="^}$" contains=@jsonTop
+ unlet! b:current_syntax
endif
if get(g:, 'vim_markdown_math', 0)
cd "$( dirname "${BASH_SOURCE[0]}" )"
-for dep in ../build/tabular ../build/vader.vim; do
+for dep in ../build/tabular ../build/vim-toml ../build/vader.vim; do
if [[ ! -d $dep ]]; then
echo "Missing dependency: $dep"
echo "You may just want to use 'make test'."
let g:vim_markdown_frontmatter=1
syn off | syn on
AssertEqual SyntaxAt(5, 1), 'mkdRule'
+ unlet g:vim_markdown_frontmatter
+
+# TOML frontmatter
+
+Given markdown;
++++
+a = "b"
++++
+
+Execute (TOML frontmatter is controlled by the option):
+ syn off | syn on
+ AssertNotEqual SyntaxOf('b'), 'tomlString'
+ let g:vim_markdown_toml_frontmatter=1
+ syn off | syn on
+ AssertEqual SyntaxOf('b'), 'tomlString'
+ let g:vim_markdown_toml_frontmatter=0
+ syn off | syn on
+ AssertNotEqual SyntaxOf('b'), 'tomlString'
+
+Given markdown;
+
++++
+a = "b"
++++
+
+Execute (TOML frontmatter only works if it's the first thing in the file):
+ let g:vim_markdown_toml_frontmatter=1
+ syn off | syn on
+ AssertNotEqual SyntaxOf('b'), 'tomlString'
+ unlet g:vim_markdown_toml_frontmatter
+
+# JSON frontmatter
+
+Given markdown;
+{
+ "a": "b"
+}
+
+Execute (JSON frontmatter is controlled by the option):
+ syn off | syn on
+ AssertNotEqual SyntaxOf('a'), 'jsonKeyword'
+ let g:vim_markdown_json_frontmatter=1
+ syn off | syn on
+ AssertEqual SyntaxOf('a'), 'jsonKeyword'
+ let g:vim_markdown_json_frontmatter=0
+ syn off | syn on
+ AssertNotEqual SyntaxOf('a'), 'jsonKeyword'
+
+Given markdown;
+
+{
+ "a": "b"
+}
+
+Execute (JSON frontmatter only works if it's the first thing in the file):
+ let g:vim_markdown_json_frontmatter=1
+ syn off | syn on
+ AssertNotEqual SyntaxOf('a'), 'jsonKeyword'
+ unlet g:vim_markdown_json_frontmatter
# Header
set nocompatible
set rtp+=../
set rtp+=../build/tabular/
+set rtp+=../build/vim-toml/
set rtp+=../build/vader.vim/
let $LANG='en_US'
filetype on