Skip to content

Commit

Permalink
[CI:DOCS] Improve titles of command HTML pages
Browse files Browse the repository at this point in the history
When building Sphinx HTML docs, preprocess markdown files and convert
pandoc-style title lines into recommonmark eval_rst blocks

This gives command HTML pages the same title as the equivalent manpage

Fixes: containers/podman.io#385

Signed-off-by: Rob Cowsill <[email protected]>
  • Loading branch information
rcowsill committed Apr 28, 2021
1 parent 633cc47 commit e18ef90
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
# import sys
# sys.path.insert(0, os.path.abspath('.'))

import re
from recommonmark.transform import AutoStructify

# -- Project information -----------------------------------------------------

Expand Down Expand Up @@ -59,3 +61,27 @@
]

# -- Extension configuration -------------------------------------------------

def convert_markdown_title(app, docname, source):
# Process markdown files only
docpath = app.env.doc2path(docname)
if docpath.endswith(".md"):
# Convert pandoc title line into eval_rst block for recommonmark
source[0] = re.sub(
r"^% (.*)",
r"```eval_rst\n.. title:: \g<1>\n```",
source[0])


def setup(app):
app.connect("source-read", convert_markdown_title)

app.add_config_value(
"recommonmark_config", {
"enable_eval_rst": True,
"enable_auto_doc_ref": False,
"enable_auto_toc_tree": False,
"enable_math": False,
"enable_inline_math": False,
}, True)
app.add_transform(AutoStructify)

0 comments on commit e18ef90

Please sign in to comment.