]> git.madduck.net Git - etc/vim.git/commitdiff

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Add TOML/JSON front matter support
authorHiroshi Shirosaki <h.shirosaki@gmail.com>
Mon, 18 Jan 2016 02:03:51 +0000 (11:03 +0900)
committerHiroshi Shirosaki <h.shirosaki@gmail.com>
Thu, 21 Jan 2016 14:38:59 +0000 (23:38 +0900)
Add new options to enable front matter.
Fix #188, #242

Makefile
README.md
syntax/markdown.vim
test/run-tests.sh
test/syntax.vader
test/vimrc

index 5d231146a8798d3a07f4c0fd78b969775f699611..a50adc0b9c5927025e377d1dbcbf5cdf7275327e 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -18,18 +18,22 @@ install:
        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
 
index 1243577fb5dac1e7fced3787fb9589326533c9c0..60c58eca969bfd0b267f8661fb736132f751e6fe 100644 (file)
--- a/README.md
+++ b/README.md
@@ -137,14 +137,32 @@ Used as `$x^2$`, `$$x^2$$`, escapable as `\$x\$` and `\$\$x\$\$`.
 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:
index 778e8187d7ca77e00eb1181bed2b37e2d52b81ce..05cf75106fa364daeba8d82ecedc0d030cf06864 100644 (file)
@@ -110,6 +110,23 @@ syn match  mkdRule         /^\s*\*\{3,5}$/
 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)
index 731b3ced111f6331df20ecf9c09b32775078f168..ba00fc01fca33157f22d7579325a0be755c9e618 100755 (executable)
@@ -5,7 +5,7 @@ set -e
 
 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'."
index ecf36b7de46024719f31fde91ea1958a108587bc..f2fc9367532edcc21327ccd2b7e7eb99924084cc 100644 (file)
@@ -489,6 +489,65 @@ Execute (rules are not mistaken by YAML frontmatter delimiters):
   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
 
index 524fe6c0f101ab644f555ccd718de7638617ae36..015febfe148d22907bc17190f765933558dca613 100644 (file)
@@ -1,6 +1,7 @@
 set nocompatible
 set rtp+=../
 set rtp+=../build/tabular/
+set rtp+=../build/vim-toml/
 set rtp+=../build/vader.vim/
 let $LANG='en_US'
 filetype on