summaryrefslogtreecommitdiff
path: root/docs/c2rst.py
diff options
context:
space:
mode:
authorDave Astels <dastels@daveastels.com>2019-07-31 18:46:41 -0400
committerDave Astels <dastels@daveastels.com>2019-07-31 18:46:41 -0400
commitcd092df9d875d444cf110fc0a1dbb427b261bf8a (patch)
treee0d2da5d55335a485d75cd2ada2e3d70e9fb2ccc /docs/c2rst.py
parent1f9cb44fa3a09996d042b7b9e01864bf2feac363 (diff)
parent366fdcce18e148a6828b7a7074e1e4198fca3595 (diff)
Merge remote-tracking branch 'adafruit/master' into displayio_fill_area
Diffstat (limited to 'docs/c2rst.py')
-rw-r--r--docs/c2rst.py46
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)