Skip to content
Snippets Groups Projects
Commit 84ac0dcc authored by Dennis Gläser's avatar Dennis Gläser
Browse files

[doxygen][md-filter] hardcode main readme modification

parent a7d6402c
No related branches found
No related tags found
1 merge request!3453Feature/doxygen markdown main readme
Pipeline #29237 passed
+3
...@@ -18,8 +18,7 @@ TOC_INCLUDE_HEADINGS = 4 ...@@ -18,8 +18,7 @@ TOC_INCLUDE_HEADINGS = 4
# Input filters run over content before it is parsed by Doxygen. # Input filters run over content before it is parsed by Doxygen.
# - Format markdown math for Doxygen. See the documentation in # - Format markdown math for Doxygen. See the documentation in
# `markdown-math-filter.pl` for details. # `markdown-math-filter.pl` for details.
FILTER_PATTERNS = *README.md="python3 @srcdir@/markdown-filter.py -p Introduction -f" \ FILTER_PATTERNS = *.md="python3 @srcdir@/markdown-filter.py"
*.md="python3 @srcdir@/markdown-filter.py -f"
FILE_PATTERNS = *.md,*.cc,*.hh FILE_PATTERNS = *.md,*.cc,*.hh
......
#!/usr/bin/python3 #!/usr/bin/python3
import sys
import string import string
import argparse
import subprocess import subprocess
from os.path import join, dirname, abspath from os.path import join, dirname, abspath, exists
THIS_DIR = dirname(__file__)
DOC_DIR = dirname(THIS_DIR)
TOP_LEVEL_DIR = dirname(DOC_DIR)
MAIN_README = abspath(join(TOP_LEVEL_DIR, "README.md"))
assert exists(MAIN_README)
def _filter_characters(text: str) -> str: def _filter_characters(text: str) -> str:
...@@ -23,30 +30,26 @@ def _invoke_and_retrieve_output(cmd) -> str: ...@@ -23,30 +30,26 @@ def _invoke_and_retrieve_output(cmd) -> str:
return subprocess.check_output(cmd, text=True) return subprocess.check_output(cmd, text=True)
if __name__ == "__main__": def _is_main_readme_file(path) -> bool:
parser = argparse.ArgumentParser(description="Process markdown files to be consumed by Doxygen") return path == MAIN_README
parser.add_argument("-f", "--file", required=True, help="The markdown file to be processed")
parser.add_argument(
"-p", assert len(sys.argv[1]) > 1
"--prepend-header", filePath = abspath(sys.argv[1])
required=False,
help="Adds the given header at the top of the file" # Invoke math filter to translate GitLab flavoured math to such supported by Doxygen
) math_conversion_script = join(dirname(abspath(__file__)), "markdown-math-filter.pl")
args = vars(parser.parse_args()) result = _invoke_and_retrieve_output(["perl", "-0777", "-p", math_conversion_script, filePath])
# Invoke math filter to translate GitLab flavoured math to such supported by Doxygen # for the main readme, prepend "Introduction" header
math_conversion_script = join(dirname(abspath(__file__)), "markdown-math-filter.pl") if _is_main_readme_file(filePath):
result = _invoke_and_retrieve_output(["perl", "-0777", "-p", math_conversion_script, args["file"]]) result = f"# Introduction\n\n{result}"
# (maybe) prepend the given header # Give all headers anchors (labels) s.t. doxygen cross-linking works
if args["prepend_header"]: # correctly (may be fixed in the most recent Doxygen version)
result = f"# {args['prepend_header']}\n\n{result}" result_lines = []
for line in result.split("\n"):
# Give all headers anchors (labels) s.t. doxygen cross-linking works result_lines.append(_add_header_label(line))
# correctly (may be fixed in the most recent Doxygen version)
result_lines = [] # Print the final result for Doxygen to pick it up
for line in result.split("\n"): print("\n".join(result_lines))
result_lines.append(_add_header_label(line))
# Print the final result for Doxygen to pick it up
print("\n".join(result_lines))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment