'u': [0, 1, 4, 34], # URL
'M': [0, 1, 4, 35], # media URL
'm': [0, 35], # media description
+ '!': [0, 1, 7, 43, 31], # error report
}
class ColouredString:
super().__init__()
self.paras = [Paragraph()]
self.colourstack = [' ']
+ self.bad_tags = set()
def handle_starttag(self, tag, attrs):
attrdict = dict(attrs)
# and _perhaps_ that ought to generate paragraphs with a
# 'truncate, don't wrap' attribute?
- print("UNKNOWN START", tag, attrs)
+ self.bad_tags.add(tag)
def handle_endtag(self, tag):
if tag == "span":
while len(self.paras) > 0 and self.paras[-1].empty():
self.paras.pop()
+ if len(self.bad_tags) > 0:
+ error_para = Paragraph()
+ text = "Unsupported markup tags: " + " ".join(
+ f"<{tag}>" for tag in sorted(self.bad_tags))
+ error_para.add(ColouredString(text, '!'))
+ error_para.end_word()
+ self.paras[0:0] = [error_para, Paragraph()]
+
class RenderTests(unittest.TestCase):
def testBlank(self):
bl = BlankLine()
' @@@@@@@@@'),
])
+ def testError(self):
+ html = """<p>Test of some <nonsense>unsupported</nonsense> <blither>HTML tags</blither></p>"""
+ self.assertEqual(self.parse_html(html), [
+ ColouredString('Unsupported markup tags: <blither> <nonsense>',
+ '!!!!!!!!!!! !!!!!! !!!!! !!!!!!!!! !!!!!!!!!!'),
+ ColouredString(''),
+ ColouredString('Test of some unsupported HTML tags'),
+ ])
+
def testMedia(self):
ma = Media('https://a.b/c', 'foo foo foo foo foo foo foo')
self.assertEqual(list(ma.render(16)), [