Question

I have a sentence

sentence =  <p> Reading, watching or <span class="matching">listening</span> to the media isn’t <span class="matching">matching</span><span class="matching">much</span> help either. </p>

to make it render properly at front-end here is what I have done

from flask import Markup
sentence = Markup(sentence)

But the output is only rendered properly for one markup (not necessarily first one) and others are not rendered.

            <p> Reading, watching or <span class="matching">listening</span> to the media isn’t &lt;span class=&#34;matching&#34;&gt;much&lt;/span&gt; help either. </p>

What am I doing it wrong here?

Was it helpful?

Solution

The culprit is the

isn’t

that "’" is not valid ASCII, because of which it doesn't come in the valid range of characters of HTML Markup , thus it escapes it (though it should throw an error)

Hope that solves the issue.

This works for me

from flask import Markup
sentence =  '<p> Reading, watching or <span class="matching">listening</span> to the media isn\'t <span class="matching">matching</span><span class="matching">much</span> help either. </p>'
Markup(sentence)

returns

Markup(u'<p> Reading, watching or <span class="matching">listening</span> to the media isn\'t <span class="matching">matching</span><span class="matching">much</span> help either. </p>')

hope that is what is the required output

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top