# HG changeset patch # User Ludovic Chabant # Date 1706936830 28800 # Node ID 58348b2e6085c269aaba1d29f541b9bbe11eef5c # Parent b8a9c206ac7cc0257289b8d7cb659e84b648ae6c Fix bugs with text formatting - Fix measuring of article URLs and bulleted/ordered lists - Fix percent-escaping of link texts diff -r b8a9c206ac7c -r 58348b2e6085 silorider/format.py --- a/silorider/format.py Fri Feb 02 21:05:23 2024 -0800 +++ b/silorider/format.py Fri Feb 02 21:07:10 2024 -0800 @@ -86,9 +86,10 @@ # stuff with it (for instance the Bluesky silo will remember the # byte offsets to insert a hyperlink). if do_add_url and url: - ctx.reportAddedText(1) url = _process_end_url(url, ctx) card.text += ' ' + url + url_len = ctx.url_flattener.measureUrl(url) + ctx.reportAddedText(1 + url_len) return card @@ -368,7 +369,7 @@ # Get the text under the hyperlink. cnts = list(elem.contents) if len(cnts) == 1: - a_txt = cnts[0].string + a_txt = _escape_percents(cnts[0].string) else: a_txt = ''.join([_do_strip_html(c, ctx) for c in cnts]) @@ -416,17 +417,18 @@ outtxt = '' for i, c in enumerate(elem.children): if c.name == 'li': - outtxt += ('%s. ' % (i + 1)) + _do_strip_html(c, ctx) - outtxt += '\n' - return ctx.processText(outtxt) + ol_prefix = ('%s. ' % (i + 1)) + outtxt += ol_prefix + _do_strip_html(c, ctx) + '\n' + ctx.reportAddedText(ol_prefix + 1) + return outtxt if elem.name == 'ul': outtxt = '' for c in elem.children: if c.name == 'li': - outtxt += '- ' + _do_strip_html(c, ctx) - outtxt += '\n' - return ctx.processText(outtxt) + outtxt += '- ' + _do_strip_html(c, ctx) + '\n' + ctx.reportAddedText(3) + return outtxt if elem.name == 'p': # Add a newline before starting a paragraph only if this isn't @@ -434,6 +436,7 @@ p_txt = '' if ctx.text_length > 0: p_txt = '\n' + ctx.reportAddedText(1) for c in elem.children: p_txt += _do_strip_html(c, ctx) return p_txt