mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Ensure root tag is in correct namespace
This commit is contained in:
parent
ddb96c0eed
commit
9f02e70317
@ -755,11 +755,14 @@ def ensure_body(root):
|
|||||||
|
|
||||||
|
|
||||||
def html_as_json(root):
|
def html_as_json(root):
|
||||||
|
ns, name = split_name(root.tag)
|
||||||
|
if ns not in (None, XHTML_NS):
|
||||||
|
raise ValueError('HTML tag must be in empty or XHTML namespace')
|
||||||
|
ensure_body(root)
|
||||||
try:
|
try:
|
||||||
serialize = plugins['html_as_json'][0].serialize
|
serialize = plugins['html_as_json'][0].serialize
|
||||||
except KeyError:
|
except KeyError:
|
||||||
return as_bytes(json.dumps(html_as_dict(root), ensure_ascii=False, separators=(',', ':')))
|
return as_bytes(json.dumps(html_as_dict(root), ensure_ascii=False, separators=(',', ':')))
|
||||||
ensure_body(root)
|
|
||||||
for child in tuple(root.iterchildren('*')):
|
for child in tuple(root.iterchildren('*')):
|
||||||
if child.tag.partition('}')[-1] not in ('head', 'body'):
|
if child.tag.partition('}')[-1] not in ('head', 'body'):
|
||||||
root.remove(child)
|
root.remove(child)
|
||||||
@ -768,7 +771,6 @@ def html_as_json(root):
|
|||||||
|
|
||||||
|
|
||||||
def html_as_dict(root):
|
def html_as_dict(root):
|
||||||
ensure_body(root)
|
|
||||||
for child in tuple(root.iterchildren('*')):
|
for child in tuple(root.iterchildren('*')):
|
||||||
if child.tag.partition('}')[-1] not in ('head', 'body'):
|
if child.tag.partition('}')[-1] not in ('head', 'body'):
|
||||||
root.remove(child)
|
root.remove(child)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user