diff --git a/src/calibre/srv/render_book.py b/src/calibre/srv/render_book.py index 0a8dfb3f4f..e10afbbdb5 100644 --- a/src/calibre/srv/render_book.py +++ b/src/calibre/srv/render_book.py @@ -8,7 +8,7 @@ import json import os import re import sys -from collections import OrderedDict, defaultdict +from collections import defaultdict from datetime import datetime from functools import partial from itertools import count @@ -142,37 +142,11 @@ def transform_declaration(decl): return changed -def replace_epub_type_selector(m): - which = m.group(2) - roleval = EPUB_TYPE_MAP.get(which) - if roleval is None: - return m.group() - return 'role{}"{}"'.format(m.group(1), roleval) - - -def epub_type_pat(): - ans = getattr(epub_type_pat, 'ans', None) - if ans is None: - ans = epub_type_pat.ans = re.compile(r'epub\|type([$*~]?=)"(\S+)"') - return ans - - -def transform_selector(rule): - selector = rule.selectorText - if 'epub|type' in selector: - ns, num = epub_type_pat().subn(replace_epub_type_selector, selector) - if num > 0 and ns != selector: - rule.selectorText = ns - return True - - def transform_sheet(sheet): changed = False for rule in sheet.cssRules.rulesOfType(CSSRule.STYLE_RULE): if transform_declaration(rule.style): changed = True - if transform_selector(rule): - changed = True return changed @@ -543,41 +517,6 @@ def split_name(name): boolean_attributes = frozenset('allowfullscreen,async,autofocus,autoplay,checked,compact,controls,declare,default,defaultchecked,defaultmuted,defaultselected,defer,disabled,enabled,formnovalidate,hidden,indeterminate,inert,ismap,itemscope,loop,multiple,muted,nohref,noresize,noshade,novalidate,nowrap,open,pauseonexit,readonly,required,reversed,scoped,seamless,selected,sortable,truespeed,typemustmatch,visible'.split(',')) # noqa -# see https://idpf.github.io/epub-guides/epub-aria-authoring/ -EPUB_TYPE_MAP = {k:'doc-' + k for k in ( - 'abstract acknowledgements afterword appendix biblioentry bibliography biblioref chapter colophon conclusion cover credit' - ' credits dedication epigraph epilogue errata footnote footnotes forward glossary glossref index introduction link noteref notice' - ' pagebreak pagelist part preface prologue pullquote qna locator subtitle title toc').split(' ')} -for k in 'figure term definition directory list list-item table row cell'.split(' '): - EPUB_TYPE_MAP[k] = k - -EPUB_TYPE_MAP['help'] = 'doc-tip' -EPUB_TYPE_MAP['page-list'] = 'doc-pagelist' - - -def map_epub_type(epub_type, attribs, elem): - val = EPUB_TYPE_MAP.get(epub_type.lower()) - if val: - role = None - in_attribs = None - for i, x in enumerate(attribs): - if x[0] == 'role': - role = x[1] - in_attribs = i - break - else: - role = elem.get('role') - roles = OrderedDict([(k, True) for k in role.split()]) if role else OrderedDict() - if val not in roles: - roles[val] = True - role = ' '.join(roles) - if in_attribs is None: - attribs.append(['role', role]) - else: - attribs[in_attribs] = ['role', role] - return True - return False - known_tags = ('img', 'script', 'link', 'image', 'style') discarded_tags = ('meta', 'base') @@ -611,9 +550,6 @@ def serialize_elem(elem, nsmap): if val and val.lower() in (al, ''): attribs.append([al, al]) continue - if attr_ns == EPUB_NS and al == 'type': - map_epub_type(val, attribs, elem) - continue attrib = [aname, val] if attr_ns: attr_ns = nsmap[attr_ns] diff --git a/src/pyj/read_book/resources.pyj b/src/pyj/read_book/resources.pyj index 7c219f0ec6..814ae4039d 100644 --- a/src/pyj/read_book/resources.pyj +++ b/src/pyj/read_book/resources.pyj @@ -164,7 +164,7 @@ def finalize_resources(book, root_name, resource_data): js_types = {k: True for k in 'text/javascript text/ecmascript application/javascript application/ecmascript'.split(' ')} resource_tag_names = {'script':'src', 'link':'href', 'img':'src', 'image':'xlink:href'} -ns_rmap = {'http://www.w3.org/2000/svg':'svg', 'http://www.w3.org/1999/xlink':'xlink', 'http://www.w3.org/1998/Math/MathML':'math', 'http://www.w3.org/XML/1998/namespace': 'xml'} +ns_rmap = {'http://www.w3.org/2000/svg':'svg', 'http://www.w3.org/1999/xlink':'xlink', 'http://www.w3.org/1998/Math/MathML':'math', 'http://www.w3.org/XML/1998/namespace': 'xml', 'http://www.idpf.org/2007/ops': 'epub'} ns_count = 0 hide_tooltips = False