change 'c2rst' from source_parser -> extension; allows use of sphinx 2.x
This commit is contained in:
parent
143275db04
commit
d489c7a057
6
conf.py
6
conf.py
|
@ -54,7 +54,8 @@ extensions = [
|
||||||
'sphinx.ext.intersphinx',
|
'sphinx.ext.intersphinx',
|
||||||
'sphinx.ext.todo',
|
'sphinx.ext.todo',
|
||||||
'sphinx.ext.coverage',
|
'sphinx.ext.coverage',
|
||||||
'rstjinja'
|
'rstjinja',
|
||||||
|
'c2rst'
|
||||||
]
|
]
|
||||||
|
|
||||||
# Add any paths that contain templates here, relative to this directory.
|
# Add any paths that contain templates here, relative to this directory.
|
||||||
|
@ -63,8 +64,7 @@ templates_path = ['templates']
|
||||||
# The suffix of source filenames.
|
# The suffix of source filenames.
|
||||||
source_suffix = ['.rst', '.md', '.c', '.h']
|
source_suffix = ['.rst', '.md', '.c', '.h']
|
||||||
|
|
||||||
source_parsers = {'.md': CommonMarkParser,
|
source_parsers = {'.md': CommonMarkParser}
|
||||||
'.c': "c2rst.CStrip", '.h': "c2rst.CStrip"}
|
|
||||||
|
|
||||||
# The encoding of source files.
|
# The encoding of source files.
|
||||||
#source_encoding = 'utf-8-sig'
|
#source_encoding = 'utf-8-sig'
|
||||||
|
|
|
@ -1,19 +1,31 @@
|
||||||
import sphinx.parsers
|
def c2rst(app, docname, source):
|
||||||
|
""" Pre-parse '.c' & '.h' files that contain rST source.
|
||||||
|
"""
|
||||||
|
# Make sure we're outputting HTML
|
||||||
|
if app.builder.format != 'html':
|
||||||
|
return
|
||||||
|
|
||||||
class CStrip(sphinx.parsers.Parser):
|
fname = app.env.doc2path(docname)
|
||||||
def __init__(self):
|
if (not fname.endswith(".c") and
|
||||||
self.rst_parser = sphinx.parsers.RSTParser()
|
not fname.endswith(".h")):
|
||||||
|
#print("skipping:", fname)
|
||||||
|
return
|
||||||
|
|
||||||
def parse(self, inputstring, document):
|
src = source[0]
|
||||||
# This setting is missing starting with Sphinx 1.7.1 so we set it ourself.
|
|
||||||
document.settings.tab_width = 4
|
stripped = []
|
||||||
document.settings.character_level_inline_markup = False
|
for line in src.split("\n"):
|
||||||
stripped = []
|
line = line.strip()
|
||||||
for line in inputstring.split("\n"):
|
if line == "//|":
|
||||||
line = line.strip()
|
stripped.append("")
|
||||||
if line == "//|":
|
elif line.startswith("//| "):
|
||||||
stripped.append("")
|
stripped.append(line[len("//| "):])
|
||||||
elif line.startswith("//| "):
|
stripped = "\r\n".join(stripped)
|
||||||
stripped.append(line[len("//| "):])
|
|
||||||
stripped = "\r\n".join(stripped)
|
rendered = app.builder.templates.render_string(
|
||||||
self.rst_parser.parse(stripped, document)
|
stripped, app.config.html_context
|
||||||
|
)
|
||||||
|
source[0] = rendered
|
||||||
|
|
||||||
|
def setup(app):
|
||||||
|
app.connect("source-read", c2rst)
|
||||||
|
|
Loading…
Reference in New Issue