From 6123ea49e53b57e200138744dc618a797633d4d6 Mon Sep 17 00:00:00 2001 From: jfbu Date: Sun, 3 Apr 2016 15:14:13 +0200 Subject: [PATCH 01/19] Fix #2405: numref link in PDF jumps to the wrong location The hypertarget insertion by the LaTeX writer for literal blocks is moved from depart_container to visit_caption. modified: sphinx/writers/latex.py --- sphinx/writers/latex.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/sphinx/writers/latex.py b/sphinx/writers/latex.py index 6019d04ed..943f5a170 100644 --- a/sphinx/writers/latex.py +++ b/sphinx/writers/latex.py @@ -1444,8 +1444,9 @@ class LaTeXTranslator(nodes.NodeVisitor): self.in_caption += 1 if self.in_container_literal_block: self.body.append('\\needspace{\\literalblockneedspace}') - self.body.append('\\vspace{\\literalblockcaptiontopvspace}%') - self.body.append('\n\\SphinxSetupCaptionForVerbatim{literal-block}{') + self.body.append('\\vspace{\\literalblockcaptiontopvspace}\n') + self.body.append(self.context.pop()) + self.body.append('\\SphinxSetupCaptionForVerbatim{literal-block}{') elif self.in_minipage and isinstance(node.parent, nodes.figure): self.body.append('\\captionof{figure}{') else: @@ -1998,7 +1999,7 @@ class LaTeXTranslator(nodes.NodeVisitor): def depart_container(self, node): if node.get('literal_block'): self.in_container_literal_block -= 1 - self.body.append(self.context.pop()) + # self.body.append(self.context.pop()) moved to visit_caption def visit_decoration(self, node): pass From a1647b6bb9f89141a9ba5b3579cc1bce8d4b18c2 Mon Sep 17 00:00:00 2001 From: jfbu Date: Sun, 3 Apr 2016 16:21:28 +0200 Subject: [PATCH 02/19] Fix broken numeric reference in PDF hyperlinks to "Listing " code-blocks The `\label` is now inserted into the caption on top of the Verbatim, and `\ref` will work as expected. No need for `\phantomsection`. modified: sphinx/writers/latex.py modified: tests/test_directive_code.py --- sphinx/writers/latex.py | 11 ++++++----- tests/test_directive_code.py | 4 ++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/sphinx/writers/latex.py b/sphinx/writers/latex.py index 943f5a170..801726f4e 100644 --- a/sphinx/writers/latex.py +++ b/sphinx/writers/latex.py @@ -1445,8 +1445,8 @@ class LaTeXTranslator(nodes.NodeVisitor): if self.in_container_literal_block: self.body.append('\\needspace{\\literalblockneedspace}') self.body.append('\\vspace{\\literalblockcaptiontopvspace}\n') - self.body.append(self.context.pop()) - self.body.append('\\SphinxSetupCaptionForVerbatim{literal-block}{') + self.body.append('\\SphinxSetupCaptionForVerbatim{literal-block}{' + + self.context.pop()) elif self.in_minipage and isinstance(node.parent, nodes.figure): self.body.append('\\captionof{figure}{') else: @@ -1992,14 +1992,15 @@ class LaTeXTranslator(nodes.NodeVisitor): for id in self.pop_hyperlink_ids('code-block'): ids += self.hypertarget(id, anchor=False) if node['ids']: - ids += self.hypertarget(node['ids'][0]) + # suppress with anchor=False \phantomsection generation + ids += self.hypertarget(node['ids'][0], anchor=False) self.body.append('\n') - self.context.append(ids + '\n') + if ids: + self.context.append(ids) # will be used in visit_caption def depart_container(self, node): if node.get('literal_block'): self.in_container_literal_block -= 1 - # self.body.append(self.context.pop()) moved to visit_caption def visit_decoration(self, node): pass diff --git a/tests/test_directive_code.py b/tests/test_directive_code.py index 6f7b749b1..59a440b53 100644 --- a/tests/test_directive_code.py +++ b/tests/test_directive_code.py @@ -64,7 +64,7 @@ def test_code_block_caption_html(app, status, warning): def test_code_block_caption_latex(app, status, warning): app.builder.build_all() latex = (app.outdir / 'Python.tex').text(encoding='utf-8') - caption = '\\SphinxSetupCaptionForVerbatim{literal-block}{caption \\emph{test} rb}' + caption = '\\SphinxSetupCaptionForVerbatim{literal-block}{\label{caption:caption-test-rb}caption \\emph{test} rb}' assert caption in latex @@ -229,7 +229,7 @@ def test_literalinclude_caption_html(app, status, warning): def test_literalinclude_caption_latex(app, status, warning): app.builder.build('index') latex = (app.outdir / 'Python.tex').text(encoding='utf-8') - caption = '\\SphinxSetupCaptionForVerbatim{literal-block}{caption \\textbf{test} py}' + caption = '\\SphinxSetupCaptionForVerbatim{literal-block}{\label{caption:caption-test-py}caption \\textbf{test} py}' assert caption in latex From a124a396257310d308a7298b89aa7bf6583c1405 Mon Sep 17 00:00:00 2001 From: jfbu Date: Sun, 3 Apr 2016 16:50:47 +0200 Subject: [PATCH 03/19] Remove unneeded test "if 'ids':" from previous commit. modified: sphinx/writers/latex.py --- sphinx/writers/latex.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sphinx/writers/latex.py b/sphinx/writers/latex.py index 801726f4e..544fb60b6 100644 --- a/sphinx/writers/latex.py +++ b/sphinx/writers/latex.py @@ -1995,8 +1995,7 @@ class LaTeXTranslator(nodes.NodeVisitor): # suppress with anchor=False \phantomsection generation ids += self.hypertarget(node['ids'][0], anchor=False) self.body.append('\n') - if ids: - self.context.append(ids) # will be used in visit_caption + self.context.append(ids) # will be used in visit_caption def depart_container(self, node): if node.get('literal_block'): From ad1cc969d33ea09f8baac677cf8953b8ece51b6c Mon Sep 17 00:00:00 2001 From: jfbu Date: Mon, 4 Apr 2016 10:10:05 +0200 Subject: [PATCH 04/19] Fix two issues in latex.py reported by Travis CI modified: sphinx/writers/latex.py --- sphinx/writers/latex.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sphinx/writers/latex.py b/sphinx/writers/latex.py index f0c51ced5..2ac92c149 100644 --- a/sphinx/writers/latex.py +++ b/sphinx/writers/latex.py @@ -1445,8 +1445,7 @@ class LaTeXTranslator(nodes.NodeVisitor): if self.in_container_literal_block: self.body.append('\\needspace{\\literalblockneedspace}') self.body.append('\\vspace{\\literalblockcaptiontopvspace}\n') - self.body.append('\\SphinxSetupCaptionForVerbatim{literal-block}{' - + self.context.pop()) + self.body.append('\\SphinxSetupCaptionForVerbatim{literal-block}{' + self.context.pop()) elif self.in_minipage and isinstance(node.parent, nodes.figure): self.body.append('\\captionof{figure}{') else: @@ -1995,7 +1994,8 @@ class LaTeXTranslator(nodes.NodeVisitor): # suppress with anchor=False \phantomsection generation ids += self.hypertarget(node['ids'][0], anchor=False) self.body.append('\n') - self.context.append(ids) # will be used in visit_caption + # context.pop will be done in visit_caption + self.context.append(ids) def depart_container(self, node): if node.get('literal_block'): From 5cad1481aab59d67fff900eeaedc32fb2dc3242e Mon Sep 17 00:00:00 2001 From: jfbu Date: Mon, 4 Apr 2016 10:14:20 +0200 Subject: [PATCH 05/19] Fix line too long issue reported by Travis CI modified: sphinx/writers/latex.py --- sphinx/writers/latex.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sphinx/writers/latex.py b/sphinx/writers/latex.py index 2ac92c149..d587c1fbe 100644 --- a/sphinx/writers/latex.py +++ b/sphinx/writers/latex.py @@ -1445,7 +1445,8 @@ class LaTeXTranslator(nodes.NodeVisitor): if self.in_container_literal_block: self.body.append('\\needspace{\\literalblockneedspace}') self.body.append('\\vspace{\\literalblockcaptiontopvspace}\n') - self.body.append('\\SphinxSetupCaptionForVerbatim{literal-block}{' + self.context.pop()) + self.body.append('\\SphinxSetupCaptionForVerbatim{literal-block}{' + '' + self.context.pop()) elif self.in_minipage and isinstance(node.parent, nodes.figure): self.body.append('\\captionof{figure}{') else: From 261ff1a9d2f1794f72c275718f31555089fd7e99 Mon Sep 17 00:00:00 2001 From: jfbu Date: Thu, 7 Apr 2016 11:27:33 +0200 Subject: [PATCH 06/19] Enable pdf hyperlinks to named literal-blocks without caption. This is tango between latex.py and sphinx.sty to handle PDF hyperlinks to literal-blocks (both code-block and literalinclude) either with name or caption (then numref can be used) or both. modified: sphinx/texinputs/sphinx.sty modified: sphinx/writers/latex.py This test file is now back to original. modified: tests/test_directive_code.py --- sphinx/texinputs/sphinx.sty | 16 +++++++++++++++- sphinx/writers/latex.py | 26 ++++++++++++++++++-------- tests/test_directive_code.py | 4 ++-- 3 files changed, 35 insertions(+), 11 deletions(-) diff --git a/sphinx/texinputs/sphinx.sty b/sphinx/texinputs/sphinx.sty index 1e8f43978..3cd81fdca 100644 --- a/sphinx/texinputs/sphinx.sty +++ b/sphinx/texinputs/sphinx.sty @@ -186,8 +186,11 @@ \newcommand*\SphinxVerbatimTitle {} \newcommand*\SphinxSetupCaptionForVerbatim [2] {% - \def\SphinxVerbatimTitle{\captionof{#1}{#2}\smallskip }% + \needspace{\literalblockneedspace}\vspace{\literalblockcaptiontopvspace}% + \def\SphinxVerbatimTitle + {\captionof{#1}{\SphinxLiteralBlockLabel #2}\smallskip }% } +\newcommand*\SphinxLiteralBlockLabel {} % \SphinxCustomFBox is copied from framed.sty's \CustomFBox, but % #1=title/caption is to be set _above_ the top rule, not _below_ @@ -246,6 +249,16 @@ \bgroup\parskip\z@skip \smallskip % use customized framed environment + % first, check if has caption + \ifx\SphinxVerbatimTitle\empty + % no caption. Require space if at bottom of page + \needspace{\literalblockwithoutcaptionneedspace}% + % if there is a label insert hypertarget. + \ifx\SphinxLiteralBlockLabel\empty\else + \phantomsection\SphinxLiteralBlockLabel + \fi + \fi + % non empty \SphinxVerbatimTitle has label inside if there is one. \let\SphinxFrameTitle\SphinxVerbatimTitle \global\Sphinx@myfirstframedpasstrue % The list environement is needed to control perfectly the vertical @@ -625,5 +638,6 @@ \RequirePackage{needspace} % if the left page space is less than \literalblockneedsapce, insert page-break \newcommand{\literalblockneedspace}{5\baselineskip} +\newcommand{\literalblockwithoutcaptionneedspace}{1.5\baselineskip} % margin before the caption of literal-block \newcommand{\literalblockcaptiontopvspace}{0.5\baselineskip} diff --git a/sphinx/writers/latex.py b/sphinx/writers/latex.py index d587c1fbe..9a1760ce5 100644 --- a/sphinx/writers/latex.py +++ b/sphinx/writers/latex.py @@ -1443,10 +1443,7 @@ class LaTeXTranslator(nodes.NodeVisitor): def visit_caption(self, node): self.in_caption += 1 if self.in_container_literal_block: - self.body.append('\\needspace{\\literalblockneedspace}') - self.body.append('\\vspace{\\literalblockcaptiontopvspace}\n') - self.body.append('\\SphinxSetupCaptionForVerbatim{literal-block}{' - '' + self.context.pop()) + self.body.append('\\SphinxSetupCaptionForVerbatim{literal-block}{') elif self.in_minipage and isinstance(node.parent, nodes.figure): self.body.append('\\captionof{figure}{') else: @@ -1801,6 +1798,16 @@ class LaTeXTranslator(nodes.NodeVisitor): # most probably a parsed-literal block -- don't highlight self.body.append('\\begin{alltt}\n') else: + ids = '' + for id in self.pop_hyperlink_ids('code-block'): + ids += self.hypertarget(id, anchor=False) + if node['ids']: + # suppress with anchor=False \phantomsection insertion + ids += self.hypertarget(node['ids'][0], anchor=False) + # define label for use in caption, or directly if none exist. + # LaTeX code will add the \phantomsection in latter case. + if ids: + self.body.append('\n\\def\\SphinxLiteralBlockLabel{' + ids + '}') code = node.astext() lang = self.hlsettingstack[-1][0] linenos = code.count('\n') >= self.hlsettingstack[-1][1] - 1 @@ -1834,6 +1841,8 @@ class LaTeXTranslator(nodes.NodeVisitor): hlcode = hlcode.rstrip()[:-14] # strip \end{Verbatim} self.body.append('\n' + hlcode + '\\end{%sVerbatim}\n' % (self.table and 'Original' or '')) + if ids: + self.body.append('\\let\\SphinxLiteralBlockLabel\empty\n') raise nodes.SkipNode def depart_literal_block(self, node): @@ -1992,15 +2001,16 @@ class LaTeXTranslator(nodes.NodeVisitor): for id in self.pop_hyperlink_ids('code-block'): ids += self.hypertarget(id, anchor=False) if node['ids']: - # suppress with anchor=False \phantomsection generation + # suppress with anchor=False \phantomsection insertion ids += self.hypertarget(node['ids'][0], anchor=False) - self.body.append('\n') - # context.pop will be done in visit_caption - self.context.append(ids) + # define label for use in caption. + if ids: + self.body.append('\n\\def\\SphinxLiteralBlockLabel{' + ids + '}\n') def depart_container(self, node): if node.get('literal_block'): self.in_container_literal_block -= 1 + self.body.append('\\let\\SphinxLiteralBlockLabel\\empty\n') def visit_decoration(self, node): pass diff --git a/tests/test_directive_code.py b/tests/test_directive_code.py index 59a440b53..6f7b749b1 100644 --- a/tests/test_directive_code.py +++ b/tests/test_directive_code.py @@ -64,7 +64,7 @@ def test_code_block_caption_html(app, status, warning): def test_code_block_caption_latex(app, status, warning): app.builder.build_all() latex = (app.outdir / 'Python.tex').text(encoding='utf-8') - caption = '\\SphinxSetupCaptionForVerbatim{literal-block}{\label{caption:caption-test-rb}caption \\emph{test} rb}' + caption = '\\SphinxSetupCaptionForVerbatim{literal-block}{caption \\emph{test} rb}' assert caption in latex @@ -229,7 +229,7 @@ def test_literalinclude_caption_html(app, status, warning): def test_literalinclude_caption_latex(app, status, warning): app.builder.build('index') latex = (app.outdir / 'Python.tex').text(encoding='utf-8') - caption = '\\SphinxSetupCaptionForVerbatim{literal-block}{\label{caption:caption-test-py}caption \\textbf{test} py}' + caption = '\\SphinxSetupCaptionForVerbatim{literal-block}{caption \\textbf{test} py}' assert caption in latex From 267c266561cd6a19da1eca564c67be47d6dd9719 Mon Sep 17 00:00:00 2001 From: jfbu Date: Thu, 7 Apr 2016 11:56:43 +0200 Subject: [PATCH 07/19] Fix comment modified: sphinx/writers/latex.py --- sphinx/writers/latex.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sphinx/writers/latex.py b/sphinx/writers/latex.py index 9a1760ce5..32d71c99b 100644 --- a/sphinx/writers/latex.py +++ b/sphinx/writers/latex.py @@ -1804,8 +1804,7 @@ class LaTeXTranslator(nodes.NodeVisitor): if node['ids']: # suppress with anchor=False \phantomsection insertion ids += self.hypertarget(node['ids'][0], anchor=False) - # define label for use in caption, or directly if none exist. - # LaTeX code will add the \phantomsection in latter case. + # LaTeX code will insert \phantomsection prior to \label if ids: self.body.append('\n\\def\\SphinxLiteralBlockLabel{' + ids + '}') code = node.astext() From 9df7783ba280865468179a40532f8675bb23b287 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Sun, 10 Apr 2016 20:25:25 +0900 Subject: [PATCH 08/19] Fix #2395: Sphinx crashs if unicode character in image filename --- CHANGES | 1 + sphinx/config.py | 2 +- tests/roots/test-image-glob/index.rst | 2 ++ tests/test_intl.py | 2 +- 4 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGES b/CHANGES index 4d9627e84..71c4dc019 100644 --- a/CHANGES +++ b/CHANGES @@ -29,6 +29,7 @@ Bugs fixed * #2412: Fix hyperlink targets are broken in LaTeX builder * Fix figure directive crashes if non paragraph item is given as caption * #2418: Fix time formats no longer allowed in today_fmt +* #2395: Fix Sphinx crashs if unicode character in image filename Release 1.4 (released Mar 28, 2016) diff --git a/sphinx/config.py b/sphinx/config.py index 73f442cf9..e199e7ddc 100644 --- a/sphinx/config.py +++ b/sphinx/config.py @@ -58,7 +58,7 @@ class Config(object): language = (None, 'env', string_classes), locale_dirs = ([], 'env'), - figure_language_filename = ('{root}.{language}{ext}', 'env', [str]), + figure_language_filename = (u'{root}.{language}{ext}', 'env', [str]), master_doc = ('contents', 'env'), source_suffix = (['.rst'], 'env'), diff --git a/tests/roots/test-image-glob/index.rst b/tests/roots/test-image-glob/index.rst index 6ac4a90ef..d43e7e3ba 100644 --- a/tests/roots/test-image-glob/index.rst +++ b/tests/roots/test-image-glob/index.rst @@ -12,3 +12,5 @@ test-image-glob .. figure:: img.* The caption of img + +.. image:: testimäge.png diff --git a/tests/test_intl.py b/tests/test_intl.py index e82d9f3ed..47a51589d 100644 --- a/tests/test_intl.py +++ b/tests/test_intl.py @@ -841,7 +841,7 @@ def test_image_glob_intl(app, status, warning): @with_app(buildername='dummy', testroot='image-glob', confoverrides={'language': 'xx', - 'figure_language_filename': '{root}{ext}.{language}'}) + 'figure_language_filename': u'{root}{ext}.{language}'}) def test_image_glob_intl_using_figure_language_filename(app, status, warning): app.builder.build_all() From 062a9f935e8c858a648be20dd69f8d2bcd204b4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ionel=20Cristian=20M=C4=83rie=C8=99?= Date: Tue, 29 Mar 2016 03:07:36 +0300 Subject: [PATCH 09/19] Seems that e6a5a3a92e938fcd75866b4227db9e0524d58f7c forgot to update this file. --- sphinx/themes/basic/genindex-single.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sphinx/themes/basic/genindex-single.html b/sphinx/themes/basic/genindex-single.html index a771c587b..93fb9b332 100644 --- a/sphinx/themes/basic/genindex-single.html +++ b/sphinx/themes/basic/genindex-single.html @@ -37,7 +37,7 @@ {%- for column in entries|slice(2) if column %}
- {%- for entryname, (links, subitems) in column %} + {%- for entryname, (links, subitems, _) in column %} {{ indexentries(entryname, links) }} {%- if subitems %}
From aaac328336ac106f9fa1fdaf2ac5abb20518d55f Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Sun, 10 Apr 2016 20:52:14 +0900 Subject: [PATCH 10/19] Update CHANGES for PR#2396 --- CHANGES | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES b/CHANGES index 71c4dc019..86ead5363 100644 --- a/CHANGES +++ b/CHANGES @@ -30,6 +30,7 @@ Bugs fixed * Fix figure directive crashes if non paragraph item is given as caption * #2418: Fix time formats no longer allowed in today_fmt * #2395: Fix Sphinx crashs if unicode character in image filename +* #2396: Fix "too many values to unpack" in genindex-single Release 1.4 (released Mar 28, 2016) From afb83c249f7904ba00ad1d262b7d3a0d8c620bd6 Mon Sep 17 00:00:00 2001 From: jfbu Date: Sun, 10 Apr 2016 18:43:55 +0200 Subject: [PATCH 11/19] Make reset of \SphinxVerbatimTitle to \empty explicit in produced LaTeX files modified: sphinx/texinputs/sphinx.sty modified: sphinx/writers/latex.py --- sphinx/texinputs/sphinx.sty | 15 +++++++-------- sphinx/writers/latex.py | 1 + 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/sphinx/texinputs/sphinx.sty b/sphinx/texinputs/sphinx.sty index 3cd81fdca..bbcf73ecc 100644 --- a/sphinx/texinputs/sphinx.sty +++ b/sphinx/texinputs/sphinx.sty @@ -190,6 +190,7 @@ \def\SphinxVerbatimTitle {\captionof{#1}{\SphinxLiteralBlockLabel #2}\smallskip }% } +% \SphinxLiteralBlockLabel will be set dynamically to hold the label for links \newcommand*\SphinxLiteralBlockLabel {} % \SphinxCustomFBox is copied from framed.sty's \CustomFBox, but @@ -248,17 +249,17 @@ % list starts new par, but we don't want it to be set apart vertically \bgroup\parskip\z@skip \smallskip - % use customized framed environment - % first, check if has caption + % first, let's check if there is a caption \ifx\SphinxVerbatimTitle\empty - % no caption. Require space if at bottom of page - \needspace{\literalblockwithoutcaptionneedspace}% - % if there is a label insert hypertarget. + % there was no caption. Check if nevertheless a label was set. \ifx\SphinxLiteralBlockLabel\empty\else + % we require some space to be sure hyperlink target from \phantomsection + % will not be separated from upcoming verbatim by a page break + \needspace{\literalblockwithoutcaptionneedspace}% \phantomsection\SphinxLiteralBlockLabel \fi \fi - % non empty \SphinxVerbatimTitle has label inside if there is one. + % non-empty \SphinxVerbatimTitle has label inside it (in case there is one) \let\SphinxFrameTitle\SphinxVerbatimTitle \global\Sphinx@myfirstframedpasstrue % The list environement is needed to control perfectly the vertical @@ -280,8 +281,6 @@ \endlist % close group to restore \parskip (and \SphinxFrameTitle) \egroup - % reset to empty \SphinxVerbatimTitle - \global\let\SphinxVerbatimTitle\empty } diff --git a/sphinx/writers/latex.py b/sphinx/writers/latex.py index 32d71c99b..98a68d70d 100644 --- a/sphinx/writers/latex.py +++ b/sphinx/writers/latex.py @@ -2009,6 +2009,7 @@ class LaTeXTranslator(nodes.NodeVisitor): def depart_container(self, node): if node.get('literal_block'): self.in_container_literal_block -= 1 + self.body.append('\\let\\SphinxVerbatimTitle\\empty\n') self.body.append('\\let\\SphinxLiteralBlockLabel\\empty\n') def visit_decoration(self, node): From a4aefd454a6a1b4350f5a2cda4b159573b4f707a Mon Sep 17 00:00:00 2001 From: jfbu Date: Sun, 10 Apr 2016 18:48:52 +0200 Subject: [PATCH 12/19] Remove unneeded \bgroup/\egroup in legacy sphinx.sty definition of Verbatim Indeed, sphinx.sty redefines _environment_ Verbatim, and LaTeX's environments always are scope-limiting for local assignments. modified: sphinx/texinputs/sphinx.sty --- sphinx/texinputs/sphinx.sty | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/sphinx/texinputs/sphinx.sty b/sphinx/texinputs/sphinx.sty index bbcf73ecc..ce17407bb 100644 --- a/sphinx/texinputs/sphinx.sty +++ b/sphinx/texinputs/sphinx.sty @@ -247,7 +247,7 @@ \renewcommand{\Verbatim}[1][1]{% % list starts new par, but we don't want it to be set apart vertically - \bgroup\parskip\z@skip + \parskip\z@skip \smallskip % first, let's check if there is a caption \ifx\SphinxVerbatimTitle\empty @@ -279,8 +279,7 @@ \endOriginalVerbatim \endMakeFramed \endlist - % close group to restore \parskip (and \SphinxFrameTitle) - \egroup + % LaTeX environments always revert local changes on exit, here e.g. \parskip } From 673222f20a14fd2a3270f330379bba586008f277 Mon Sep 17 00:00:00 2001 From: jfbu Date: Sun, 10 Apr 2016 20:42:00 +0200 Subject: [PATCH 13/19] Added Tests for latex(pdf) links to captioned or named literal blocks As conf.py has now numfig = True, needed to modify accordingly test for links in html output. This topic branch fixes #2405, #2414, and also makes for latex(pdf) functional hyperlinks to named references, but only for literal blocks (code-block or literalinclude). modified: tests/roots/test-directive-code/caption.rst modified: tests/roots/test-directive-code/conf.py new file: tests/roots/test-directive-code/namedblocks.rst modified: tests/test_directive_code.py --- tests/roots/test-directive-code/caption.rst | 35 ++++++++++++++- tests/roots/test-directive-code/conf.py | 2 + .../roots/test-directive-code/namedblocks.rst | 28 ++++++++++++ tests/test_directive_code.py | 44 +++++++++++++++++++ 4 files changed, 107 insertions(+), 2 deletions(-) create mode 100644 tests/roots/test-directive-code/namedblocks.rst diff --git a/tests/roots/test-directive-code/caption.rst b/tests/roots/test-directive-code/caption.rst index 5a2fe4a1f..e8389b994 100644 --- a/tests/roots/test-directive-code/caption.rst +++ b/tests/roots/test-directive-code/caption.rst @@ -1,5 +1,13 @@ -Dedent -====== +Caption +======= + +References +---------- + +See :numref:`caption *test* rb` and :numref:`caption **test** py`. + +See :ref:`Ruby ` and :ref:`Python `. + Code blocks ----------- @@ -19,3 +27,26 @@ Literal Include :language: python :caption: caption **test** py :lines: 10-11 + + +Named Code blocks +----------------- + +.. code-block:: ruby + :name: name *test* rb + :caption: caption *test* rbnamed + + def ruby? + false + end + + +Named Literal Include +--------------------- + +.. literalinclude:: literal.inc + :language: python + :name: name **test** py + :caption: caption **test** pynamed + :lines: 10-11 + diff --git a/tests/roots/test-directive-code/conf.py b/tests/roots/test-directive-code/conf.py index e10f5e5fb..6601c76a9 100644 --- a/tests/roots/test-directive-code/conf.py +++ b/tests/roots/test-directive-code/conf.py @@ -2,3 +2,5 @@ master_doc = 'index' exclude_patterns = ['_build'] +numfig = True + diff --git a/tests/roots/test-directive-code/namedblocks.rst b/tests/roots/test-directive-code/namedblocks.rst new file mode 100644 index 000000000..5779bc972 --- /dev/null +++ b/tests/roots/test-directive-code/namedblocks.rst @@ -0,0 +1,28 @@ +Named Blocks +============ + +References to named blocks +-------------------------- + +See :ref:`the ruby code ` and +also :ref:`the python code `. + + +Named Code block +---------------- + +.. code-block:: ruby + :name: some ruby code + + def ruby? + false + end + + +Named Literal Include +--------------------- + +.. literalinclude:: literal.inc + :language: python + :name: some python code + diff --git a/tests/test_directive_code.py b/tests/test_directive_code.py index 6f7b749b1..84341a28c 100644 --- a/tests/test_directive_code.py +++ b/tests/test_directive_code.py @@ -54,6 +54,7 @@ def test_code_block_caption_html(app, status, warning): app.builder.build(['caption']) html = (app.outdir / 'caption.html').text(encoding='utf-8') caption = (u'
' + u'Listing 1 ' u'caption test rb' u'\xb6
') @@ -65,7 +66,28 @@ def test_code_block_caption_latex(app, status, warning): app.builder.build_all() latex = (app.outdir / 'Python.tex').text(encoding='utf-8') caption = '\\SphinxSetupCaptionForVerbatim{literal-block}{caption \\emph{test} rb}' + label = '\\def\\SphinxLiteralBlockLabel{\\label{caption:caption-test-rb}}' + link = '\hyperref[caption:caption-test-rb]' \ + '{Listing \\ref{caption:caption-test-rb}}' assert caption in latex + assert label in latex + assert link in latex + + +@with_app('latex', testroot='directive-code') +def test_code_block_namedlink_latex(app, status, warning): + app.builder.build_all() + latex = (app.outdir / 'Python.tex').text(encoding='utf-8') + label1 = '\def\SphinxLiteralBlockLabel{\label{caption:name-test-rb}}' + link1 = '\\hyperref[caption:name\\string-test\\string-rb]'\ + '{\\crossref{\\DUrole{std,std-ref}{Ruby}}' + label2 = '\def\SphinxLiteralBlockLabel{\label{namedblocks:some-ruby-code}}' + link2 = '\\hyperref[namedblocks:some\\string-ruby\\string-code]'\ + '{\\crossref{\\DUrole{std,std-ref}{the ruby code}}}' + assert label1 in latex + assert link1 in latex + assert label2 in latex + assert link2 in latex @with_app('xml', testroot='directive-code') @@ -219,6 +241,7 @@ def test_literalinclude_caption_html(app, status, warning): app.builder.build('index') html = (app.outdir / 'caption.html').text(encoding='utf-8') caption = (u'
' + u'Listing 2 ' u'caption test py' u'\xb6
') @@ -230,7 +253,28 @@ def test_literalinclude_caption_latex(app, status, warning): app.builder.build('index') latex = (app.outdir / 'Python.tex').text(encoding='utf-8') caption = '\\SphinxSetupCaptionForVerbatim{literal-block}{caption \\textbf{test} py}' + label = '\\def\\SphinxLiteralBlockLabel{\\label{caption:caption-test-py}}' + link = '\hyperref[caption:caption-test-py]' \ + '{Listing \\ref{caption:caption-test-py}}' assert caption in latex + assert label in latex + assert link in latex + + +@with_app('latex', testroot='directive-code') +def test_literalinclude_namedlink_latex(app, status, warning): + app.builder.build('index') + latex = (app.outdir / 'Python.tex').text(encoding='utf-8') + label1 = '\def\SphinxLiteralBlockLabel{\label{caption:name-test-py}}' + link1 = '\\hyperref[caption:name\\string-test\\string-py]'\ + '{\\crossref{\\DUrole{std,std-ref}{Python}}' + label2 = '\def\SphinxLiteralBlockLabel{\label{namedblocks:some-python-code}}' + link2 = '\\hyperref[namedblocks:some\\string-python\\string-code]'\ + '{\\crossref{\\DUrole{std,std-ref}{the python code}}}' + assert label1 in latex + assert link1 in latex + assert label2 in latex + assert link2 in latex @with_app('xml', testroot='directive-code') From 750720ee90985fbf3a192670fc83562d56629561 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Mon, 11 Apr 2016 10:54:49 +0900 Subject: [PATCH 14/19] Update CHANGES for PR#2405 --- CHANGES | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES b/CHANGES index 86ead5363..7d5792e4a 100644 --- a/CHANGES +++ b/CHANGES @@ -31,6 +31,8 @@ Bugs fixed * #2418: Fix time formats no longer allowed in today_fmt * #2395: Fix Sphinx crashs if unicode character in image filename * #2396: Fix "too many values to unpack" in genindex-single +* #2405: Fix numref link in PDF jumps to the wrong location +* #2414: Fix missing number in PDF hyperlinks to code listings Release 1.4 (released Mar 28, 2016) From eb13982c41aa67fa8a3d638c8fd6aa969c57e4c0 Mon Sep 17 00:00:00 2001 From: "Korn, Uwe" Date: Tue, 12 Apr 2016 12:26:59 +0000 Subject: [PATCH 15/19] Fix wrong import for gmtime --- sphinx/util/i18n.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sphinx/util/i18n.py b/sphinx/util/i18n.py index 311787b8b..128484bd0 100644 --- a/sphinx/util/i18n.py +++ b/sphinx/util/i18n.py @@ -14,7 +14,7 @@ import os import re import warnings from os import path -from time import time +from time import time, gmtime from datetime import datetime from collections import namedtuple @@ -188,7 +188,7 @@ def format_date(format, date=None, language=None, warn=None): # See https://wiki.debian.org/ReproducibleBuilds/TimestampsProposal source_date_epoch = os.getenv('SOURCE_DATE_EPOCH') if source_date_epoch is not None: - date = time.gmtime(float(source_date_epoch)) + date = gmtime(float(source_date_epoch)) else: date = datetime.now() From ab02e2a06f6f9270cfb0f48f2334383df0c71d3f Mon Sep 17 00:00:00 2001 From: shimizukawa Date: Tue, 12 Apr 2016 21:57:01 +0900 Subject: [PATCH 16/19] Fix flake8 and update CHANGES for #2440 --- CHANGES | 1 + sphinx/util/i18n.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index 7d5792e4a..8116a57ca 100644 --- a/CHANGES +++ b/CHANGES @@ -33,6 +33,7 @@ Bugs fixed * #2396: Fix "too many values to unpack" in genindex-single * #2405: Fix numref link in PDF jumps to the wrong location * #2414: Fix missing number in PDF hyperlinks to code listings +* #2440: Fix wrong import for gmtime. Thanks to Uwe L. Korn. Release 1.4 (released Mar 28, 2016) diff --git a/sphinx/util/i18n.py b/sphinx/util/i18n.py index 128484bd0..f4a8bce4b 100644 --- a/sphinx/util/i18n.py +++ b/sphinx/util/i18n.py @@ -14,7 +14,7 @@ import os import re import warnings from os import path -from time import time, gmtime +from time import gmtime from datetime import datetime from collections import namedtuple From b8fe679b4c73dc801bfe1ddabcb88e8549003cca Mon Sep 17 00:00:00 2001 From: shimizukawa Date: Tue, 12 Apr 2016 22:05:25 +0900 Subject: [PATCH 17/19] tweak CHANGES --- CHANGES | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/CHANGES b/CHANGES index 8116a57ca..de6d77df8 100644 --- a/CHANGES +++ b/CHANGES @@ -24,16 +24,16 @@ Bugs fixed * C++, type declarations are now using the prefixes ``typedef``, ``using``, and ``type``, depending on the style of declaration. * #2413: C++, fix crash on duplicate declarations -* #2394: Fix Sphinx crashes when html_last_updated_fmt is invalid +* #2394: Sphinx crashes when html_last_updated_fmt is invalid * #2408: dummy builder not available in Makefile and make.bat -* #2412: Fix hyperlink targets are broken in LaTeX builder -* Fix figure directive crashes if non paragraph item is given as caption -* #2418: Fix time formats no longer allowed in today_fmt -* #2395: Fix Sphinx crashs if unicode character in image filename -* #2396: Fix "too many values to unpack" in genindex-single -* #2405: Fix numref link in PDF jumps to the wrong location -* #2414: Fix missing number in PDF hyperlinks to code listings -* #2440: Fix wrong import for gmtime. Thanks to Uwe L. Korn. +* #2412: hyperlink targets are broken in LaTeX builder +* figure directive crashes if non paragraph item is given as caption +* #2418: time formats no longer allowed in today_fmt +* #2395: Sphinx crashes if unicode character in image filename +* #2396: "too many values to unpack" in genindex-single +* #2405: numref link in PDF jumps to the wrong location +* #2414: missing number in PDF hyperlinks to code listings +* #2440: wrong import for gmtime. Thanks to Uwe L. Korn. Release 1.4 (released Mar 28, 2016) From 47681a063801df44c0bfbea0b0c4b4efe7bcd191 Mon Sep 17 00:00:00 2001 From: shimizukawa Date: Tue, 12 Apr 2016 22:12:19 +0900 Subject: [PATCH 18/19] Bump to 1.4.1 final --- CHANGES | 4 ++-- sphinx/__init__.py | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/CHANGES b/CHANGES index de6d77df8..25506a1bb 100644 --- a/CHANGES +++ b/CHANGES @@ -1,5 +1,5 @@ -Release 1.4.1 (in development) -============================== +Release 1.4.1 (released Apr 12, 2016) +===================================== Incompatible changes -------------------- diff --git a/sphinx/__init__.py b/sphinx/__init__.py index 9a7876fec..16ec7a4c6 100644 --- a/sphinx/__init__.py +++ b/sphinx/__init__.py @@ -15,13 +15,13 @@ import sys from os import path -__version__ = '1.4+' -__released__ = '1.4' # used when Sphinx builds its own docs +__version__ = '1.4.1' +__released__ = '1.4.1' # used when Sphinx builds its own docs # version info for better programmatic use # possible values for 3rd element: 'alpha', 'beta', 'rc', 'final' # 'final' has 0 as the last element -version_info = (1, 4, 1, 'beta', 1) +version_info = (1, 4, 1, 'final', 0) package_dir = path.abspath(path.dirname(__file__)) From 5655fe1e6a48c6dd120932c529101e06a0a74888 Mon Sep 17 00:00:00 2001 From: shimizukawa Date: Tue, 12 Apr 2016 22:20:08 +0900 Subject: [PATCH 19/19] Bump version --- CHANGES | 7 +++++++ sphinx/__init__.py | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/CHANGES b/CHANGES index 25506a1bb..b8ec77afd 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,10 @@ +Release 1.4.2 (in development) +============================== + +Bugs fixed +---------- + + Release 1.4.1 (released Apr 12, 2016) ===================================== diff --git a/sphinx/__init__.py b/sphinx/__init__.py index 16ec7a4c6..4e5e97a04 100644 --- a/sphinx/__init__.py +++ b/sphinx/__init__.py @@ -15,13 +15,13 @@ import sys from os import path -__version__ = '1.4.1' +__version__ = '1.4.1+' __released__ = '1.4.1' # used when Sphinx builds its own docs # version info for better programmatic use # possible values for 3rd element: 'alpha', 'beta', 'rc', 'final' # 'final' has 0 as the last element -version_info = (1, 4, 1, 'final', 0) +version_info = (1, 4, 2, 'beta', 1) package_dir = path.abspath(path.dirname(__file__))