DOCX Input: Add role="doc-noteref" for links to footnotes/endnotes

This commit is contained in:
Kovid Goyal 2024-03-30 12:34:08 +05:30
parent cc1b698cde
commit 6fb49c9a22
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 21 additions and 16 deletions

View File

@ -5,7 +5,6 @@ __license__ = 'GPL v3'
__copyright__ = '2013, Kovid Goyal <kovid at kovidgoyal.net>' __copyright__ = '2013, Kovid Goyal <kovid at kovidgoyal.net>'
from collections import OrderedDict from collections import OrderedDict
from polyglot.builtins import iteritems
class Note: class Note:
@ -55,7 +54,7 @@ class Footnotes:
return None, None return None, None
def __iter__(self): def __iter__(self):
for anchor, (counter, note) in iteritems(self.notes): for anchor, (counter, note) in self.notes.items():
yield anchor, counter, note yield anchor, counter, note
@property @property

View File

@ -4,32 +4,36 @@
__license__ = 'GPL v3' __license__ = 'GPL v3'
__copyright__ = '2013, Kovid Goyal <kovid at kovidgoyal.net>' __copyright__ = '2013, Kovid Goyal <kovid at kovidgoyal.net>'
import sys, os, re, math, errno, uuid, numbers import errno
import math
import numbers
import os
import re
import sys
import uuid
from collections import OrderedDict, defaultdict from collections import OrderedDict, defaultdict
from lxml import html from lxml import html
from lxml.html.builder import ( from lxml.html.builder import BODY, BR, DD, DIV, DL, DT, H1, HEAD, HTML, LINK, META, SPAN, TITLE, A, P
HTML, HEAD, TITLE, BODY, LINK, META, P, SPAN, BR, DIV, A, DT, DL, DD, H1)
from calibre import guess_type from calibre import guess_type
from calibre.ebooks.docx.container import DOCX, fromstring
from calibre.ebooks.docx.names import XML, generate_anchor
from calibre.ebooks.docx.styles import Styles, inherit, PageProperties
from calibre.ebooks.docx.numbering import Numbering
from calibre.ebooks.docx.fonts import Fonts, is_symbol_font, map_symbol_text
from calibre.ebooks.docx.images import Images
from calibre.ebooks.docx.tables import Tables
from calibre.ebooks.docx.footnotes import Footnotes
from calibre.ebooks.docx.cleanup import cleanup_markup from calibre.ebooks.docx.cleanup import cleanup_markup
from calibre.ebooks.docx.container import DOCX, fromstring
from calibre.ebooks.docx.fields import Fields
from calibre.ebooks.docx.fonts import Fonts, is_symbol_font, map_symbol_text
from calibre.ebooks.docx.footnotes import Footnotes
from calibre.ebooks.docx.images import Images
from calibre.ebooks.docx.names import XML, generate_anchor
from calibre.ebooks.docx.numbering import Numbering
from calibre.ebooks.docx.settings import Settings
from calibre.ebooks.docx.styles import PageProperties, Styles, inherit
from calibre.ebooks.docx.tables import Tables
from calibre.ebooks.docx.theme import Theme from calibre.ebooks.docx.theme import Theme
from calibre.ebooks.docx.toc import create_toc from calibre.ebooks.docx.toc import create_toc
from calibre.ebooks.docx.fields import Fields
from calibre.ebooks.docx.settings import Settings
from calibre.ebooks.metadata.opf2 import OPFCreator from calibre.ebooks.metadata.opf2 import OPFCreator
from calibre.utils.localization import canonicalize_lang, lang_as_iso639_1 from calibre.utils.localization import canonicalize_lang, lang_as_iso639_1
from polyglot.builtins import iteritems, itervalues from polyglot.builtins import iteritems, itervalues
NBSP = '\xa0' NBSP = '\xa0'
@ -703,6 +707,7 @@ class Convert:
if anchor and name: if anchor and name:
l = A(name, id='back_%s' % anchor, href='#' + anchor, title=name) l = A(name, id='back_%s' % anchor, href='#' + anchor, title=name)
l.set('class', 'noteref') l.set('class', 'noteref')
l.set('role', 'doc-noteref')
text.add_elem(l) text.add_elem(l)
ans.append(text.elem) ans.append(text.elem)
elif self.namespace.is_tag(child, 'w:tab'): elif self.namespace.is_tag(child, 'w:tab'):
@ -847,6 +852,7 @@ class Convert:
if __name__ == '__main__': if __name__ == '__main__':
import shutil import shutil
from calibre.utils.logging import default_log from calibre.utils.logging import default_log
default_log.filter_level = default_log.DEBUG default_log.filter_level = default_log.DEBUG
dest_dir = os.path.join(os.getcwd(), 'docx_input') dest_dir = os.path.join(os.getcwd(), 'docx_input')