@@ -61,8 +61,10 @@ module.exports = grammar({
61
61
62
62
// Explicit special cases: these are plaintext, not errors.
63
63
_word_common : ( ) => choice (
64
- // NOT optionlink: single "'".
64
+ // NOT optionlink: '
65
65
"'" ,
66
+ // NOT optionlink: 'x
67
+ seq ( "'" , token . immediate ( / [ ^ ' \n \t ] / ) ) ,
66
68
// NOT optionlink: followed by non-lowercase char.
67
69
seq ( "'" , token . immediate ( / [ a - z ] * [ ^ ' a - z \n \t ] [ a - z ] * / ) , optional ( token . immediate ( "'" ) ) ) ,
68
70
// NOT optionlink: single char surrounded by "'".
@@ -199,7 +201,15 @@ module.exports = grammar({
199
201
// Link to option: 'foo'. Lowercase non-digit ASCII, minimum 2 chars. #14
200
202
optionlink : ( $ ) => _word ( $ , / [ a - z ] [ a - z ] + / , "'" , "'" ) ,
201
203
// Link to tag: |foo|
202
- taglink : ( $ ) => _word ( $ , / [ ^ | \n \t ] + / , '|' , '|' ) ,
204
+ taglink : ( $ ) => _word ( $ , choice (
205
+ token . immediate ( / [ ^ | \n \t ] + / ) ,
206
+ // Special cases: |(| |{| …
207
+ token . immediate ( '{' ) ,
208
+ token . immediate ( '}' ) ,
209
+ token . immediate ( '(' ) ,
210
+ token . immediate ( ')' ) ,
211
+ token . immediate ( '`' ) ,
212
+ ) , '|' , '|' ) ,
203
213
// Inline code (may contain whitespace!): `foo bar`
204
214
codespan : ( $ ) => _word ( $ , / [ ^ ` ` \n ] + / , '`' , '`' ) ,
205
215
// Argument: {arg}
@@ -208,9 +218,10 @@ module.exports = grammar({
208
218
} ) ;
209
219
210
220
// 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 ) {
221
+ // `rule` can be a rule function or regex. It is aliased to "word" because they are
222
+ // semantically the same: atoms of captured plain text.
223
+ function _word ( $ , rule , c1 , c2 , fname ) {
224
+ rule = rule . test !== undefined ? token . immediate ( rule ) : rule
214
225
fname = fname ?? 'text' ;
215
- return seq ( c1 , field ( fname , alias ( token . immediate ( word_regex ) , $ . word ) ) , token . immediate ( c2 ) ) ;
226
+ return seq ( c1 , field ( fname , alias ( rule , $ . word ) ) , token . immediate ( c2 ) ) ;
216
227
}
0 commit comments