diff options
| author | sommersoft <sommersoft@gmail.com> | 2019-07-28 15:59:26 -0500 |
|---|---|---|
| committer | sommersoft <sommersoft@gmail.com> | 2019-07-28 15:59:26 -0500 |
| commit | d489c7a0579d13d29d42f29d6284cf51e57013d5 (patch) | |
| tree | 765a6b2c46de48def5b1235a51b068b18b79bb0f /docs | |
| parent | 143275db044ae8a3f1d5aebb5b4c7ddfe49e4d69 (diff) | |
change 'c2rst' from source_parser -> extension; allows use of sphinx 2.x
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/c2rst.py | 46 |
1 files changed, 29 insertions, 17 deletions
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) |
