leforestier / yattag

Python library to generate HTML or XML in a readable, concise and pythonic way.
332 stars 31 forks source link

support Unicode escape sequence in text() #53

Closed sandrotosi closed 5 years ago

sandrotosi commented 5 years ago

if i want to add a unicode escape sequence, say an emoji, i'd need to enter a string like &#x1F44D bit yattag text() will escape it to &#x1F44D which renders the verbatim string &#x1F44D instead of the thumbs-up emoji.

it would be great if we could have an option to not escape strings and/or any other way you see fit to support unicode sequences.

thanks!

leforestier commented 5 years ago

Hi,

if you declare the document as being utf-8 encoded, you can do this:

    text('♬ Ob-La-Di, Ob-La-Da ♬')

or in case your code editor doesn't display utf-8 characters:

    text('\u266C Ob-La-Di, Ob-La-Da \u266C')

You can see a more thorough reply I gave to the same question here: https://github.com/leforestier/yattag/issues/45

leforestier commented 5 years ago

By the way, you always have the option to insert text without escaping, that's what the asis method is for.