Merge pull request #20589 from Homebrew/pod2man-improve

feat: update pod2man normalize
This commit is contained in:
Mike McQuaid 2025-08-28 08:25:02 +00:00 committed by GitHub
commit e235466dee
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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)