From 3b11454aa195c1cc60ab36aaa87e30b9580d5592 Mon Sep 17 00:00:00 2001 From: Peter Odding Date: Sun, 23 Jun 2013 20:28:04 +0200 Subject: [PATCH] Work around a bug in the Markdown specification... --- autoload/xolox/notes/markdown.vim | 5 +++-- autoload/xolox/notes/parser.vim | 23 +++++++++++++---------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/autoload/xolox/notes/markdown.vim b/autoload/xolox/notes/markdown.vim index a50efa5..ee6a624 100644 --- a/autoload/xolox/notes/markdown.vim +++ b/autoload/xolox/notes/markdown.vim @@ -37,8 +37,9 @@ function! xolox#notes#markdown#convert_block(block) " {{{1 elseif a:block.type == 'heading' return printf("%s %s", repeat('#', 1 + a:block.level), a:block.text) elseif a:block.type == 'code' - let text = xolox#misc#str#dedent(a:block.text) - return xolox#misc#str#indent(text, 4) + let comment = "" + let text = xolox#misc#str#indent(xolox#misc#str#dedent(a:block.text), 4) + return join([comment, text], "\n\n") elseif a:block.type == 'divider' return '* * *' elseif a:block.type == 'list' diff --git a/autoload/xolox/notes/parser.vim b/autoload/xolox/notes/parser.vim index d4cb6ad..adecf3b 100644 --- a/autoload/xolox/notes/parser.vim +++ b/autoload/xolox/notes/parser.vim @@ -21,6 +21,7 @@ function! xolox#notes#parser#parse_note(text) " {{{1 elseif chr == '{' && context.peek(3) == "\{\{\{" let block = s:parse_code_block(context) else + call xolox#misc#msg#debug("notes.vim %s: Disambiguating list item from paragraph ..", g:xolox#notes#version) let lookahead = s:match_bullet_or_divider(context, 0) if !empty(lookahead) if lookahead.type =~ 'list' @@ -37,6 +38,7 @@ function! xolox#notes#parser#parse_note(text) " {{{1 endif " Don't include empty blocks in the output. if !empty(block) + call xolox#misc#msg#debug("notes.vim %s: Parsed block %s", g:xolox#notes#version, string(block)) call add(blocks, block) endif endwhile @@ -215,17 +217,18 @@ function! s:parse_list(context) " {{{1 endif endif let line = s:match_line(a:context) - if line[-1:] == "\n" - call add(lines, line) - elseif !empty(line) - call add(lines, line) - else - " FIXME What happens when we find an empty line? Here's what: - " 1. If the line after that starts without indentation, we found - " the end of the list. - " 2. If the line starts with indentation, we are dealing with a - " list item that contains multiple paragraphs... + call add(lines, line) + if line[-1:] != "\n" + " XXX When match_line() returns a line that doesn't end in a newline + " character, it means either we hit the end of the input or the current + " line continues in a code block (which is not ours to parse :-). + break endif + " FIXME What happens when we find an empty line? Here's what: + " 1. If the line after that starts without indentation, we found + " the end of the list. + " 2. If the line starts with indentation, we are dealing with a + " list item that contains multiple paragraphs... endwhile call s:save_item(items, lines, indent) return {'type': 'list', 'ordered': (list_type == 'ordered-list'), 'items': items}