From 7f1357472d3ccad569135c1030ebf8c042360c5f Mon Sep 17 00:00:00 2001 From: Tinmarino Date: Wed, 15 Mar 2023 00:54:49 -0300 Subject: [PATCH] Yaml metadata, fix regex (#1287) --- autoload/vimwiki/vars.vim | 11 +++-------- doc/vimwiki.txt | 2 +- test/issue_1287_yaml_header.vader | 11 ++++------- 3 files changed, 8 insertions(+), 16 deletions(-) diff --git a/autoload/vimwiki/vars.vim b/autoload/vimwiki/vars.vim index a22ede5..5e38f51 100644 --- a/autoload/vimwiki/vars.vim +++ b/autoload/vimwiki/vars.vim @@ -820,20 +820,15 @@ function! s:get_common_syntaxlocal() abort " Declare helper: a line with only --- or ... let rx_yaml_start_pre = '\%(^\%(\%1l\|^$\n\)\@<=\)' let rx_yaml_start_post = '\%(\%(\n^$\)\@!$\)' - let a_yaml_region = [] - for rx_yaml_delimiter in ['---', '\.\.\.'] - let rx_yaml_start = rx_yaml_start_pre . rx_yaml_delimiter . rx_yaml_start_post - let rx_yaml_stop = '^' . rx_yaml_delimiter . '$' - call add(a_yaml_region, [rx_yaml_start, rx_yaml_stop]) - endfor + let rx_yaml_start = rx_yaml_start_pre . '---' . rx_yaml_start_post + let rx_yaml_stop = '^' . '\%(---\|\.\.\.\)' . '$' let res.nested_extended = {'type': type(''), 'default': 'VimwikiError,VimwikiPre,VimwikiCode,VimwikiEqIn,VimwikiSuperScript,VimwikiSubScript,textSnipTEX'} let res.nested_typeface = {'type': type(''), 'default': 'VimwikiBold,VimwikiItalic,VimwikiUnderline,VimwikiDelText'} let res.nested = {'type': type(''), 'default': res.nested_extended.default . ',' . res.nested_typeface.default} let res.rxTableSep = {'type': type(''), 'default': '|'} " See issue #1287 - let res.yaml_metadata_block = {'type': type([]), 'default': a_yaml_region} - + let res.yaml_metadata_block = {'type': type([]), 'default': [[rx_yaml_start, rx_yaml_stop]]} " Declare helper for inline math nested variable let s:rx_inline_math_start = '\%(^\|[^$\\]\)\@<=\$\%($\|[^$[:space:]]\)\@=' diff --git a/doc/vimwiki.txt b/doc/vimwiki.txt index f5f4475..cb06ac6 100644 --- a/doc/vimwiki.txt +++ b/doc/vimwiki.txt @@ -2954,7 +2954,7 @@ Where: List of (start, end) regex region delimiters to define the YAML header More information in #1287 and https://pandoc.org/MANUAL.html#extension-yaml_metadata_block -Default: [['^---$', '^---$'], ['^\.\.\.$', '^\.\.\.$']] +Default: [['^---$', '^\%(---\|\.\.\.$']] or similar with stricter anchors diff --git a/test/issue_1287_yaml_header.vader b/test/issue_1287_yaml_header.vader index d164d1d..1ef512e 100644 --- a/test/issue_1287_yaml_header.vader +++ b/test/issue_1287_yaml_header.vader @@ -25,13 +25,13 @@ Given vimwiki (Yaml with --- at top): Execute (Assert delimiter with --- at top): call Issue1287Yaml(1) -Given vimwiki (Yaml with ... at top): - ... +Given vimwiki (Yaml with --- at bottom): + --- title: my title description: my description ... -Execute (Assert delimiter with ... at top): +Execute (Assert delimiter with ... at bottom): call Issue1287Yaml(1) Given vimwiki (Yaml with --- after empty line): @@ -63,10 +63,7 @@ Execute (Assert all is yaml except after the closing ---): AssertEqual 'textSnipYAML1', GetSyntaxStack(1, 2)[0] . 1 AssertEqual 'textSnipYAML2', GetSyntaxStack(2, 2)[0] . 2 - AssertEqual 'textSnipYAML3', GetSyntaxStack(3, 2)[0] . 3 - AssertEqual 'textSnipYAML4', GetSyntaxStack(4, 2)[0] . 4 - AssertEqual 'textSnipYAML5', GetSyntaxStack(5, 2)[0] . 5 - AssertEqual 'textSnipYAML6', GetSyntaxStack(5, 2)[0] . 6 + AssertEqual 'VimwikiPre3', GetSyntaxStack(3, 2)[0] . 3 AssertEqual 0, len(GetSyntaxStack(7, 2)) AssertEqual 0, len(GetSyntaxStack(8, 2))