Skip to content

Commit cc3c564

Browse files
committed
Titles are sorted now by length to help better match sentences containing words that are also titles
Signed-off-by: Hofi <hofione@gmail.com>
1 parent dff039c commit cc3c564

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

_plugins/generate_tooltips.rb

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def process_markdown_parts(page, markdown)
126126

127127
# Search for known link titles
128128
# NOTE: Using multi line matching here will not help either if the pattern itself is in the middle broken/spaned to multiple lines, so using whitespace replacements now inside the patter to handle this, see above!
129-
full_pattern = /(^|[\s.,;:&'"\-(])(#{pattern})([\s.,;:&'"\-)]|\z)(?![^<]*?<\/a>)/
129+
full_pattern = /(^|[\s.,;:&'"(])(#{pattern})([\s.,;:&'")]|\z)(?![^<]*?<\/a>)/
130130
markdown_part = process_markdown_part(page, markdown_part, page_links, full_pattern, id, url, needs_tooltip, true)
131131
else
132132
# Content inside of special Markdown blocks
@@ -232,7 +232,11 @@ def page_links_ids_sorted_by_title(page_links)
232232
end
233233
end
234234

235-
sorted_arr.sort_by { |page| page["title"].downcase }.reverse
235+
# With this reversed length sort order we try to guarantie that
236+
# the autolink/tooltip title pattern matching finds titles like
237+
# 'Soft macros' before 'macros'
238+
# In most of the cases matching the longer titles first will eliminate such issues
239+
sorted_arr.sort_by { |page| page["title"].length }.reverse
236240
end
237241

238242
def gen_page_link_data(links_dir, link_files_pattern)
@@ -287,16 +291,15 @@ def gen_page_link_data(links_dir, link_files_pattern)
287291
puts "Unknow ID (#{alias_id}) in alias definition"
288292
exit 4
289293
end
290-
_, aliases = alias_data.first
291-
page_link_data["title"] = aliases.concat(page_link_data["title"])
292-
#puts "page_link_data: #{page_link_data}"
294+
page_link_data["title"].concat(alias_data["aliases"])
295+
# puts "page_link_data: #{page_link_data}"
293296
end
294297

295298
# Just for debugging
296299
# pp page_links_dictionary
297-
page_links_ids_sorted_by_title(page_links_dictionary).each do |data|
298-
#puts data
299-
end
300+
# page_links_ids_sorted_by_title(page_links_dictionary).each do |data|
301+
# puts data
302+
# end
300303

301304
#pp page_links_dictionary
302305
return page_links_dictionary

0 commit comments

Comments
 (0)