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

Commit0c551c9

Browse files
committed
Make lxml tree-builder coerce comments to work with lxml 3.5.
1 parentdae03f6 commit0c551c9

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

‎html5lib/ihatexml.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,9 @@ def coerceComment(self, data):
225225
while"--"indata:
226226
warnings.warn("Comments cannot contain adjacent dashes",DataLossWarning)
227227
data=data.replace("--","- -")
228+
ifdata.endswith("-"):
229+
warnings.warn("Comments cannot end in a dash",DataLossWarning)
230+
data+=" "
228231
returndata
229232

230233
defcoerceCharacters(self,data):

‎html5lib/treebuilders/etree_lxml.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def _getChildNodes(self):
5454
deftestSerializer(element):
5555
rv= []
5656
finalText=None
57-
infosetFilter=ihatexml.InfosetFilter()
57+
infosetFilter=ihatexml.InfosetFilter(preventDoubleDashComments=True)
5858

5959
defserializeElement(element,indent=0):
6060
ifnothasattr(element,"tag"):
@@ -189,7 +189,7 @@ class TreeBuilder(_base.TreeBuilder):
189189

190190
def__init__(self,namespaceHTMLElements,fullTree=False):
191191
builder=etree_builders.getETreeModule(etree,fullTree=fullTree)
192-
infosetFilter=self.infosetFilter=ihatexml.InfosetFilter()
192+
infosetFilter=self.infosetFilter=ihatexml.InfosetFilter(preventDoubleDashComments=True)
193193
self.namespaceHTMLElements=namespaceHTMLElements
194194

195195
classAttributes(dict):
@@ -257,7 +257,7 @@ def _getData(self):
257257
data=property(_getData,_setData)
258258

259259
self.elementClass=Element
260-
self.commentClass=builder.Comment
260+
self.commentClass=Comment
261261
# self.fragmentClass = builder.DocumentFragment
262262
_base.TreeBuilder.__init__(self,namespaceHTMLElements)
263263

@@ -344,7 +344,8 @@ def insertRoot(self, token):
344344

345345
# Append the initial comments:
346346
forcomment_tokeninself.initial_comments:
347-
root.addprevious(etree.Comment(comment_token["data"]))
347+
comment=self.commentClass(comment_token["data"])
348+
root.addprevious(comment._element)
348349

349350
# Create the root document and add the ElementTree to it
350351
self.document=self.documentClass()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp