# data that converts each one into a list of integers that go in an
# ECMA-48 style SGR control sequence.
colourmap = {
- ' ': [],
- 'S': [0, 1, 7, 44, 37],
- 'D': [0, 7, 44, 37],
- 'F': [0, 1, 32],
- 'f': [0, 32],
- 'c': [0, 33],
- '#': [0, 36],
- '@': [0, 32],
- 'M': [0, 1, 4, 35],
- 'm': [0, 35],
+ ' ': [], # default
+ 'S': [0, 1, 7, 44, 37], # message separator line, other than the date
+ 'D': [0, 7, 44, 37], # date on a message separator line
+ 'F': [0, 1, 32], # username in a From line
+ 'f': [0, 32], # username in other headers like Via
+ 'c': [0, 33], # <code> tags
+ '#': [0, 36], # #hashtags
+ '@': [0, 32], # @mentions of a user
+ 's': [0, 1], # <strong> tags
+ 'u': [0, 1, 4, 34], # URL
+ 'M': [0, 1, 4, 35], # media URL
+ 'm': [0, 35], # media description
}
class ColouredString:
if tag == "a":
classes = set(attrdict.get("class", "").split())
colour = ("#" if "hashtag" in classes else
- "@" if "mention" in classes else " ")
+ "@" if "mention" in classes else
+ "u" if "href" in attrdict else " ")
self.colourstack.append(colour)
return
self.colourstack.append('c')
return
+ if tag == "strong":
+ self.colourstack.append('s')
+ return
+
# FIXME: need <pre>, e.g. in
# https://neuromatch.social/@mstimberg/111375114784712346
# and _perhaps_ that ought to generate paragraphs with a
self.paras.append(Paragraph())
return
- if tag in {"a", "code"}:
+ if tag in {"a", "code", "strong"}:
self.colourstack.pop()
return
html = "<p>Test of some <code>literal code</code></p>"
self.assertEqual(self.parse_html(html), [
ColouredString('Test of some literal code',
- ' cccccccccccc'),
+ ' ccccccc cccc'),
+ ])
+
+ html = "<p>Test of some <strong>strong text</strong></p>"
+ self.assertEqual(self.parse_html(html), [
+ ColouredString('Test of some strong text',
+ ' ssssss ssss'),
])
html = """<p>Test of a <a href="https://some.instance/tags/hashtag" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>hashtag</span></a></p>"""