feat: update pod2man normalize

This commit is contained in:
Daeho Ro 2025-08-27 16:17:24 +09:00
parent 81b79b93f3
commit e0f1fb54a3
No known key found for this signature in database

View File

@ -563,7 +563,7 @@ class Keg
def normalize_pod2man_outputs!
# 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/
manpages.each do |f|
manpage = Pathname.new(f)
@ -581,15 +581,30 @@ class Keg
content = content.gsub(generated_regex, "")
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
parts = line.split(/\s(?=(?:[^"]|"[^"]*")*$)/)
next line if parts.length != 6
# Split the line by spaces, but preserve quoted strings
parts = line.split(/\s(?=(?:[^"]|"[^"]*")*$)/)
next line if parts.length != 6
# pod2man embeds the perl version used into the 5th field of the footer
parts[4]&.gsub!(/^"perl v.*"$/, "\"\"")
# man extension remove in man files
parts[2]&.gsub!(/([1-9]){,p,pm}/, "\\1")
# pod2man embeds the perl version used into the 5th field of the footer
T.must(parts[4]).gsub!(/^"perl v.*"$/, "\"\"")
"#{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
manpage.atomic_write(content)