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