diff options
author | Tim Graham <timograham@gmail.com> | 2015-11-16 11:13:09 -0500 |
---|---|---|
committer | Tim Graham <timograham@gmail.com> | 2015-11-16 20:41:06 -0500 |
commit | 904c47bc0643509311cfbde9de1138f3998d6dcb (patch) | |
tree | 857e9d19174b3a3c8464501a1dc78a2694605b11 | |
parent | a4973c8f285fbf3bd542cce9f19d775f089f0e19 (diff) | |
download | django-904c47bc0643509311cfbde9de1138f3998d6dcb.tar.gz |
[1.7.x] Fixed #23751 -- Fixed code snippet formatting in docs PDF.
Thanks Graham Wideman for the patch.
Backport of e48a5b5a03181b3ada6183595eb6e1c599a9657a from master
-rw-r--r-- | docs/_ext/djangodocs.py | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/docs/_ext/djangodocs.py b/docs/_ext/djangodocs.py index 6770ff46ac..dd141cd7c5 100644 --- a/docs/_ext/djangodocs.py +++ b/docs/_ext/djangodocs.py @@ -126,14 +126,8 @@ def visit_snippet_latex(self, node): """ Latex document generator visit handler """ - self.verbatim = '' + code = node.rawsource.rstrip('\n') - -def depart_snippet_latex(self, node): - """ - Latex document generator depart handler. - """ - code = self.verbatim.rstrip('\n') lang = self.hlsettingstack[-1][0] linenos = code.count('\n') >= self.hlsettingstack[-1][1] - 1 fname = node['filename'] @@ -152,9 +146,14 @@ def depart_snippet_latex(self, node): linenos=linenos, **highlight_args) - self.body.append('\n{\\colorbox[rgb]{0.9,0.9,0.9}' - '{\\makebox[\\textwidth][l]' - '{\\small\\texttt{%s}}}}\n' % (fname,)) + self.body.append( + '\n{\\colorbox[rgb]{0.9,0.9,0.9}' + '{\\makebox[\\textwidth][l]' + '{\\small\\texttt{%s}}}}\n' % ( + # Some filenames have '_', which is special in latex. + fname.replace('_', r'\_'), + ) + ) if self.table: hlcode = hlcode.replace('\\begin{Verbatim}', @@ -166,7 +165,16 @@ def depart_snippet_latex(self, node): hlcode = hlcode.rstrip() + '\n' self.body.append('\n' + hlcode + '\\end{%sVerbatim}\n' % (self.table and 'Original' or '')) - self.verbatim = None + + # Prevent rawsource from appearing in output a second time. + raise nodes.SkipNode + + +def depart_snippet_latex(self, node): + """ + Latex document generator depart handler. + """ + pass class SnippetWithFilename(Directive): |