Is it possible to prevent Genshi from parsing HTML objects?

I have the following Python code using Genshi (simplified):

with open(pathToHTMLFile, 'r') as f:
    template = MarkupTemplate(f.read())
finalPage = template.generate().render('html', doctype = 'html')

The HTML source file contains objects such as ©, ™and ®. Genshi replaces them with its UTF-8 character, which causes problems with the viewer (the output is used as a separate file, not a response to a web request), which ultimately sees the received HTML. Is there any way to prevent Genshi from parsing these entities? More general ones, such as &go through a fine.

+3
source share
3 answers

& , , & , HTML. ©, , , .

, . , , ASCII, ASCII:

template.generate().render('html', doctype= 'html', encoding= 'us-ascii')

- © , ©, , , , .

+9

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

<head> HTML- UTF-8.

, , & copy; UTF-8 HTML. HTML , , , UTF-8.

+3

To prevent escaping character markup characters (x) html in Genshi:

from genshi.core import Markup
...
newstring = Markup(oldstring)
...
<now apply templates as before, but substituting newstring for oldstring>
0
source

Source: https://habr.com/ru/post/1719897/


All Articles