Use \seqsplit for DOIs to avoid awkward spacing
This commit is contained in:
parent
afc151913f
commit
55cf6d77d6
49
extension.py
49
extension.py
@ -14,9 +14,11 @@ def setup(app):
|
|||||||
app.add_role('subref', SubRefRole())
|
app.add_role('subref', SubRefRole())
|
||||||
app.add_role('msubref', MSubRefRole())
|
app.add_role('msubref', MSubRefRole())
|
||||||
|
|
||||||
#app.add_source_parser(PORSTParser, override=True)
|
app.add_source_parser(PORSTParser, override=True)
|
||||||
|
|
||||||
|
# ===================================================================
|
||||||
# HTML Builder
|
# HTML Builder
|
||||||
|
# ===================================================================
|
||||||
|
|
||||||
from sphinx.builders.html import StandaloneHTMLBuilder
|
from sphinx.builders.html import StandaloneHTMLBuilder
|
||||||
from sphinx.environment.adapters.toctree import TocTree
|
from sphinx.environment.adapters.toctree import TocTree
|
||||||
@ -85,7 +87,9 @@ def _TocTree_resolve(self, *args, **kwargs):
|
|||||||
return result
|
return result
|
||||||
TocTree.resolve = _TocTree_resolve
|
TocTree.resolve = _TocTree_resolve
|
||||||
|
|
||||||
|
# ===================================================================
|
||||||
# LaTeX Builder
|
# LaTeX Builder
|
||||||
|
# ===================================================================
|
||||||
|
|
||||||
from sphinx.builders.latex import LaTeXBuilder
|
from sphinx.builders.latex import LaTeXBuilder
|
||||||
from sphinx.writers.latex import LaTeXTranslator
|
from sphinx.writers.latex import LaTeXTranslator
|
||||||
@ -114,6 +118,8 @@ class POLaTeXTranslator(LaTeXTranslator):
|
|||||||
self.body.append(r'{{\small\bfseries\sffamily[{0}]}} '.format(self.paragraph_num))
|
self.body.append(r'{{\small\bfseries\sffamily[{0}]}} '.format(self.paragraph_num))
|
||||||
|
|
||||||
def visit_reference(self, node):
|
def visit_reference(self, node):
|
||||||
|
uri = node.get('refuri', '')
|
||||||
|
|
||||||
if 'po_mref' in node.attributes:
|
if 'po_mref' in node.attributes:
|
||||||
# Force page reference
|
# Force page reference
|
||||||
self.builder.config.latex_show_pagerefs = True
|
self.builder.config.latex_show_pagerefs = True
|
||||||
@ -121,11 +127,36 @@ class POLaTeXTranslator(LaTeXTranslator):
|
|||||||
self.builder.config.latex_show_pagerefs = False
|
self.builder.config.latex_show_pagerefs = False
|
||||||
else:
|
else:
|
||||||
super().visit_reference(node)
|
super().visit_reference(node)
|
||||||
|
|
||||||
|
if '://doi.org/' in uri:
|
||||||
|
# Fix formatting of DOI references
|
||||||
|
self.body.append('\\seqsplit{')
|
||||||
|
|
||||||
|
def depart_reference(self, node):
|
||||||
|
uri = node.get('refuri', '')
|
||||||
|
if '://doi.org/' in uri:
|
||||||
|
# Fix formatting of DOI references
|
||||||
|
self.body.append('}')
|
||||||
|
|
||||||
|
super().depart_reference(node)
|
||||||
|
|
||||||
class POLaTeXBuilder(LaTeXBuilder):
|
class POLaTeXBuilder(LaTeXBuilder):
|
||||||
default_translator_class = POLaTeXTranslator
|
default_translator_class = POLaTeXTranslator
|
||||||
|
|
||||||
|
# Don't escape "-"
|
||||||
|
|
||||||
|
import sphinx.util.texescape
|
||||||
|
sphinx.util.texescape.ascii_tex_replacements.remove(('-', r'\sphinxhyphen{}'))
|
||||||
|
|
||||||
|
__texescape_init = sphinx.util.texescape.init
|
||||||
|
def _texescape_init():
|
||||||
|
__texescape_init()
|
||||||
|
del sphinx.util.texescape._tex_escape_map_without_unicode[ord('-')]
|
||||||
|
sphinx.util.texescape.init = _texescape_init
|
||||||
|
|
||||||
|
# ===================================================================
|
||||||
# Epub3 Builder
|
# Epub3 Builder
|
||||||
|
# ===================================================================
|
||||||
|
|
||||||
from sphinx.builders.epub3 import Epub3Builder
|
from sphinx.builders.epub3 import Epub3Builder
|
||||||
|
|
||||||
@ -142,7 +173,9 @@ class POEpub3Builder(Epub3Builder):
|
|||||||
'text': 'Index'
|
'text': 'Index'
|
||||||
})
|
})
|
||||||
|
|
||||||
|
# ===================================================================
|
||||||
# Referencing roles
|
# Referencing roles
|
||||||
|
# ===================================================================
|
||||||
|
|
||||||
from sphinx.roles import XRefRole
|
from sphinx.roles import XRefRole
|
||||||
|
|
||||||
@ -248,14 +281,14 @@ def _StandardDomain_resolve_doc_xref(self, env, fromdocname, builder, typ, targe
|
|||||||
return result
|
return result
|
||||||
StandardDomain._resolve_doc_xref = _StandardDomain_resolve_doc_xref
|
StandardDomain._resolve_doc_xref = _StandardDomain_resolve_doc_xref
|
||||||
|
|
||||||
# RST Parser
|
# ===================================================================
|
||||||
|
# RST Parser (unused)
|
||||||
|
# ===================================================================
|
||||||
|
|
||||||
from sphinx.parsers import RSTParser
|
from sphinx.parsers import RSTParser
|
||||||
|
|
||||||
class PORSTParser(RSTParser):
|
class PORSTParser(RSTParser):
|
||||||
def parse(self, inputstring, document):
|
pass
|
||||||
super().parse(inputstring, document)
|
|
||||||
|
#def parse(self, inputstring, document):
|
||||||
# Verify footnotes
|
# super().parse(inputstring, document)
|
||||||
|
|
||||||
print(document)
|
|
||||||
|
Loading…
Reference in New Issue
Block a user