summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsommersoft <sommersoft@gmail.com>2019-07-28 15:59:26 -0500
committersommersoft <sommersoft@gmail.com>2019-07-28 15:59:26 -0500
commitd489c7a0579d13d29d42f29d6284cf51e57013d5 (patch)
tree765a6b2c46de48def5b1235a51b068b18b79bb0f
parent143275db044ae8a3f1d5aebb5b4c7ddfe49e4d69 (diff)
change 'c2rst' from source_parser -> extension; allows use of sphinx 2.x
-rw-r--r--conf.py6
-rw-r--r--docs/c2rst.py46
2 files changed, 32 insertions, 20 deletions
diff --git a/conf.py b/conf.py
index 7a00454e0..56625e758 100644
--- a/conf.py
+++ b/conf.py
@@ -54,7 +54,8 @@ extensions = [
'sphinx.ext.intersphinx',
'sphinx.ext.todo',
'sphinx.ext.coverage',
- 'rstjinja'
+ 'rstjinja',
+ 'c2rst'
]
# Add any paths that contain templates here, relative to this directory.
@@ -63,8 +64,7 @@ templates_path = ['templates']
# The suffix of source filenames.
source_suffix = ['.rst', '.md', '.c', '.h']
-source_parsers = {'.md': CommonMarkParser,
- '.c': "c2rst.CStrip", '.h': "c2rst.CStrip"}
+source_parsers = {'.md': CommonMarkParser}
# The encoding of source files.
#source_encoding = 'utf-8-sig'
diff --git a/docs/c2rst.py b/docs/c2rst.py
index 904fb7408..76489dca3 100644
--- a/docs/c2rst.py
+++ b/docs/c2rst.py
@@ -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):
- def __init__(self):
- self.rst_parser = sphinx.parsers.RSTParser()
+ fname = app.env.doc2path(docname)
+ if (not fname.endswith(".c") and
+ not fname.endswith(".h")):
+ #print("skipping:", fname)
+ return
- def parse(self, inputstring, document):
- # This setting is missing starting with Sphinx 1.7.1 so we set it ourself.
- document.settings.tab_width = 4
- document.settings.character_level_inline_markup = False
- stripped = []
- for line in inputstring.split("\n"):
- line = line.strip()
- if line == "//|":
- stripped.append("")
- elif line.startswith("//| "):
- stripped.append(line[len("//| "):])
- stripped = "\r\n".join(stripped)
- self.rst_parser.parse(stripped, document)
+ src = source[0]
+
+ stripped = []
+ for line in src.split("\n"):
+ line = line.strip()
+ if line == "//|":
+ stripped.append("")
+ elif line.startswith("//| "):
+ stripped.append(line[len("//| "):])
+ stripped = "\r\n".join(stripped)
+
+ rendered = app.builder.templates.render_string(
+ stripped, app.config.html_context
+ )
+ source[0] = rendered
+
+def setup(app):
+ app.connect("source-read", c2rst)