mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 02:34:06 -04:00
PDF Output: Remove JS from HTML files before passing them to WebKit
This commit is contained in:
parent
c2e36408d3
commit
3d586aa15a
@ -270,6 +270,18 @@ class PDFOutput(OutputFormatPlugin):
|
|||||||
if hasattr(root, 'xpath') and margins:
|
if hasattr(root, 'xpath') and margins:
|
||||||
root.set('data-calibre-pdf-output-page-margins', json.dumps(margins))
|
root.set('data-calibre-pdf-output-page-margins', json.dumps(margins))
|
||||||
|
|
||||||
|
# Remove javascript
|
||||||
|
for item in self.oeb.spine:
|
||||||
|
root = item.data
|
||||||
|
if hasattr(root, 'xpath'):
|
||||||
|
for script in root.xpath('//*[local-name()="script"]'):
|
||||||
|
script.text = None
|
||||||
|
script.attrib.clear()
|
||||||
|
for elem in root.iter('*'):
|
||||||
|
for attr in tuple(elem.attrib):
|
||||||
|
if attr.startswith('on'):
|
||||||
|
elem.set(attr, '')
|
||||||
|
|
||||||
with TemporaryDirectory('_pdf_out') as oeb_dir:
|
with TemporaryDirectory('_pdf_out') as oeb_dir:
|
||||||
from calibre.customize.ui import plugin_for_output_format
|
from calibre.customize.ui import plugin_for_output_format
|
||||||
oeb_output = plugin_for_output_format('oeb')
|
oeb_output = plugin_for_output_format('oeb')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user