I'm working on a blog with Django, however my question is Python related not really Django related.
To write my blog posts I use Quill which generate the post in HTML. I save this HTML in the database than display the post using the filter |safe. Until now everything worked well until ... I want to display HTML code as examples which is obviously considered as safe because of the filter and is interpreted by the browser.
As a workaround I try to create a function able to escape HTML code as soon as they are between the tags but not escape the HTML out of this tag.
For example if quill return this:
<p> This is the code you need:
<pre class="myclass"> <div> The code </div> </pre>
</p>
I would like to save in database something like this:
<p> This is the code you need:
<pre class="myclass"> <div> The code </div> </pre>
</p>
That way the safe tag will make the HTML code interpreted and display the HTML code inside the tag.
My problem is I don't find a way to make a replacement for each character only between the tags and keep everything as it is.
Basically I try to replace characters only in a substring of a string.
I'm running on python3.10
Any idea?