# HG changeset patch
# User Tim Dumol <tim@timdumol.com>
# Date 1257283130 -28800
# Node ID 50ac73467de3a933a77a85513dff5a867a2f46a1
# Parent 29ae8520f55147565f0c1996e6882d948722e75e
#7384 SageNB -- Fix sphinxify's doctests. Tim Dumol.
diff -r 29ae8520f551 -r 50ac73467de3 sagenb/misc/sphinxify.py
a
|
b
|
|
1 | | #!/usr/bin/python |
| 1 | #!/usr/bin/env python |
2 | 2 | r""" |
3 | 3 | Process docstrings with Sphinx |
4 | 4 | |
5 | 5 | Processes docstrings with Sphinx. Can also be used as a commandline script: |
6 | 6 | |
7 | | $ python sphinxify.py <text> |
| 7 | ``python sphinxify.py <text>`` |
8 | 8 | |
9 | 9 | AUTHORS: |
10 | 10 | |
11 | 11 | - Tim Joseph Dumol (2009-09-29): initial version |
12 | | |
| 12 | """ |
13 | 13 | #************************************************** |
14 | 14 | # Copyright (C) 2009 Tim Dumol <tim@timdumol.com> |
15 | 15 | # |
16 | 16 | # Distributed under the terms of the BSD License |
17 | 17 | #************************************************** |
18 | | """ |
19 | 18 | import os, hashlib, re, shutil |
20 | 19 | from tempfile import mkdtemp |
21 | 20 | |
… |
… |
|
35 | 34 | return ("`" in docstring or "::" in docstring) |
36 | 35 | |
37 | 36 | def sphinxify(docstring): |
38 | | """ |
| 37 | r""" |
39 | 38 | Runs Sphinx on a docstring, and outputs the processed documentation. |
40 | 39 | |
41 | 40 | INPUT: |
… |
… |
|
49 | 48 | EXAMPLES:: |
50 | 49 | |
51 | 50 | sage: from sagenb.misc.sphinxify import sphinxify |
52 | | sage: sphinxify('Foobar') |
53 | | '\n<div class="docstring">\n \n \n <p>Foobar</p>\n\n\n</div>' |
| 51 | sage: sphinxify('A test') |
| 52 | '\n<div class="docstring">\n \n <p>A test</p>\n\n\n</div>' |
54 | 53 | sage: sphinxify('**Testing**\n`monospace`') |
55 | | '\n<div class="docstring"...<strong>Testing</strong>\n<img..." alt="monospace" /></p>\n\n\n</div>' |
| 54 | '\n<div class="docstring"...<strong>Testing</strong>\n<span class="math"...</p>\n\n\n</div>' |
56 | 55 | """ |
57 | 56 | tmpdir = mkdtemp() |
58 | 57 | docstring_hash = hashlib.md5(docstring).hexdigest() |
… |
… |
|
108 | 107 | return new_html |
109 | 108 | |
110 | 109 | def generate_configuration(directory): |
111 | | """ |
| 110 | r""" |
112 | 111 | Generates Sphinx configuration at ``directory``. |
113 | 112 | |
114 | 113 | EXAMPLES:: |
… |
… |
|
118 | 117 | sage: tmpdir = tempfile.mkdtemp() |
119 | 118 | sage: generate_configuration(tmpdir) |
120 | 119 | sage: open(os.path.join(tmpdir, 'conf.py')).read() |
121 | | '\nextensions =...templates_path...NestedClass\n ' |
| 120 | '\n...extensions =...templates_path...source = False\n...' |
122 | 121 | """ |
123 | 122 | conf = r''' |
124 | 123 | ########################################################### |