docs/options.md: use a separate table for each option group
This commit is contained in:
@@ -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("<", "<").replace(">", ">")
|
||||
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),
|
||||
))
|
||||
|
||||
Reference in New Issue
Block a user