From 885b997a258c88a248f2f2a8514f717274103127 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Mon, 7 Dec 2015 11:02:45 +0900 Subject: [PATCH 1/6] Add testcases for latex_show_urls --- .../conf.py | 0 .../index.rst | 14 ++++-- .../rimg.png | Bin tests/test_build_latex.py | 45 +++++++++++++++++- 4 files changed, 55 insertions(+), 4 deletions(-) rename tests/roots/{test-references-in-caption => test-footnotes}/conf.py (100%) rename tests/roots/{test-references-in-caption => test-footnotes}/index.rst (68%) rename tests/roots/{test-references-in-caption => test-footnotes}/rimg.png (100%) diff --git a/tests/roots/test-references-in-caption/conf.py b/tests/roots/test-footnotes/conf.py similarity index 100% rename from tests/roots/test-references-in-caption/conf.py rename to tests/roots/test-footnotes/conf.py diff --git a/tests/roots/test-references-in-caption/index.rst b/tests/roots/test-footnotes/index.rst similarity index 68% rename from tests/roots/test-references-in-caption/index.rst rename to tests/roots/test-footnotes/index.rst index decec1bad..59211ad78 100644 --- a/tests/roots/test-references-in-caption/index.rst +++ b/tests/roots/test-footnotes/index.rst @@ -1,6 +1,6 @@ -============== -test-reference -============== +=============== +test-footenotes +=============== The section with a reference to [AuthorYear]_ ============================================= @@ -19,4 +19,12 @@ The section with a reference to [AuthorYear]_ .. rubric:: The rubric title with a reference to [AuthorYear]_ +* First footnote: [#]_ +* Second footnote: [1]_ +* `Sphinx `_ +* Third footnote: [#]_ + .. [AuthorYear] Author, Title, Year +.. [#] First +.. [1] Second +.. [#] Third diff --git a/tests/roots/test-references-in-caption/rimg.png b/tests/roots/test-footnotes/rimg.png similarity index 100% rename from tests/roots/test-references-in-caption/rimg.png rename to tests/roots/test-footnotes/rimg.png diff --git a/tests/test_build_latex.py b/tests/test_build_latex.py index 00d3b82c1..7627e83b7 100644 --- a/tests/test_build_latex.py +++ b/tests/test_build_latex.py @@ -323,7 +323,7 @@ def test_footnote(app, status, warning): assert r'\footnote{sphinx-dev@googlegroups.com}' not in result -@with_app(buildername='latex', testroot='references-in-caption') +@with_app(buildername='latex', testroot='footnotes') def test_reference_in_caption(app, status, warning): app.builder.build_all() result = (app.outdir / 'Python.tex').text(encoding='utf8') @@ -335,3 +335,46 @@ def test_reference_in_caption(app, status, warning): assert '\\chapter{The section with a reference to {[}AuthorYear{]}}' in result assert '\\caption{The table title with a reference to {[}AuthorYear{]}}' in result assert '\\paragraph{The rubric title with a reference to {[}AuthorYear{]}}' in result + + +@with_app(buildername='latex', testroot='footnotes', + confoverrides={'latex_show_urls': 'inline'}) +def test_latex_show_urls_is_inline(app, status, warning): + app.builder.build_all() + result = (app.outdir / 'Python.tex').text(encoding='utf8') + print(result) + print(status.getvalue()) + print(warning.getvalue()) + assert 'First footnote: \\footnote[2]{\nFirst\n}' in result + assert 'Second footnote: \\footnote[1]{\nSecond\n}' in result + assert '\\href{http://sphinx-doc.org/}{Sphinx} (http://sphinx-doc.org/)' in result + assert 'Third footnote: \\footnote[3]{\nThird\n}' in result + + +@with_app(buildername='latex', testroot='footnotes', + confoverrides={'latex_show_urls': 'footnote'}) +def test_latex_show_urls_is_footnote(app, status, warning): + app.builder.build_all() + result = (app.outdir / 'Python.tex').text(encoding='utf8') + print(result) + print(status.getvalue()) + print(warning.getvalue()) + assert 'First footnote: \\footnote[2]{\nFirst\n}' in result + assert 'Second footnote: \\footnote[1]{\nSecond\n}' in result + assert ('\\href{http://sphinx-doc.org/}{Sphinx}' + '\\footnote{http://sphinx-doc.org/}' in result) + assert 'Third footnote: \\footnote[3]{\nThird\n}' in result + + +@with_app(buildername='latex', testroot='footnotes', + confoverrides={'latex_show_urls': 'no'}) +def test_latex_show_urls_is_no(app, status, warning): + app.builder.build_all() + result = (app.outdir / 'Python.tex').text(encoding='utf8') + print(result) + print(status.getvalue()) + print(warning.getvalue()) + assert 'First footnote: \\footnote[2]{\nFirst\n}' in result + assert 'Second footnote: \\footnote[1]{\nSecond\n}' in result + assert '\\href{http://sphinx-doc.org/}{Sphinx}' in result + assert 'Third footnote: \\footnote[3]{\nThird\n}' in result From 9fec96d32742bf753cad0a9b1f9ddff9e24f2a06 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Tue, 8 Dec 2015 00:37:20 +0900 Subject: [PATCH 2/6] Refactor latex_show_urls processor to Transform class --- sphinx/writers/latex.py | 106 +++++++++++++++++++++++---- tests/roots/test-footnotes/index.rst | 4 +- tests/test_build_latex.py | 9 ++- 3 files changed, 100 insertions(+), 19 deletions(-) diff --git a/sphinx/writers/latex.py b/sphinx/writers/latex.py index c1667666d..34fe90dc2 100644 --- a/sphinx/writers/latex.py +++ b/sphinx/writers/latex.py @@ -18,6 +18,7 @@ from os import path from six import itervalues, text_type from docutils import nodes, writers +from docutils.transforms import Transform from docutils.writers.latex2e import Babel from sphinx import addnodes @@ -69,6 +70,8 @@ FOOTER = r''' \end{document} ''' +URI_SCHEMES = ('mailto:', 'http:', 'https:', 'ftp:') + class collected_footnote(nodes.footnote): """Footnotes that are collected are assigned this class.""" @@ -98,6 +101,8 @@ class LaTeXWriter(writers.Writer): self.builder.translator_class or LaTeXTranslator) def translate(self): + transform = ShowUrlsTransform(self.document) + transform.apply() visitor = self.translator_class(self.document, self.builder) self.document.walkabout(visitor) self.output = visitor.astext() @@ -126,6 +131,89 @@ if hasattr(Babel, '_ISO639_TO_BABEL'): Babel._ISO639_TO_BABEL['sl'] = 'slovene' +class ShowUrlsTransform(Transform): + expanded = False + + def apply(self): + self.expand_show_urls() + if self.expanded: + self.renumber_footnotes() + + def expand_show_urls(self): + show_urls = self.document.settings.env.config.latex_show_urls + if show_urls is False or show_urls == 'no': + return + + for node in self.document.traverse(nodes.reference): + uri = node.get('refuri', '') + if uri.startswith(URI_SCHEMES): + if uri.startswith('mailto:'): + uri = uri[7:] + if node.astext() != uri: + index = node.parent.index(node) + if show_urls == 'footnote': + footnote_nodes = self.create_footnote(uri) + for i, fn in enumerate(footnote_nodes): + node.parent.insert(index + i + 1, fn) + + self.expanded = True + else: # all other true values (b/w compat) + textnode = nodes.Text(" (%s)" % uri) + node.parent.insert(index + 1, textnode) + + def create_footnote(self, uri): + label = nodes.label('', '#') + para = nodes.paragraph() + para.append(nodes.Text(uri)) + footnote = nodes.footnote(uri, label, para, auto=1) + footnote['names'].append('#') + self.document.note_autofootnote(footnote) + + label = nodes.Text('#') + footnote_ref = nodes.footnote_reference('[#]_', label, auto=1, + refid=footnote['ids'][0]) + self.document.note_autofootnote_ref(footnote_ref) + footnote.add_backref(footnote_ref['ids'][0]) + + return [footnote, footnote_ref] + + def renumber_footnotes(self): + def is_used_number(number): + for node in self.document.traverse(nodes.footnote): + if not node.get('auto') and number in node['names']: + return True + + return False + + def is_auto_footnote(node): + return isinstance(node, nodes.footnote) and node.get('auto') + + def footnote_ref_by(ids): + def is_footnote_ref(node): + return isinstance(node, nodes.footnote_reference) and ids[0] == node['refid'] + + return is_footnote_ref + + startnum = 1 + for footnote in self.document.traverse(is_auto_footnote): + while True: + label = str(startnum) + startnum += 1 + if not is_used_number(label): + break + + old_label = footnote[0].astext() + footnote.remove(footnote[0]) + footnote.insert(0, nodes.label('', label)) + if old_label in footnote['names']: + footnote['names'].remove(old_label) + footnote['names'].append(label) + + for footnote_ref in self.document.traverse(footnote_ref_by(footnote['ids'])): + footnote_ref.remove(footnote_ref[0]) + footnote_ref += nodes.Text(label) + + class Table(object): def __init__(self): self.col = 0 @@ -1399,23 +1487,9 @@ class LaTeXTranslator(nodes.NodeVisitor): uri = '%' + self.curfilestack[-1] + '#' + node['refid'] if self.in_title or not uri: self.context.append('') - elif uri.startswith('mailto:') or uri.startswith('http:') or \ - uri.startswith('https:') or uri.startswith('ftp:'): + elif uri.startswith(URI_SCHEMES): self.body.append('\\href{%s}{' % self.encode_uri(uri)) - # if configured, put the URL after the link - show_urls = self.builder.config.latex_show_urls - if uri.startswith('mailto:'): - uri = uri[7:] - if node.astext() != uri and show_urls and show_urls != 'no': - if show_urls == 'footnote' and not \ - (self.in_footnote or self.in_caption): - # obviously, footnotes in footnotes are not going to work - self.context.append( - r'}\footnote{%s}' % self.encode_uri(uri)) - else: # all other true values (b/w compat) - self.context.append('} (%s)' % self.encode_uri(uri)) - else: - self.context.append('}') + self.context.append('}') elif uri.startswith('#'): # references to labels in the same document id = self.curfilestack[-1] + ':' + uri[1:] diff --git a/tests/roots/test-footnotes/index.rst b/tests/roots/test-footnotes/index.rst index 59211ad78..ceace70c2 100644 --- a/tests/roots/test-footnotes/index.rst +++ b/tests/roots/test-footnotes/index.rst @@ -19,12 +19,14 @@ The section with a reference to [AuthorYear]_ .. rubric:: The rubric title with a reference to [AuthorYear]_ +.. [#] First + * First footnote: [#]_ * Second footnote: [1]_ * `Sphinx `_ * Third footnote: [#]_ +* `URL including tilde `_ .. [AuthorYear] Author, Title, Year -.. [#] First .. [1] Second .. [#] Third diff --git a/tests/test_build_latex.py b/tests/test_build_latex.py index 7627e83b7..5a060efe5 100644 --- a/tests/test_build_latex.py +++ b/tests/test_build_latex.py @@ -349,6 +349,8 @@ def test_latex_show_urls_is_inline(app, status, warning): assert 'Second footnote: \\footnote[1]{\nSecond\n}' in result assert '\\href{http://sphinx-doc.org/}{Sphinx} (http://sphinx-doc.org/)' in result assert 'Third footnote: \\footnote[3]{\nThird\n}' in result + assert ('\\href{http://sphinx-doc.org/~test/}{URL including tilde} ' + '(http://sphinx-doc.org/\\textasciitilde{}test/)' in result) @with_app(buildername='latex', testroot='footnotes', @@ -362,8 +364,10 @@ def test_latex_show_urls_is_footnote(app, status, warning): assert 'First footnote: \\footnote[2]{\nFirst\n}' in result assert 'Second footnote: \\footnote[1]{\nSecond\n}' in result assert ('\\href{http://sphinx-doc.org/}{Sphinx}' - '\\footnote{http://sphinx-doc.org/}' in result) - assert 'Third footnote: \\footnote[3]{\nThird\n}' in result + '\\footnote[3]{\nhttp://sphinx-doc.org/\n}' in result) + assert 'Third footnote: \\footnote[5]{\nThird\n}' in result + assert ('\\href{http://sphinx-doc.org/~test/}{URL including tilde}' + '\\footnote[4]{\nhttp://sphinx-doc.org/\\textasciitilde{}test/\n}' in result) @with_app(buildername='latex', testroot='footnotes', @@ -378,3 +382,4 @@ def test_latex_show_urls_is_no(app, status, warning): assert 'Second footnote: \\footnote[1]{\nSecond\n}' in result assert '\\href{http://sphinx-doc.org/}{Sphinx}' in result assert 'Third footnote: \\footnote[3]{\nThird\n}' in result + assert '\\href{http://sphinx-doc.org/~test/}{URL including tilde}' in result From 5fc4536040ac4993558d28a37456edeb4659bba7 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Tue, 8 Dec 2015 12:10:20 +0900 Subject: [PATCH 3/6] Fix invalid node id was assigned Because document.ids is reset on pickling doctree... --- sphinx/writers/latex.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/sphinx/writers/latex.py b/sphinx/writers/latex.py index 34fe90dc2..7b1094b31 100644 --- a/sphinx/writers/latex.py +++ b/sphinx/writers/latex.py @@ -135,10 +135,17 @@ class ShowUrlsTransform(Transform): expanded = False def apply(self): + # replace id_prefix temporarily + id_prefix = self.document.settings.id_prefix + self.document.settings.id_prefix = 'show_urls' + self.expand_show_urls() if self.expanded: self.renumber_footnotes() + # restore id_prefix + self.document.settings.id_prefix = id_prefix + def expand_show_urls(self): show_urls = self.document.settings.env.config.latex_show_urls if show_urls is False or show_urls == 'no': From 5983d027876c0e8992f71d8478294cacbbd8849c Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Tue, 8 Dec 2015 12:16:15 +0900 Subject: [PATCH 4/6] Fix #1237 footnotes not working in definition list in LaTeX --- CHANGES | 1 + sphinx/writers/latex.py | 19 ++++++++++++++++--- tests/roots/test-footnotes/index.rst | 11 +++++++++++ tests/test_build_latex.py | 18 ++++++++++++++++++ 4 files changed, 46 insertions(+), 3 deletions(-) diff --git a/CHANGES b/CHANGES index 5feea324b..996337a23 100644 --- a/CHANGES +++ b/CHANGES @@ -10,6 +10,7 @@ Bugs fixed * #1833: Fix email addresses is showed again if latex_show_urls is not None * #2176: sphinx.ext.graphviz: use instead of to embed svg * #967: Fix SVG inheritance diagram is not hyperlinked (clickable) +* #1237: Fix footnotes not working in definition list in LaTeX Release 1.3.3 (released Dec 2, 2015) diff --git a/sphinx/writers/latex.py b/sphinx/writers/latex.py index 7b1094b31..388fe81e1 100644 --- a/sphinx/writers/latex.py +++ b/sphinx/writers/latex.py @@ -373,6 +373,7 @@ class LaTeXTranslator(nodes.NodeVisitor): sys.maxsize]] self.bodystack = [] self.footnotestack = [] + self.termfootnotestack = [] self.curfilestack = [] self.handled_abbrs = set() if document.settings.docclass == 'howto': @@ -392,6 +393,7 @@ class LaTeXTranslator(nodes.NodeVisitor): self.in_footnote = 0 self.in_caption = 0 self.in_container_literal_block = 0 + self.in_term = 0 self.first_document = 1 self.this_is_the_title = 1 self.literal_whitespace = 0 @@ -856,7 +858,7 @@ class LaTeXTranslator(nodes.NodeVisitor): def visit_collected_footnote(self, node): self.in_footnote += 1 - if 'in_table' in node: + if 'footnotetext' in node: self.body.append('\\footnotetext[%s]{' % node['number']) else: self.body.append('\\footnote[%s]{' % node['number']) @@ -959,7 +961,7 @@ class LaTeXTranslator(nodes.NodeVisitor): self.body.append('\\end{threeparttable}\n\n') if self.table.footnotes: for footnode in self.table.footnotes: - footnode['in_table'] = True + footnode['footnotetext'] = True footnode.walkabout(self) self.table = None self.tablebody = None @@ -1126,14 +1128,22 @@ class LaTeXTranslator(nodes.NodeVisitor): pass def visit_term(self, node): + self.in_term += 1 ctx = '}] \\leavevmode' if node.get('ids'): ctx += self.hypertarget(node['ids'][0]) self.body.append('\\item[{') + self.termfootnotestack.append([]) self.context.append(ctx) def depart_term(self, node): self.body.append(self.context.pop()) + footnotes = self.termfootnotestack.pop() + for footnode in footnotes: + footnode['footnotetext'] = True + footnode.walkabout(self) + + self.in_term -= 1 def visit_termsep(self, node): self.body.append(', ') @@ -1647,7 +1657,7 @@ class LaTeXTranslator(nodes.NodeVisitor): # if a footnote has been inserted once, it shouldn't be repeated # by the next reference if used: - if self.table: + if self.table or self.in_term: self.body.append('\\protect\\footnotemark[%s]' % num) else: self.body.append('\\footnotemark[%s]' % num) @@ -1655,6 +1665,9 @@ class LaTeXTranslator(nodes.NodeVisitor): self.footnotestack[-1][num][1] = True self.body.append('\\protect\\footnotemark[%s]' % num) self.table.footnotes.append(footnode) + elif self.in_term: + self.body.append('\\footnotemark[%s]' % num) + self.termfootnotestack[-1].append(footnode) else: if self.in_caption: raise UnsupportedError('%s:%s: footnotes in float captions ' diff --git a/tests/roots/test-footnotes/index.rst b/tests/roots/test-footnotes/index.rst index ceace70c2..5c3bf6f36 100644 --- a/tests/roots/test-footnotes/index.rst +++ b/tests/roots/test-footnotes/index.rst @@ -30,3 +30,14 @@ The section with a reference to [AuthorYear]_ .. [AuthorYear] Author, Title, Year .. [1] Second .. [#] Third + +`URL in term `_ + Description Description Description ... + +Footnote in term [#]_ + Description Description Description ... + + `Term in deflist `_ + Description2 + +.. [#] Footnote in term diff --git a/tests/test_build_latex.py b/tests/test_build_latex.py index 5a060efe5..844c524fa 100644 --- a/tests/test_build_latex.py +++ b/tests/test_build_latex.py @@ -351,6 +351,12 @@ def test_latex_show_urls_is_inline(app, status, warning): assert 'Third footnote: \\footnote[3]{\nThird\n}' in result assert ('\\href{http://sphinx-doc.org/~test/}{URL including tilde} ' '(http://sphinx-doc.org/\\textasciitilde{}test/)' in result) + assert ('\\item[{\\href{http://sphinx-doc.org/}{URL in term} (http://sphinx-doc.org/)}] ' + '\\leavevmode\nDescription' in result) + assert ('\\item[{Footnote in term \\footnotemark[4]}] ' + '\\leavevmode\\footnotetext[4]{\nFootnote in term\n}\nDescription' in result) + assert ('\\item[{\\href{http://sphinx-doc.org/}{Term in deflist} (http://sphinx-doc.org/)}] ' + '\\leavevmode\nDescription' in result) @with_app(buildername='latex', testroot='footnotes', @@ -368,6 +374,12 @@ def test_latex_show_urls_is_footnote(app, status, warning): assert 'Third footnote: \\footnote[5]{\nThird\n}' in result assert ('\\href{http://sphinx-doc.org/~test/}{URL including tilde}' '\\footnote[4]{\nhttp://sphinx-doc.org/\\textasciitilde{}test/\n}' in result) + assert ('\\item[{\\href{http://sphinx-doc.org/}{URL in term}\\footnotemark[6]}] ' + '\\leavevmode\\footnotetext[6]{\nhttp://sphinx-doc.org/\n}\nDescription' in result) + assert ('\\item[{Footnote in term \\footnotemark[8]}] ' + '\\leavevmode\\footnotetext[8]{\nFootnote in term\n}\nDescription' in result) + assert ('\\item[{\\href{http://sphinx-doc.org/}{Term in deflist}\\footnotemark[7]}] ' + '\\leavevmode\\footnotetext[7]{\nhttp://sphinx-doc.org/\n}\nDescription' in result) @with_app(buildername='latex', testroot='footnotes', @@ -383,3 +395,9 @@ def test_latex_show_urls_is_no(app, status, warning): assert '\\href{http://sphinx-doc.org/}{Sphinx}' in result assert 'Third footnote: \\footnote[3]{\nThird\n}' in result assert '\\href{http://sphinx-doc.org/~test/}{URL including tilde}' in result + assert ('\\item[{\\href{http://sphinx-doc.org/}{URL in term}}] ' + '\\leavevmode\nDescription' in result) + assert ('\\item[{Footnote in term \\footnotemark[4]}] ' + '\\leavevmode\\footnotetext[4]{\nFootnote in term\n}\nDescription' in result) + assert ('\\item[{\\href{http://sphinx-doc.org/}{Term in deflist}}] ' + '\\leavevmode\nDescription' in result) From 9f96bbaf35dd5423eeb62ef4a5c8f32aad2e0186 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Sat, 19 Dec 2015 14:42:01 +0900 Subject: [PATCH 5/6] Move testcases for footnotes to roots/test-footnote --- tests/root/conf.py | 1 - tests/root/footnote.txt | 12 ------------ tests/roots/test-footnotes/index.rst | 2 ++ tests/test_build_latex.py | 19 ++++++++++++++----- 4 files changed, 16 insertions(+), 18 deletions(-) diff --git a/tests/root/conf.py b/tests/root/conf.py index 6ce196c3d..bdf2f8c8d 100644 --- a/tests/root/conf.py +++ b/tests/root/conf.py @@ -51,7 +51,6 @@ latex_documents = [ 'Georg Brandl \\and someone else', 'manual'), ] -latex_show_urls = 'footnote' latex_additional_files = ['svgimg.svg'] texinfo_documents = [ diff --git a/tests/root/footnote.txt b/tests/root/footnote.txt index c30a5fe9c..36ad3fadc 100644 --- a/tests/root/footnote.txt +++ b/tests/root/footnote.txt @@ -35,18 +35,6 @@ footnotes in table * - VIDIOC_CROPCAP - Information about VIDIOC_CROPCAP -URLs as footnotes ------------------ - -`homepage `_ - -URLs should not be footnotes ----------------------------- - -GitHub Page: `https://github.com/sphinx-doc/sphinx `_ - -Mailing list: `sphinx-dev@googlegroups.com `_ - footenotes -------------------- diff --git a/tests/roots/test-footnotes/index.rst b/tests/roots/test-footnotes/index.rst index 5c3bf6f36..c7fe38ff9 100644 --- a/tests/roots/test-footnotes/index.rst +++ b/tests/roots/test-footnotes/index.rst @@ -26,6 +26,8 @@ The section with a reference to [AuthorYear]_ * `Sphinx `_ * Third footnote: [#]_ * `URL including tilde `_ +* GitHub Page: `https://github.com/sphinx-doc/sphinx `_ +* Mailing list: `sphinx-dev@googlegroups.com `_ .. [AuthorYear] Author, Title, Year .. [1] Second diff --git a/tests/test_build_latex.py b/tests/test_build_latex.py index 844c524fa..d4f9f8451 100644 --- a/tests/test_build_latex.py +++ b/tests/test_build_latex.py @@ -318,9 +318,6 @@ def test_footnote(app, status, warning): assert ('\\end{threeparttable}\n\n' '\\footnotetext[4]{\nfootnotes in table caption\n}' '\\footnotetext[5]{\nfootnotes in table\n}' in result) - assert r'\href{http://sphinx.org}{homepage}\footnote{http://sphinx.org}' in result - assert r'\footnote{https://github.com/sphinx-doc/sphinx}' not in result - assert r'\footnote{sphinx-dev@googlegroups.com}' not in result @with_app(buildername='latex', testroot='footnotes') @@ -355,8 +352,12 @@ def test_latex_show_urls_is_inline(app, status, warning): '\\leavevmode\nDescription' in result) assert ('\\item[{Footnote in term \\footnotemark[4]}] ' '\\leavevmode\\footnotetext[4]{\nFootnote in term\n}\nDescription' in result) - assert ('\\item[{\\href{http://sphinx-doc.org/}{Term in deflist} (http://sphinx-doc.org/)}] ' - '\\leavevmode\nDescription' in result) + assert ('\\item[{\\href{http://sphinx-doc.org/}{Term in deflist} ' + '(http://sphinx-doc.org/)}] \\leavevmode\nDescription' in result) + assert ('\\href{https://github.com/sphinx-doc/sphinx}' + '{https://github.com/sphinx-doc/sphinx}\n' in result) + assert ('\\href{mailto:sphinx-dev@googlegroups.com}' + '{sphinx-dev@googlegroups.com}' in result) @with_app(buildername='latex', testroot='footnotes', @@ -380,6 +381,10 @@ def test_latex_show_urls_is_footnote(app, status, warning): '\\leavevmode\\footnotetext[8]{\nFootnote in term\n}\nDescription' in result) assert ('\\item[{\\href{http://sphinx-doc.org/}{Term in deflist}\\footnotemark[7]}] ' '\\leavevmode\\footnotetext[7]{\nhttp://sphinx-doc.org/\n}\nDescription' in result) + assert ('\\href{https://github.com/sphinx-doc/sphinx}' + '{https://github.com/sphinx-doc/sphinx}\n' in result) + assert ('\\href{mailto:sphinx-dev@googlegroups.com}' + '{sphinx-dev@googlegroups.com}\n' in result) @with_app(buildername='latex', testroot='footnotes', @@ -401,3 +406,7 @@ def test_latex_show_urls_is_no(app, status, warning): '\\leavevmode\\footnotetext[4]{\nFootnote in term\n}\nDescription' in result) assert ('\\item[{\\href{http://sphinx-doc.org/}{Term in deflist}}] ' '\\leavevmode\nDescription' in result) + assert ('\\href{https://github.com/sphinx-doc/sphinx}' + '{https://github.com/sphinx-doc/sphinx}\n' in result) + assert ('\\href{mailto:sphinx-dev@googlegroups.com}' + '{sphinx-dev@googlegroups.com}\n' in result) From a21bfb1061150f95a40cf091aeca12436b2e46bb Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Sat, 19 Dec 2015 16:53:15 +0900 Subject: [PATCH 6/6] Make ShowUrlsTransform plain class --- sphinx/writers/latex.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/sphinx/writers/latex.py b/sphinx/writers/latex.py index 388fe81e1..af1c6af7a 100644 --- a/sphinx/writers/latex.py +++ b/sphinx/writers/latex.py @@ -18,7 +18,6 @@ from os import path from six import itervalues, text_type from docutils import nodes, writers -from docutils.transforms import Transform from docutils.writers.latex2e import Babel from sphinx import addnodes @@ -131,9 +130,12 @@ if hasattr(Babel, '_ISO639_TO_BABEL'): Babel._ISO639_TO_BABEL['sl'] = 'slovene' -class ShowUrlsTransform(Transform): +class ShowUrlsTransform(object): expanded = False + def __init__(self, document): + self.document = document + def apply(self): # replace id_prefix temporarily id_prefix = self.document.settings.id_prefix