commit 7f1357472d3ccad569135c1030ebf8c042360c5f
parent 2f1f497f888c1d49b0f2534608c8066bf014e5b3
Author: Tinmarino <tinmarino@gmail.com>
Date: Wed, 15 Mar 2023 00:54:49 -0300
Yaml metadata, fix regex (#1287)
Diffstat:
3 files changed, 8 insertions(+), 16 deletions(-)
diff --git 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
@@ -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
@@ -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))