@@ -199,7 +199,15 @@ module.exports = grammar({
199
199
// Link to option: 'foo'. Lowercase non-digit ASCII, minimum 2 chars. #14
200
200
optionlink : ( $ ) => _word ( $ , / [ a - z ] [ a - z ] + / , "'" , "'" ) ,
201
201
// Link to tag: |foo|
202
- taglink : ( $ ) => _word ( $ , / [ ^ | \n \t ] + / , '|' , '|' ) ,
202
+ taglink : ( $ ) => _word ( $ , choice (
203
+ token . immediate ( / [ ^ | \n \t ] + / ) ,
204
+ // Special cases: |(| |{| …
205
+ token . immediate ( '{' ) ,
206
+ token . immediate ( '}' ) ,
207
+ token . immediate ( '(' ) ,
208
+ token . immediate ( ')' ) ,
209
+ token . immediate ( '`' ) ,
210
+ ) , '|' , '|' ) ,
203
211
// Inline code (may contain whitespace!): `foo bar`
204
212
codespan : ( $ ) => _word ( $ , / [ ^ ` ` \n ] + / , '`' , '`' ) ,
205
213
// Argument: {arg}
@@ -208,9 +216,10 @@ module.exports = grammar({
208
216
} ) ;
209
217
210
218
// Word delimited by special chars.
211
- // The word_regex capture is aliased to "word" because they are semantically
212
- // the same: atoms of captured plain text.
213
- function _word ( $ , word_regex , c1 , c2 , fname ) {
219
+ // `rule` can be a rule function or regex. It is aliased to "word" because they are
220
+ // semantically the same: atoms of captured plain text.
221
+ function _word ( $ , rule , c1 , c2 , fname ) {
222
+ rule = rule . test !== undefined ? token . immediate ( rule ) : rule
214
223
fname = fname ?? 'text' ;
215
- return seq ( c1 , field ( fname , alias ( token . immediate ( word_regex ) , $ . word ) ) , token . immediate ( c2 ) ) ;
224
+ return seq ( c1 , field ( fname , alias ( rule , $ . word ) ) , token . immediate ( c2 ) ) ;
216
225
}
0 commit comments