@@ -61,8 +61,10 @@ module.exports = grammar({
6161
6262 // Explicit special cases: these are plaintext, not errors.
6363 _word_common : ( ) => choice (
64- // NOT optionlink: single "'".
64+ // NOT optionlink: '
6565 "'" ,
66+ // NOT optionlink: 'x
67+ seq ( "'" , token . immediate ( / [ ^ ' \n \t ] / ) ) ,
6668 // NOT optionlink: followed by non-lowercase char.
6769 seq ( "'" , token . immediate ( / [ a - z ] * [ ^ ' a - z \n \t ] [ a - z ] * / ) , optional ( token . immediate ( "'" ) ) ) ,
6870 // NOT optionlink: single char surrounded by "'".
@@ -199,7 +201,15 @@ module.exports = grammar({
199201 // Link to option: 'foo'. Lowercase non-digit ASCII, minimum 2 chars. #14
200202 optionlink : ( $ ) => _word ( $ , / [ a - z ] [ a - z ] + / , "'" , "'" ) ,
201203 // 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+ ) , '|' , '|' ) ,
203213 // Inline code (may contain whitespace!): `foo bar`
204214 codespan : ( $ ) => _word ( $ , / [ ^ ` ` \n ] + / , '`' , '`' ) ,
205215 // Argument: {arg}
@@ -208,9 +218,10 @@ module.exports = grammar({
208218} ) ;
209219
210220// 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
214225 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 ) ) ;
216227}
0 commit comments