2016-10-18 17:42:47 -07:00
|
|
|
import sphinx.parsers
|
|
|
|
|
|
|
|
class CStrip(sphinx.parsers.Parser):
|
2018-02-27 18:08:49 -08:00
|
|
|
def __init__(self):
|
|
|
|
self.rst_parser = sphinx.parsers.RSTParser()
|
2016-10-18 17:42:47 -07:00
|
|
|
|
2018-02-27 18:08:49 -08:00
|
|
|
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
|
2018-05-23 11:53:00 -07:00
|
|
|
document.settings.character_level_inline_markup = False
|
2018-02-27 18:08:49 -08:00
|
|
|
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)
|