Skip to content

Commit ebe6ba6

Browse files
man/docgen (manpage_output): Add special cases
...to handle command-line options with complex argument structures (where "complex" means "anything but the most trivial case"). This causes them to format idiomatically, with parameters in italics, literals in bold, and "synopsis language", like brackets denoting optional parameters, in roman. This approach is necessary for idiomatic man page rendering because in the language interpreted by this script, there is no way to mark up such distinctions in code comments. Such a mini-language would have to be designed, and that way lies perlpod(1) and similar efforts.
1 parent 0f1c693 commit ebe6ba6

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

man/docgen

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -241,14 +241,26 @@ class Parameter:
241241
return ""
242242

243243
def manpage_output(self):
244-
result = self.name
245-
246244
if self.args:
247-
result += " " + self.args
248-
249-
result = '\\fB' + result + '\\fR'
250-
251-
result += "\n"
245+
# Special cases -- GBR is not proud.
246+
if self.args == "[<x> <y> | <xy>]":
247+
result = ".BR " + self.name + " \\~\\c\n" \
248+
+ ".RI [ x\~y | xy ]\n"
249+
elif self.args == "<WxH>":
250+
result = ".BI " + self.name + "\\~ W x H\n"
251+
elif self.args == "<x> <y>":
252+
result = ".BI " + self.name + "\\~ \"x y\"\n"
253+
elif self.args == "<files>":
254+
result = ".BI " + self.name + "\\~ \"file\\~\c\n" \
255+
+ "\\&.\\|.\\|.\n"
256+
elif self.args == "<save-num> <demo-name>":
257+
result = ".BI " + self.name \
258+
+ "\\~ \"save-num demo-name\"\n"
259+
else:
260+
self.args = re.sub(r'[<>]', '', self.args)
261+
result = ".BI " + self.name + "\\~ " + self.args + "\n"
262+
else:
263+
result = ".B " + self.name + "\n"
252264

253265
if self.platform:
254266
result += "[%s only] " % self.platform

0 commit comments

Comments
 (0)