@@ -10,7 +10,8 @@ import * as tk from './text.mjs';
1010import * as re from './regexp.mjs' ;
1111import assign from './assign.mjs' ;
1212
13- const NL = '\n' ; // New line character
13+ const CR = '\r' ; // carriage-return character
14+ const LF = '\n' ; // line-feed character
1415const EMOJI_VARIATION = '\ufe0f' ; // Variation selector, follows heart and others
1516const EMOJI_JOINER = '\u200d' ; // zero-width joiner
1617const OBJECT_REPLACEMENT = '\ufffc' ; // whitespace placeholder that sometimes appears in rich text editors
@@ -121,10 +122,15 @@ export function init(customSchemes = []) {
121122 // Whitespace jumps
122123 // Tokens of only non-newline whitespace are arbitrarily long
123124 // If any whitespace except newline, more whitespace!
125+ const Nl = tt ( Start , LF , tk . NL , { [ fsm . whitespace ] : true } ) ;
126+ const Cr = tt ( Start , CR , tk . WS , { [ fsm . whitespace ] : true } ) ;
124127 const Ws = tr ( Start , re . SPACE , tk . WS , { [ fsm . whitespace ] : true } ) ;
125128 tt ( Start , OBJECT_REPLACEMENT , Ws ) ;
126- tt ( Start , NL , tk . NL , { [ fsm . whitespace ] : true } ) ;
127- tt ( Ws , NL ) ; // non-accepting state to avoid mixing whitespaces
129+ tt ( Cr , LF , Nl ) ; // \r\n
130+ tt ( Cr , OBJECT_REPLACEMENT , Ws ) ;
131+ tr ( Cr , re . SPACE , Ws ) ;
132+ tt ( Ws , CR ) ; // non-accepting state to avoid mixing whitespaces
133+ tt ( Ws , LF ) ; // non-accepting state to avoid mixing whitespaces
128134 tr ( Ws , re . SPACE , Ws ) ;
129135 tt ( Ws , OBJECT_REPLACEMENT , Ws ) ;
130136
0 commit comments