Skip to content

Commit f4a8d8b

Browse files
committed
Fix nested blockquotes
1 parent 94a3fb8 commit f4a8d8b

File tree

1 file changed

+22
-19
lines changed

1 file changed

+22
-19
lines changed

pdfsyntax/markdown.py

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -308,14 +308,14 @@ def render_htmlV2(md: str):
308308
def tokenize(md: str) -> list:
309309
"""Split input string and transform some tokens to facilitate further processing."""
310310
res = ['\n', '\n']
311-
i = 2
311+
i = 0
312312
last_nl = 0
313313
before_nl = 0
314314
tok = ''
315315
UNDER2FRONT = {'=': '#', '-': '##'}
316316
while i < len(md):
317317
c = md[i]
318-
#y, z = res[-2], res[-1]
318+
print(tok)
319319
if c in '\n[]()>*_`-+.':
320320
if c == '\n':
321321
before_nl = last_nl
@@ -387,16 +387,20 @@ def emit_html(toks: list, start = 2, stack = ['']):
387387
return i+1, res
388388
elif y == '\n' and z == len(toks[i]) * '#':
389389
return i, res
390-
elif y == '\n' and z in '>>>>>>' and len(stack) > 1 and stack[-2] in '>>>>>>':
390+
elif y == '\n' and z[:1] == '>' and len(stack) > 1 and stack[-2] != f'>{len(z)}':
391+
return i, res
392+
elif y == '\n' and z[:1] != '>' and len(stack) > 1 and stack[-2][:1] == '>':
391393
return i, res
392-
elif context in '>>>>>>':
393-
if i > 0 and y == '\n' and (z == context[:-1] or z[0] != '>'):
394+
elif context[:1] == '>':
395+
if y == '\n' and z[:1] == '>' and int(context[1:]) > len(z):
396+
return i+1, res
397+
elif y == '\n' and z[:1] != '>':
394398
return i+1, res
395399
elif context == 'indented':
396-
if i > 0 and y == '\n' and z != ' ':
400+
if y == '\n' and z != ' ':
397401
return i, res
398402
elif context == 'fenced':
399-
if i > 0 and y == '\n' and (z == '```' or z == '~~~'):
403+
if y == '\n' and (z == '```' or z == '~~~'):
400404
return i+1, res
401405
elif context[:2] == 'ul':
402406
if x == '\n' and y == len(y) * ' ' and z == '-*+' and len(y) < int(context[2:]):
@@ -477,25 +481,24 @@ def emit_html(toks: list, start = 2, stack = ['']):
477481
elif x == '\n' and y == len(y) * ' ' and z[-1] == '.':
478482
i, r = emit_html(toks, i, stack + [f'ol{len(y)}'])
479483
res += f'\n<ol>{r}\n</ol>'
480-
elif context != '>' and y == '\n' and z == '>':
481-
if i < len(toks) - 1:
482-
toks[i+1] = toks[i+1].lstrip()
483-
i, r = emit_html(toks, i+1, stack + ['>'])
484+
elif not context and y == '\n' and z == '>':
485+
i, r = emit_html(toks, i+1, stack + ['>1'])
484486
res += f'\n<blockquote>{r}\n</blockquote>'
485-
elif context in '>>>>>' and y == '\n' and z == context + '>':
486-
if i < len(toks) - 1:
487-
toks[i+1] = toks[i+1].lstrip()
488-
i, r = emit_html(toks, i, stack + [toks[i]])
487+
elif context[:1] == '>' and y == '\n' and z == (int(context[1:])+1) * '>':
488+
i, r = emit_html(toks, i, stack + [f'>{len(z)}'])
489489
res += f'\n<blockquote>{r}\n</blockquote>'
490-
elif context in '>>>>>' and toks[i-1] == '\n' and toks[i] == ' ':
490+
elif context[:1] == '>' and toks[i-1] == '\n' and toks[i] == ' ':
491491
i, r = emit_html(toks, i+1, stack + ['indented'])
492492
res += f'\n<pre><code>{r}</code></pre>'
493493
elif context == 'pre&code' and y == '\n' and z == ' ':
494494
i += 1
495-
elif context and context[:2] in ['ul', 'ol'] and z == len(z) * ' ':
495+
elif context[:2] in ['ul', 'ol'] and z == len(z) * ' ':
496496
i += 1
497-
elif context and context[:2] not in ['ul', 'ol'] and context not in '>>>>>':
498-
res += z
497+
elif context and context[:1] not in ['u', 'o', '>']:
498+
if context == 'p' and len(stack) > 1 and stack[-2][:1] == '>' and z in '>>>>>':
499+
pass
500+
else:
501+
res += z
499502
i += 1
500503
else:
501504
if z == '' or z == '\n':

0 commit comments

Comments
 (0)