From c7bf1aa222136fb571baddaac250cd3affc1815e Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Wed, 17 Oct 2012 18:22:57 -0700 Subject: [PATCH] Handle some more escapes in de-groffing man pages Fixes https://github.com/fish-shell/fish-shell/issues/10 --- share/tools/create_manpage_completions.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/share/tools/create_manpage_completions.py b/share/tools/create_manpage_completions.py index 4b0c2657b..7b0c6de97 100755 --- a/share/tools/create_manpage_completions.py +++ b/share/tools/create_manpage_completions.py @@ -509,10 +509,15 @@ class TypeDarwinManParser(ManParser): line = line[3:] return line + # Replace some groff escapes. There's a lot we don't bother to handle. + def groff_replace_escapes(self, line): + line = line.replace('\\ ', ' ') + line = line.replace('\& ', '') + return line + def is_option(self, line): return line.startswith('.It Fl') - def parseManPage(self, manpage): got_something = False lines = manpage.splitlines() @@ -528,10 +533,15 @@ class TypeDarwinManParser(ManParser): if not lines: continue + # Get the line and clean it up + line = lines.pop(0) + line = self.groff_replace_escapes(line) + line = self.trim_groff(line) + line = line.strip() + if not line: continue + # Extract the name - name = self.trim_groff(lines.pop(0)).strip() - if not name: continue - name = name.split(None, 2)[0] + name = line.split(None, 2)[0] # Extract the description desc = '' @@ -741,6 +751,7 @@ def parse_manpage_at_path(manpage_path, yield_to_dirs, output_directory): # Output the magic word Autogenerated so we can tell if we can overwrite this built_command_output.insert(1, "# Autogenerated from man pages") + built_command_output.insert(2, "# using " + parser_name) for line in built_command_output: output_file.write(line) output_file.write('\n')