Merge pull request #20589 from Homebrew/pod2man-improve
feat: update pod2man normalize
This commit is contained in:
commit
e235466dee
@ -563,7 +563,7 @@ class Keg
|
|||||||
|
|
||||||
def normalize_pod2man_outputs!
|
def normalize_pod2man_outputs!
|
||||||
# Only process uncompressed manpages, which end in a digit
|
# Only process uncompressed manpages, which end in a digit
|
||||||
manpages = Dir[path/"share/man/*/*.[1-9]"]
|
manpages = Dir[path/"share/man/*/*.[1-9]{,p,pm}"]
|
||||||
generated_regex = /^\.\\"\s*Automatically generated by .*\n/
|
generated_regex = /^\.\\"\s*Automatically generated by .*\n/
|
||||||
manpages.each do |f|
|
manpages.each do |f|
|
||||||
manpage = Pathname.new(f)
|
manpage = Pathname.new(f)
|
||||||
@ -581,15 +581,30 @@ class Keg
|
|||||||
|
|
||||||
content = content.gsub(generated_regex, "")
|
content = content.gsub(generated_regex, "")
|
||||||
content = content.lines.map do |line|
|
content = content.lines.map do |line|
|
||||||
next line unless line.start_with?(".TH")
|
if line.start_with?(".TH")
|
||||||
|
|
||||||
# Split the line by spaces, but preserve quoted strings
|
# Split the line by spaces, but preserve quoted strings
|
||||||
parts = line.split(/\s(?=(?:[^"]|"[^"]*")*$)/)
|
parts = line.split(/\s(?=(?:[^"]|"[^"]*")*$)/)
|
||||||
next line if parts.length != 6
|
next line if parts.length != 6
|
||||||
|
|
||||||
# pod2man embeds the perl version used into the 5th field of the footer
|
# pod2man embeds the perl version used into the 5th field of the footer
|
||||||
T.must(parts[4]).gsub!(/^"perl v.*"$/, "\"\"")
|
parts[4]&.gsub!(/^"perl v.*"$/, "\"\"")
|
||||||
|
# man extension remove in man files
|
||||||
|
parts[2]&.gsub!(/([1-9]){,p,pm}/, "\\1")
|
||||||
|
|
||||||
"#{parts.join(" ")}\n"
|
"#{parts.join(" ")}\n"
|
||||||
|
elsif line.start_with?(".IX")
|
||||||
|
# Split the line by spaces, but preserve quoted strings
|
||||||
|
parts = line.split(/\s(?=(?:[^"]|"[^"]*")*$)/)
|
||||||
|
next line if parts.length != 3
|
||||||
|
next line if parts[1] != "Title"
|
||||||
|
|
||||||
|
# man extension remove in man files
|
||||||
|
parts[2]&.gsub!(/\s+([1-9]){,p,pm}/, "\\1")
|
||||||
|
|
||||||
|
"#{parts.join(" ")}\n"
|
||||||
|
else
|
||||||
|
line
|
||||||
|
end
|
||||||
end.join
|
end.join
|
||||||
|
|
||||||
manpage.atomic_write(content)
|
manpage.atomic_write(content)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user