Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9041a5d

Browse files
committed
Allow DOCTYPEs to round-trip, keeping public/system identifiers.
1 parent4751ac4 commit9041a5d

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

‎src/html5lib/serializer/htmlserializer.py‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,23 @@ def serialize(self, treewalker, encoding=None):
103103
fortokenintreewalker:
104104
type=token["type"]
105105
iftype=="Doctype":
106-
doctype=u"<!DOCTYPE %s>"%token["name"]
106+
doctype=u"<!DOCTYPE %s"%token["name"]
107+
108+
iftoken["publicId"]:
109+
doctype+=u' PUBLIC "%s"'%token["publicId"]
110+
eliftoken["systemId"]:
111+
doctype+=u" SYSTEM"
112+
iftoken["systemId"]:
113+
iftoken["systemId"].find(u'"')>=0:
114+
iftoken["systemId"].find(u"'")>=0:
115+
self.serializeError(_("System identifer contains both single and double quote characters"))
116+
quote_char=u"'"
117+
else:
118+
quote_char=u'"'
119+
doctype+=u" %s%s%s"% (quote_char,token["systemId"],quote_char)
120+
121+
doctype+=u">"
122+
107123
ifencoding:
108124
yielddoctype.encode(encoding)
109125
else:

‎tests/test_serializer.py‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,12 @@ def __iter__(self):
3939
fortokeninself.text(token[1]):
4040
yieldtoken
4141
eliftype=="Doctype":
42-
yieldself.doctype(token[1])
42+
iflen(token)==4:
43+
yieldself.doctype(token[1],token[2],token[3])
44+
eliflen(token)==3:
45+
yieldself.doctype(token[1],token[2])
46+
else:
47+
yieldself.doctype(token[1])
4348
else:
4449
raiseValueError("Unknown token type: "+type)
4550

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp