Vimwiki2HTML: remove string concat from variable substitution (#1110)

Problem: I noticed that running :Vimwiki2HTML for a file with a `"` in
the `%title` line would error out.  For example, a title like:

    %title this will die: "

Causes:

    Error detected while processing function vimwiki#html#Wiki2HTML[1]..<SNR>177_convert_file[15]..<SNR>177_convert_file_to_lines
_template:
    line    8:
    E116: Invalid arguments for function substitute(v:val, "%title%", "this will die: "", "g")

Solution: It seems like the string concatenation here was unnecessary.
At least on my vim 8.1, the evaluated code seems to have access to the
correct variables.

I'm sure there are bigger problems with the HTML generation here, but this
allows my ~2000 pages with titles to render without throwing errors.

Also adds a brief test and removes some unnecessary DeleteFile() calls
from html_convert_default.vader.

Co-authored-by: Brennen Bearnes <code@p1k3.com>
This commit is contained in:
Brennen Bearnes
2021-04-05 21:07:38 -06:00
committed by GitHub
parent db85dc54c9
commit 618893be00
4 changed files with 18 additions and 19 deletions
+6 -6
View File
@@ -1831,25 +1831,25 @@ function! s:convert_file_to_lines_template(wikifile, current_html_file) abort
let html_lines = s:get_html_template(converted['template_name']) let html_lines = s:get_html_template(converted['template_name'])
" processing template variables (refactor to a function) " processing template variables (refactor to a function)
call map(html_lines, 'substitute(v:val, "%title%", "'. converted['title'] .'", "g")') call map(html_lines, 'substitute(v:val, "%title%", converted["title"], "g")')
call map(html_lines, 'substitute(v:val, "%date%", "'. converted['date'] .'", "g")') call map(html_lines, 'substitute(v:val, "%date%", converted["date"], "g")')
call map(html_lines, 'substitute(v:val, "%root_path%", "'. call map(html_lines, 'substitute(v:val, "%root_path%", "'.
\ s:root_path(vimwiki#vars#get_bufferlocal('subdir')) .'", "g")') \ s:root_path(vimwiki#vars#get_bufferlocal('subdir')) .'", "g")')
call map(html_lines, 'substitute(v:val, "%wiki_path%", "'. converted['wiki_path'] .'", "g")') call map(html_lines, 'substitute(v:val, "%wiki_path%", converted["wiki_path"], "g")')
let css_name = expand(vimwiki#vars#get_wikilocal('css_name')) let css_name = expand(vimwiki#vars#get_wikilocal('css_name'))
let css_name = substitute(css_name, '\', '/', 'g') let css_name = substitute(css_name, '\', '/', 'g')
call map(html_lines, 'substitute(v:val, "%css%", "'. css_name .'", "g")') call map(html_lines, 'substitute(v:val, "%css%", css_name, "g")')
let rss_name = expand(vimwiki#vars#get_wikilocal('rss_name')) let rss_name = expand(vimwiki#vars#get_wikilocal('rss_name'))
let rss_name = substitute(rss_name, '\', '/', 'g') let rss_name = substitute(rss_name, '\', '/', 'g')
call map(html_lines, 'substitute(v:val, "%rss%", "'. rss_name .'", "g")') call map(html_lines, 'substitute(v:val, "%rss%", rss_name, "g")')
let enc = &fileencoding let enc = &fileencoding
if enc ==? '' if enc ==? ''
let enc = &encoding let enc = &encoding
endif endif
call map(html_lines, 'substitute(v:val, "%encoding%", "'. enc .'", "g")') call map(html_lines, 'substitute(v:val, "%encoding%", enc, "g")')
let html_lines = s:html_insert_contents(html_lines, converted['html']) " %contents% let html_lines = s:html_insert_contents(html_lines, converted['html']) " %contents%
+1
View File
@@ -3955,6 +3955,7 @@ Changed:~
Removed:~ Removed:~
Fixed:~ Fixed:~
* Allow title values with quotes
* Enable strikethrough for Neovim * Enable strikethrough for Neovim
* Issue #1029: Fix: error loading plugin when lang uses comma instead of * Issue #1029: Fix: error loading plugin when lang uses comma instead of
dot as decimal separator dot as decimal separator
+1 -13
View File
@@ -1,4 +1,4 @@
# Conertion: Wiki -> Html # Conversion: Wiki -> Html
################################################# #################################################
Given vimwiki (Comments): Given vimwiki (Comments):
@@ -43,10 +43,6 @@ Expect (Comments Removed):
</html> </html>
Execute(Delete):
call DeleteFile('$HOME/testwiki/test_html_table.wiki')
call DeleteFile('$HOME/html/default/test_html_table.html')
################################################# #################################################
Given vimwiki (Table no heading {{{1): Given vimwiki (Table no heading {{{1):
| header1 | header2 | | header1 | header2 |
@@ -101,10 +97,6 @@ Expect (Table no heading):
</body> </body>
</html> </html>
Execute(Delete):
call DeleteFile('$HOME/testwiki/test_html_table.wiki')
call DeleteFile('$HOME/html/default/test_html_table.html')
Given vimwiki (Table with heading {{{1): Given vimwiki (Table with heading {{{1):
| header1 | header2 | header3 | | header1 | header2 | header3 |
@@ -165,10 +157,6 @@ Expect (Table with heading):
</html> </html>
Execute(Delete):
call DeleteFile('$HOME/testwiki/test_html_table.wiki')
call DeleteFile('$HOME/html/default/test_html_table.html')
################################################# #################################################
Execute (Log): Execute (Log):
Log '#473: Syntax "local:" doesnt work as expected. #473' Log '#473: Syntax "local:" doesnt work as expected. #473'
+10
View File
@@ -0,0 +1,10 @@
# Test that %title values carry through when HTML is rendered
Given vimwiki (Title value):
%title this is a title with some quotes in it: ' "
Some content.
Execute(Check for title tag):
call ConvertWiki2Html()
Assert 0 != search('<title>this is a title with some quotes in it: '' "</title>')