mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-08-05 08:40:13 -04:00
Implement tester for HTML transforms
This commit is contained in:
parent
9b2c742341
commit
3e9e49d06c
@ -387,6 +387,13 @@ def transform_doc(root, rules):
|
||||
return changed
|
||||
|
||||
|
||||
def transform_html(html, serialized_rules):
|
||||
root = parse(html, namespace_elements=True)
|
||||
rules = tuple(Rule(r) for r in serialized_rules)
|
||||
changed = transform_doc(root, rules)
|
||||
return changed, etree.tostring(root, encoding='unicode')
|
||||
|
||||
|
||||
def transform_container(container, serialized_rules, names=()):
|
||||
if not names:
|
||||
types = OEB_DOCS
|
||||
|
@ -11,7 +11,7 @@ from qt.core import (
|
||||
|
||||
from calibre import prepare_string_for_xml
|
||||
from calibre.ebooks.html_transform_rules import (
|
||||
ACTION_MAP, MATCH_TYPE_MAP, export_rules, import_rules,
|
||||
ACTION_MAP, MATCH_TYPE_MAP, export_rules, import_rules, transform_html,
|
||||
validate_rule
|
||||
)
|
||||
from calibre.gui2 import choose_files, choose_save_file, elided_text, error_dialog
|
||||
@ -350,7 +350,8 @@ class Tester(Dialog): # {{{
|
||||
return self.html.toPlainText()
|
||||
|
||||
def do_test(self):
|
||||
pass # TODO: Implement this
|
||||
changed, html = transform_html('\n' + self.value + '\n', self.rules)
|
||||
self.result.load_text('<!-- %s -->\n\n%s' % (_('Resulting HTML'), html), 'html')
|
||||
|
||||
def sizeHint(self):
|
||||
return QSize(800, 600)
|
||||
|
Loading…
x
Reference in New Issue
Block a user