From e0f1fb54a32a6eecda5d54b5f71344c75f7f44e6 Mon Sep 17 00:00:00 2001 From: Daeho Ro <40587651+daeho-ro@users.noreply.github.com> Date: Wed, 27 Aug 2025 16:17:24 +0900 Subject: [PATCH] feat: update pod2man normalize --- Library/Homebrew/keg.rb | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/Library/Homebrew/keg.rb b/Library/Homebrew/keg.rb index 0e909bf74d..4117411047 100644 --- a/Library/Homebrew/keg.rb +++ b/Library/Homebrew/keg.rb @@ -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)