in scripts/extractdoc.py [0:0]
def renderf(filename, basedir=os.curdir):
lang = os.path.splitext(filename)[1][1:]
show = False
code = []
body = []
with open(filename) as fp:
for line in fp:
if (not show) and re.search(r'^\s*/// !show', line, re.MULTILINE):
show = True
continue
if show and re.search(r'^\s*/// !hide', line, re.MULTILINE):
show = False
if len(body):
body.append(cat(
f'```{lang}',
textwrap.dedent(cat(*code)),
'```',
f'[{os.path.basename(filename)}]({os.path.relpath(filename, basedir)})',
))
continue
if show:
code.append(line.rstrip())
continue
else:
code = []
if re.search(r'^\s*/// !tree', line, re.MULTILINE):
body.append(cat(
'```',
sh(f'cd {os.path.dirname(filename)} && tree -L 3 -F .').rstrip(),
'```',
))
continue
m = re.search(r'^\s*/// !!\s+(.*)', line, re.MULTILINE)
if m:
body.append(m.group(1))
continue
return cat(*body)