@@ -140,6 +140,11 @@ def exclusive?(attr)
140
140
# character
141
141
142
142
def convert_attrs ( str , attrs , exclusive = false )
143
+ convert_attrs_matching_word_pairs ( str , attrs , exclusive )
144
+ convert_attrs_word_pair_map ( str , attrs , exclusive )
145
+ end
146
+
147
+ def convert_attrs_matching_word_pairs ( str , attrs , exclusive )
143
148
# first do matching ones
144
149
tags = @matching_word_pairs . select { |start , bitmap |
145
150
if exclusive && exclusive? ( bitmap )
@@ -149,21 +154,25 @@ def convert_attrs(str, attrs, exclusive = false)
149
154
else
150
155
false
151
156
end
152
- } . keys . join ( "" )
157
+ } . keys
158
+ return if tags . empty?
159
+ all_tags = @matching_word_pairs . keys
153
160
154
- re = /(^|\W ) ([#{ tags } ])([#\\ ]?[\w :.\/ \[ \] -]+?\S ?)\2 (\W |$)/
161
+ re = /(^|\W |[ #{ all_tags . join ( "" ) } ]) ([#{ tags . join ( "" ) } ])(\2 * [#\\ ]?[\w :.\/ \[ \] -]+?\S ?)\2 (?! \2 )([ #{ all_tags . join ( "" ) } ]| \W |$)/
155
162
156
163
1 while str . gsub! ( re ) { |orig |
157
164
attr = @matching_word_pairs [ $2]
158
- updated = attrs . set_attrs ( $`. length + $1. length + $2. length , $3. length , attr )
159
- if updated
165
+ attr_updated = attrs . set_attrs ( $`. length + $1. length + $2. length , $3. length , attr )
166
+ if attr_updated
160
167
$1 + NULL * $2. length + $3 + NULL * $2. length + $4
161
168
else
162
169
$1 + NON_PRINTING_START + $2 + NON_PRINTING_END + $3 + NON_PRINTING_START + $2 + NON_PRINTING_END + $4
163
170
end
164
171
}
165
172
str . delete! ( NON_PRINTING_START + NON_PRINTING_END )
173
+ end
166
174
175
+ def convert_attrs_word_pair_map ( str , attrs , exclusive )
167
176
# then non-matching
168
177
unless @word_pair_map . empty? then
169
178
@word_pair_map . each do |regexp , attr |
0 commit comments