(click)
+ in plain text
+ """
+ log.debug(text)
+ xml = ElementTree(ET.fromstring(text))
+ for parent in xml.getiterator():
+ previous_child = None
+ for child in parent:
+ if child.tag == '{http://www.w3.org/1999/xhtml}a':
+ link_text = '\n%s (%s)'%(child.attrib['href'], child.text)
+ if previous_child is not None:
+ if previous_child.tail is None:
+ previous_child.tail = link_text
+ else:
+ previous_child.tail += link_text
+ else:
+ if parent.text is None:
+ parent.text = link_text
+ else:
+ parent.text += link_text
+ parent.remove(child)
+ previous_child = child
+ return ET.tostring(xml.getroot())
+
def clean_text(string):
"""
Remove all \x19 from the string
@@ -180,15 +212,4 @@ def poezio_colors_to_xhtml(string):
self._win.attron(common.curses_color_pair(int(attr_char)))
next_attr_char = string.find('\x19')
-if __name__ == '__main__':
-# print(xhtml_code_to_shell_colors("""
-#
-#
-#
-# Wow, I'm green
-# with envy!
-#
-#
-#
-# """))
- print(poezio_colors_to_html('\x191red\x19o \x192green\x19o \x19b\x192green and bold'))
+