gemtext: fix issue with preformatted blocks

This commit is contained in:
dece 2021-05-04 22:29:00 +02:00
parent 1fddf4c2b2
commit 6b0a622017
2 changed files with 14 additions and 12 deletions

View file

@ -30,3 +30,4 @@ buffers (tabs)
handle soft-hyphens on wrapping handle soft-hyphens on wrapping
bug: combining chars reduce lengths bug: combining chars reduce lengths
non shit command-line non shit command-line
response code 11 (if still there)

View file

@ -66,6 +66,18 @@ def parse_gemtext(text: str) -> ParsedGemtext:
if not line: if not line:
continue continue
if line.startswith(Preformatted.FENCE):
if preformatted:
elements.append(preformatted)
preformatted = None
else:
preformatted = Preformatted([])
continue
if preformatted:
preformatted.lines.append(line)
continue
match = Title.RE.match(line) match = Title.RE.match(line)
if match: if match:
hashtags, text = match.groups() hashtags, text = match.groups()
@ -84,14 +96,6 @@ def parse_gemtext(text: str) -> ParsedGemtext:
elements.append(Link(url, text, last_link_id)) elements.append(Link(url, text, last_link_id))
continue continue
if line.startswith(Preformatted.FENCE):
if preformatted:
elements.append(preformatted)
preformatted = None
else:
preformatted = Preformatted([])
continue
match = Blockquote.RE.match(line) match = Blockquote.RE.match(line)
if match: if match:
text = match.groups()[0] text = match.groups()[0]
@ -104,10 +108,7 @@ def parse_gemtext(text: str) -> ParsedGemtext:
elements.append(ListItem(text)) elements.append(ListItem(text))
continue continue
if preformatted: elements.append(Paragraph(line))
preformatted.lines.append(line)
else:
elements.append(Paragraph(line))
# If a preformatted block is not closed before the file ends, consider it # If a preformatted block is not closed before the file ends, consider it
# closed anyway; the spec does not seem to talk about that case. # closed anyway; the spec does not seem to talk about that case.