From 23241209f80b4961d706b151d718e1c5b2d5c632 Mon Sep 17 00:00:00 2001 From: Karl Bartel Date: Wed, 2 Oct 2019 22:20:02 +0200 Subject: [PATCH] Fix blockquotes * nesting did not work * ">" without following space was not recognized as blockquote Quoting https://spec.commonmark.org/0.29/#example-5: > Normally the > that begins a block quote may be followed optionally by a space, which is not considered part of the content. --- smu.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/smu.c b/smu.c index 8194591..50727f4 100644 --- a/smu.c +++ b/smu.c @@ -44,7 +44,7 @@ static int nohtml = 0; static Tag lineprefix[] = { { " ", 0, "
", "\n
" }, { "\t", 0, "
", "\n
" }, - { "> ", 2, "
", "
" }, + { ">", 2, "
", "
" }, { "###### ", 1, "
", "
" }, { "##### ", 1, "
", "
" }, { "#### ", 1, "

", "

" }, @@ -212,12 +212,22 @@ dolineprefix(const char *begin, const char *end, int newblock) { if(!(buffer = malloc(BUFSIZ))) eprint("Malloc failed."); buffer[0] = '\0'; - for(j = 0, p += l; p < end; p++, j++) { - ADDC(buffer, j) = *p; - if(*p == '\n' && p + l < end) { - if(strncmp(lineprefix[i].search, p + 1, l) != 0) + + /* Collect lines into buffer while they start with the prefix */ + j = 0; + while((strncmp(lineprefix[i].search, p, l) == 0) && p + l < end) { + p += l; + + /* Special case for blockquotes: optional space after > */ + if(lineprefix[i].search[0] == '>' && *p == ' ') { + p++; + } + + while(p < end) { + ADDC(buffer, j) = *p; + j++; + if(*(p++) == '\n') break; - p += l; } }