BURs: fix rewriting wiki links with qualifiers.
When renaming a tag and the new tag has a qualifier, use the pipe trick to hide the qualifier in wiki links. For example, renaming Fallout to Fallout_(series) should change wiki links from [[Fallout]] to [[Fallout (series)|]].
This commit is contained in:
@@ -176,7 +176,6 @@ class DText
|
||||
|
||||
# Strip qualifiers, e.g. `atago (midsummer march) (azur lane)` => `atago`
|
||||
unqualified_name = name.tr("_", " ").squeeze(" ").strip.gsub(/( \(.*\))+\z/, "")
|
||||
has_qualifier = name.match?(/( \(.*\))+\z/)
|
||||
|
||||
# If old tag was lowercase, e.g. [[ink tank (Splatoon)]], then keep new tag in lowercase.
|
||||
if unqualified_name == unqualified_name.downcase
|
||||
@@ -195,7 +194,8 @@ class DText
|
||||
|
||||
if title.present?
|
||||
"[[#{final_name}|#{title}]]"
|
||||
elsif has_qualifier
|
||||
# If the new name has a qualifier, then hide the qualifier in the link.
|
||||
elsif final_name.match?(/( \(.*\))+\z/)
|
||||
"[[#{final_name}|]]"
|
||||
else
|
||||
"[[#{final_name}]]"
|
||||
|
||||
@@ -151,6 +151,8 @@ class DTextTest < ActiveSupport::TestCase
|
||||
|
||||
assert_rewrite_wiki_links("[[Zelda no Densetsu]]", "[[Zelda no Densetsu]]", "zelda_no_densetsu", "the_legend_of_zelda")
|
||||
assert_rewrite_wiki_links("[[Zelda_no_Densetsu]]", "[[Zelda_no_Densetsu]]", "zelda_no_densetsu", "the_legend_of_zelda")
|
||||
|
||||
assert_rewrite_wiki_links("[[Mario (series)|]]", "[[Mario]]", "mario", "mario_(series)")
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user