Fix: HTML Conversion: List with wrapped lines (#1008)
Track how many leading spaces a list item has in order to determine whether we should start a blockquote. Note the extra close tag in the added test: this is a pre-existing issue already present on `dev`.
This commit is contained in:
+21
-10
@@ -1005,7 +1005,7 @@ function! s:process_tag_arrow_quote(line, arrow_quote) abort
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
|
||||||
function! s:process_tag_list(line, lists) abort
|
function! s:process_tag_list(line, lists, lstLeadingSpaces) abort
|
||||||
function! s:add_checkbox(line, rx_list) abort
|
function! s:add_checkbox(line, rx_list) abort
|
||||||
let st_tag = '<li>'
|
let st_tag = '<li>'
|
||||||
let chk = matchlist(a:line, a:rx_list)
|
let chk = matchlist(a:line, a:rx_list)
|
||||||
@@ -1026,6 +1026,7 @@ function! s:process_tag_list(line, lists) abort
|
|||||||
|
|
||||||
|
|
||||||
let in_list = (len(a:lists) > 0)
|
let in_list = (len(a:lists) > 0)
|
||||||
|
let lstLeadingSpaces = a:lstLeadingSpaces
|
||||||
|
|
||||||
" If it is not list yet then do not process line that starts from *bold*
|
" If it is not list yet then do not process line that starts from *bold*
|
||||||
" text.
|
" text.
|
||||||
@@ -1033,12 +1034,14 @@ function! s:process_tag_list(line, lists) abort
|
|||||||
if !in_list
|
if !in_list
|
||||||
let pos = match(a:line, '^\s*' . s:rxBold)
|
let pos = match(a:line, '^\s*' . s:rxBold)
|
||||||
if pos != -1
|
if pos != -1
|
||||||
return [0, []]
|
return [0, [], lstLeadingSpaces]
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
let lines = []
|
let lines = []
|
||||||
let processed = 0
|
let processed = 0
|
||||||
|
let checkboxRegExp = '\s*\[\(.\)\]\s*'
|
||||||
|
let maybeCheckboxRegExp = '\%('.checkboxRegExp.'\)\?'
|
||||||
|
|
||||||
if a:line =~# '^\s*'.s:bullets.'\s'
|
if a:line =~# '^\s*'.s:bullets.'\s'
|
||||||
let lstSym = matchstr(a:line, s:bullets)
|
let lstSym = matchstr(a:line, s:bullets)
|
||||||
@@ -1057,22 +1060,29 @@ function! s:process_tag_list(line, lists) abort
|
|||||||
let lstRegExp = ''
|
let lstRegExp = ''
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
" If we're at the start of a list, figure out how many spaces indented we are so we can later
|
||||||
|
" determine whether we're indented enough to be at the setart of a blockquote
|
||||||
|
if lstSym !=# ''
|
||||||
|
let lstLeadingSpaces = strlen(matchstr(a:line, lstRegExp.maybeCheckboxRegExp))
|
||||||
|
endif
|
||||||
|
|
||||||
" Jump empty lines
|
" Jump empty lines
|
||||||
if in_list && a:line =~# '^$'
|
if in_list && a:line =~# '^$'
|
||||||
" Just Passing my way, do you mind ?
|
" Just Passing my way, do you mind ?
|
||||||
let [processed, lines, quote] = s:process_tag_precode(a:line, g:state.quote)
|
let [processed, lines, quote] = s:process_tag_precode(a:line, g:state.quote)
|
||||||
let processed = 1
|
let processed = 1
|
||||||
return [processed, lines]
|
return [processed, lines, lstLeadingSpaces]
|
||||||
endif
|
endif
|
||||||
|
|
||||||
" Can embeded indented code in list (Issue #55)
|
" Can embeded indented code in list (Issue #55)
|
||||||
let b_permit = in_list
|
let b_permit = in_list
|
||||||
let b_match = lstSym ==# '' && a:line =~# '^\s\{4,}[^[:space:]>*-]'
|
let blockquoteRegExp = '^\s\{' . (lstLeadingSpaces + 2) . ',}[^[:space:]>*-]'
|
||||||
|
let b_match = lstSym ==# '' && a:line =~# blockquoteRegExp
|
||||||
let b_match = b_match || g:state.quote
|
let b_match = b_match || g:state.quote
|
||||||
if b_permit && b_match
|
if b_permit && b_match
|
||||||
let [processed, lines, g:state.quote] = s:process_tag_precode(a:line, g:state.quote)
|
let [processed, lines, g:state.quote] = s:process_tag_precode(a:line, g:state.quote)
|
||||||
if processed == 1
|
if processed == 1
|
||||||
return [processed, lines]
|
return [processed, lines, lstLeadingSpaces]
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
@@ -1083,8 +1093,7 @@ function! s:process_tag_list(line, lists) abort
|
|||||||
let line = substitute(a:line, '\t', repeat(' ', &tabstop), 'g')
|
let line = substitute(a:line, '\t', repeat(' ', &tabstop), 'g')
|
||||||
let indent = stridx(line, lstSym)
|
let indent = stridx(line, lstSym)
|
||||||
|
|
||||||
let checkbox = '\s*\[\(.\)\]\s*'
|
let [st_tag, en_tag] = s:add_checkbox(line, lstRegExp.checkboxRegExp)
|
||||||
let [st_tag, en_tag] = s:add_checkbox(line, lstRegExp.checkbox)
|
|
||||||
|
|
||||||
if !in_list
|
if !in_list
|
||||||
call add(a:lists, [lstTagClose, indent])
|
call add(a:lists, [lstTagClose, indent])
|
||||||
@@ -1107,7 +1116,7 @@ function! s:process_tag_list(line, lists) abort
|
|||||||
|
|
||||||
call add(a:lists, [en_tag, indent])
|
call add(a:lists, [en_tag, indent])
|
||||||
call add(lines, st_tag)
|
call add(lines, st_tag)
|
||||||
call add(lines, substitute(a:line, lstRegExp.'\%('.checkbox.'\)\?', '', ''))
|
call add(lines, substitute(a:line, lstRegExp.maybeCheckboxRegExp, '', ''))
|
||||||
let processed = 1
|
let processed = 1
|
||||||
|
|
||||||
elseif in_list && a:line =~# '^\s\+\S\+'
|
elseif in_list && a:line =~# '^\s\+\S\+'
|
||||||
@@ -1123,7 +1132,7 @@ function! s:process_tag_list(line, lists) abort
|
|||||||
call s:close_tag_list(a:lists, lines)
|
call s:close_tag_list(a:lists, lines)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
return [processed, lines]
|
return [processed, lines, lstLeadingSpaces]
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
|
||||||
@@ -1323,6 +1332,7 @@ function! s:parse_line(line, state) abort
|
|||||||
let state.quote = a:state.quote
|
let state.quote = a:state.quote
|
||||||
let state.arrow_quote = a:state.arrow_quote
|
let state.arrow_quote = a:state.arrow_quote
|
||||||
let state.active_multiline_comment = a:state.active_multiline_comment
|
let state.active_multiline_comment = a:state.active_multiline_comment
|
||||||
|
let state.list_leading_spaces = a:state.list_leading_spaces
|
||||||
let state.pre = a:state.pre[:]
|
let state.pre = a:state.pre[:]
|
||||||
let state.math = a:state.math[:]
|
let state.math = a:state.math[:]
|
||||||
let state.table = a:state.table[:]
|
let state.table = a:state.table[:]
|
||||||
@@ -1490,7 +1500,7 @@ function! s:parse_line(line, state) abort
|
|||||||
|
|
||||||
" lists
|
" lists
|
||||||
if !processed
|
if !processed
|
||||||
let [processed, lines] = s:process_tag_list(line, state.lists)
|
let [processed, lines, state.list_leading_spaces] = s:process_tag_list(line, state.lists, state.list_leading_spaces)
|
||||||
if processed && state.quote
|
if processed && state.quote
|
||||||
let state.quote = s:close_tag_precode(state.quote, lines)
|
let state.quote = s:close_tag_precode(state.quote, lines)
|
||||||
endif
|
endif
|
||||||
@@ -1715,6 +1725,7 @@ function! s:convert_file_to_lines(wikifile, current_html_file) abort
|
|||||||
let state.quote = 0
|
let state.quote = 0
|
||||||
let state.arrow_quote = 0
|
let state.arrow_quote = 0
|
||||||
let state.active_multiline_comment = 0
|
let state.active_multiline_comment = 0
|
||||||
|
let state.list_leading_spaces = 0
|
||||||
let state.pre = [0, 0] " [in_pre, indent_pre]
|
let state.pre = [0, 0] " [in_pre, indent_pre]
|
||||||
let state.math = [0, 0] " [in_math, indent_math]
|
let state.math = [0, 0] " [in_math, indent_math]
|
||||||
let state.table = []
|
let state.table = []
|
||||||
|
|||||||
@@ -28,6 +28,39 @@ Expect (Tested by hand 2):
|
|||||||
|
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
|
Given vimwiki (Issue 1007: List with hard wraps and a blockquote):
|
||||||
|
- Item 1
|
||||||
|
wraps to the second line.
|
||||||
|
This is a blockquote.
|
||||||
|
|
||||||
|
And this is back to the list item
|
||||||
|
- [ ] Item 2
|
||||||
|
wraps to the second line.
|
||||||
|
This is a blockquote.
|
||||||
|
|
||||||
|
And this is back to the list item
|
||||||
|
|
||||||
|
Execute (2Html):
|
||||||
|
call ConvertWiki2Body() | 1d | $d | $d
|
||||||
|
|
||||||
|
Expect (No blockquote):
|
||||||
|
<ul>
|
||||||
|
<li>
|
||||||
|
Item 1
|
||||||
|
wraps to the second line.
|
||||||
|
<pre><code>This is a blockquote.
|
||||||
|
</code></pre>
|
||||||
|
</code></pre>
|
||||||
|
And this is back to the list item
|
||||||
|
|
||||||
|
<li class="done0">
|
||||||
|
Item 2
|
||||||
|
wraps to the second line.
|
||||||
|
<pre><code>This is a blockquote.
|
||||||
|
</code></pre>
|
||||||
|
And this is back to the list item
|
||||||
|
|
||||||
|
</ul>
|
||||||
|
|
||||||
#Given (Issue 3: BlockQuote at multiple list levels {{{3):
|
#Given (Issue 3: BlockQuote at multiple list levels {{{3):
|
||||||
# 1. Outer Item 1
|
# 1. Outer Item 1
|
||||||
|
|||||||
Reference in New Issue
Block a user