From 6b0a6220170f78813ad79960c1977cdb17c6cdf2 Mon Sep 17 00:00:00 2001 From: dece Date: Tue, 4 May 2021 22:29:00 +0200 Subject: [PATCH] gemtext: fix issue with preformatted blocks --- BOARD.txt | 1 + bebop/gemtext.py | 25 +++++++++++++------------ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/BOARD.txt b/BOARD.txt index 00fb7f7..930018c 100644 --- a/BOARD.txt +++ b/BOARD.txt @@ -30,3 +30,4 @@ buffers (tabs) handle soft-hyphens on wrapping bug: combining chars reduce lengths non shit command-line +response code 11 (if still there) diff --git a/bebop/gemtext.py b/bebop/gemtext.py index 330cd65..1fac047 100644 --- a/bebop/gemtext.py +++ b/bebop/gemtext.py @@ -66,6 +66,18 @@ def parse_gemtext(text: str) -> ParsedGemtext: if not line: 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) if match: hashtags, text = match.groups() @@ -84,14 +96,6 @@ def parse_gemtext(text: str) -> ParsedGemtext: elements.append(Link(url, text, last_link_id)) continue - if line.startswith(Preformatted.FENCE): - if preformatted: - elements.append(preformatted) - preformatted = None - else: - preformatted = Preformatted([]) - continue - match = Blockquote.RE.match(line) if match: text = match.groups()[0] @@ -104,10 +108,7 @@ def parse_gemtext(text: str) -> ParsedGemtext: elements.append(ListItem(text)) continue - if preformatted: - preformatted.lines.append(line) - else: - elements.append(Paragraph(line)) + elements.append(Paragraph(line)) # 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.