prompt-toolkit / python-prompt-toolkit

Library for building powerful interactive command line applications in Python
https://python-prompt-toolkit.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
9.2k stars 715 forks source link

doc example on to_formatted_text #742

Open 2sn opened 5 years ago

2sn commented 5 years ago

The example on https://python-prompt-toolkit.readthedocs.io/en/2.0.5/pages/printing_text.html

from prompt_toolkit.formatted_text import to_formatted_text, HTML
from prompt_toolkit import print_formatted_text

html = HTML('<aaa>Hello</aaa> <bbb>world</bbb>!')
text = to_formatted_text(html, style='class:my_html bg:#00ff00 italic')

print_formatted_text(text)

produces just the output

[('class:my_html bg:#00ff00 italic class:aaa', 'Hello'), ('class:my_html bg:#00ff00 italic ', ' '), ('class:my_html bg:#00ff00 italic class:bbb', 'world'), ('class:my_html bg:#00ff00 italic ', '!')].

I assume this is not what was intended? So it is less clear what it is intended to show and how. It also does not accept a prompt_toolkit.styles.Style object as style, as one would have expected or hoped.

jonathanslenders commented 5 years ago

Thank you for reporting, @2sn! This is a bug indeed. I have to think about it, because solving it might require some changes that could break other stuff.