chiark / gitweb /
Support <blockquote> in HTML.
authorSimon Tatham <anakin@pobox.com>
Thu, 14 Dec 2023 22:40:13 +0000 (22:40 +0000)
committerSimon Tatham <anakin@pobox.com>
Thu, 14 Dec 2023 22:40:13 +0000 (22:40 +0000)
text.py

diff --git a/text.py b/text.py
index b75cac0745908353184a72149506de1fafb8ecec..2b8b627d0e3cfcaea996833c17f3b21b0a104b17 100644 (file)
--- a/text.py
+++ b/text.py
@@ -461,6 +461,11 @@ class HTMLParser(html.parser.HTMLParser):
         self.paras = [Paragraph()]
         self.colourstack = [' ']
         self.bad_tags = set()
+        self.indent = 0
+
+    def new_para(self):
+        return (Paragraph() if self.indent == 0
+                else IndentedParagraph(self.indent, self.indent))
 
     def handle_starttag(self, tag, attrs):
         attrdict = dict(attrs)
@@ -479,11 +484,16 @@ class HTMLParser(html.parser.HTMLParser):
         if tag == "p":
             if not self.paras[-1].empty():
                 self.paras.append(Paragraph())
-            self.paras.append(Paragraph())
+            self.paras.append(self.new_para())
             return
 
         if tag == "br":
-            self.paras.append(Paragraph())
+            self.paras.append(self.new_para())
+            return
+
+        if tag == "blockquote":
+            self.indent += 2
+            self.paras.append(self.new_para())
             return
 
         if tag == "code":
@@ -510,8 +520,15 @@ class HTMLParser(html.parser.HTMLParser):
             return
 
         if tag == "p":
+            if not self.paras[-1].empty():
+                self.paras.append(self.new_para())
+            return
+
+        if tag == "blockquote":
             if not self.paras[-1].empty():
                 self.paras.append(Paragraph())
+            self.indent -= 2
+            self.paras.append(self.new_para())
             return
 
         if tag in {"a", "code", "strong", "em", "i"}: