mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
DOCX Input: Add a semantic class to footnote links and targets
This commit is contained in:
parent
692022e3b3
commit
fad7c991c6
@ -141,6 +141,7 @@ class Convert(object):
|
||||
self.body.append(dl)
|
||||
for anchor, text, note in self.footnotes:
|
||||
dl.append(DT('[', A('←' + text, href='#back_%s' % anchor, title=text), id=anchor))
|
||||
dl[-1].set('class', 'calibre-docx-footnote-target')
|
||||
dl[-1][0].tail = ']'
|
||||
dl.append(DD())
|
||||
paras = []
|
||||
@ -352,11 +353,11 @@ class Convert(object):
|
||||
def write(self, doc):
|
||||
toc = create_toc(doc, self.body, self.resolved_link_map, self.styles, self.object_map, self.log, self.namespace)
|
||||
raw = html.tostring(self.html, encoding='utf-8', doctype='<!DOCTYPE html>')
|
||||
with open(os.path.join(self.dest_dir, 'index.html'), 'wb') as f:
|
||||
with lopen(os.path.join(self.dest_dir, 'index.html'), 'wb') as f:
|
||||
f.write(raw)
|
||||
css = self.styles.generate_css(self.dest_dir, self.docx, self.notes_nopb, self.nosupsub)
|
||||
if css:
|
||||
with open(os.path.join(self.dest_dir, 'docx.css'), 'wb') as f:
|
||||
with lopen(os.path.join(self.dest_dir, 'docx.css'), 'wb') as f:
|
||||
f.write(css.encode('utf-8'))
|
||||
|
||||
opf = OPFCreator(self.dest_dir, self.mi)
|
||||
@ -374,7 +375,7 @@ class Convert(object):
|
||||
guide.append(E.reference(
|
||||
href='index.html#' + self.toc_anchor, title=_('Table of Contents'), type='toc'))
|
||||
toc_file = os.path.join(self.dest_dir, 'toc.ncx')
|
||||
with open(os.path.join(self.dest_dir, 'metadata.opf'), 'wb') as of, open(toc_file, 'wb') as ncx:
|
||||
with lopen(os.path.join(self.dest_dir, 'metadata.opf'), 'wb') as of, open(toc_file, 'wb') as ncx:
|
||||
opf.render(of, ncx, 'toc.ncx', process_guide=process_guide)
|
||||
if os.path.getsize(toc_file) == 0:
|
||||
os.remove(toc_file)
|
||||
@ -656,7 +657,7 @@ class Convert(object):
|
||||
anchor, name = self.footnotes.get_ref(child)
|
||||
if anchor and name:
|
||||
l = A(SUP(name, id='back_%s' % anchor), href='#' + anchor, title=name)
|
||||
l.set('class', 'noteref')
|
||||
l.set('class', 'noteref calibre-docx-footnote-link')
|
||||
text.add_elem(l)
|
||||
ans.append(text.elem)
|
||||
elif self.namespace.is_tag(child, 'w:tab'):
|
||||
@ -764,6 +765,7 @@ class Convert(object):
|
||||
if len(run) > 1:
|
||||
process_run(run)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
import shutil
|
||||
from calibre.utils.logging import default_log
|
||||
@ -773,4 +775,3 @@ if __name__ == '__main__':
|
||||
shutil.rmtree(dest_dir)
|
||||
os.mkdir(dest_dir)
|
||||
Convert(sys.argv[-1], dest_dir=dest_dir, log=default_log)()
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user