Peano
Loading...
Searching...
No Matches
include-filter.py
Go to the documentation of this file.
1#!/usr/bin/env python3
2"""!
3Doxygen input filter for .dox files.
4
5Doxygen 1.9 does not understand the raise option of the include command with the doc and raise options. This filter
6therefore expands such lines itself: it inlines the referenced Markdown file, drops its
7YAML front matter, and shifts all Markdown headings down by N levels. Paths are
8relative to the directory Doxygen is run from (the repository root).
9
10@param sys.argv[1]: str
11 The .dox file to filter. The result is written to stdout.
12"""
13
14import re
15import sys
16
17INCLUDE = re.compile(r"^@include\{doc,raise=(\d+)\}\s+(\S+)\s*$")
18
19
20def expand(path, raise_by):
21 with open(path, encoding="utf-8") as f:
22 lines = f.read().splitlines()
23 if lines and lines[0].strip() == "---":
24 lines = lines[lines[1:].index("---") + 2 :]
25 result = []
26 in_code = False
27 for line in lines:
28 if line.lstrip().startswith("```"):
29 in_code = not in_code
30 elif not in_code:
31 m = re.match(r"^(#+)\s*(\S.*)$", line)
32 if m:
33 line = "#" * min(len(m.group(1)) + raise_by, 6) + " " + m.group(2)
34 result.append(line)
35 return "\n".join(result)
36
37
38with open(sys.argv[1], encoding="utf-8") as f:
39 for line in f.read().splitlines():
40 m = INCLUDE.match(line)
41 print(expand(m.group(2), int(m.group(1))) if m else line)
expand(path, raise_by)