lib/kramdown/parser/kramdown/abbreviation.rb in kramdown-0.13.7 vs lib/kramdown/parser/kramdown/abbreviation.rb in kramdown-0.13.8
- old
+ new
@@ -40,10 +40,11 @@
# Replace the abbreviation text with elements.
def replace_abbreviations(el, regexps = nil)
return if @root.options[:abbrev_defs].empty?
if !regexps
- regexps = [Regexp.union(*@root.options[:abbrev_defs].keys.map {|k| /#{Regexp.escape(k)}/})]
+ sorted_abbrevs = @root.options[:abbrev_defs].keys.sort {|a,b| b.length <=> a.length}
+ regexps = [Regexp.union(*sorted_abbrevs.map {|k| /#{Regexp.escape(k)}/})]
regexps << /(?=(?:\W|^)#{regexps.first}(?!\w))/ # regexp should only match on word boundaries
end
el.children.map! do |child|
if child.type == :text
if child.value =~ regexps.first