docs/options.md: use a separate table for each option group

This commit is contained in:
Mike Fährmann
2023-01-03 16:04:48 +01:00
parent ed2d715019
commit 50d89d4acb
2 changed files with 83 additions and 58 deletions

View File

@@ -11,6 +11,7 @@
import os
import re
from argparse import SUPPRESS
import util
from gallery_dl import option
@@ -20,33 +21,38 @@ TEMPLATE = """# Command-Line Options
<!-- auto-generated by {} -->
{}
"""
TABLE = """
## {}
<table>
<thead>
<tr>
<th></th>
<th width="26%"></th>
<th></th>
</tr>
</thead>
<tbody valign="top">
{}
</tbody>
</table>
"""
""".format
ROW = """<tr>
<td>{}</td>
<td{}>{}</td>
<td>{}</td>
</tr>""".format
tbody = []
append = tbody.append
sub = re.compile(r"'([^']+)'").sub
tables = []
for group in option.build_parser()._action_groups[2:]:
append('\n<tr>\n <td colspan="3"><strong>' +
group.title + '</strong></td>\n</tr>')
tbody = []
append = tbody.append
width = ' width="28%"'
for action in group._group_actions:
help = action.help
if help == "==SUPPRESS==":
if help == SUPPRESS:
continue
try:
@@ -62,16 +68,18 @@ for group in option.build_parser()._action_groups[2:]:
short = "<code>" + short + "</code>"
if long:
long = '<code>' + long + "</code>"
if help:
help = help.replace("<", "&lt;").replace(">", "&gt;")
help = sub("<code>\\1</code>", help)
append("<tr>")
append(" <td>" + short + "</td>")
append(" <td>" + long + "</td>")
append(" <td>" + sub("<code>\\1</code>", help) + "</td>")
append("</tr>")
append(ROW(short, width, long, help))
width = ""
tables.append(TABLE(group.title, "\n".join(tbody)))
with open(util.path("docs", "options.md"), "w", encoding="utf-8") as fp:
fp.write(TEMPLATE.format(
"/".join(os.path.normpath(__file__).split(os.sep)[-2:]),
"\n".join(tbody),
"\n".join(tables),
))