File tree Expand file tree Collapse file tree 2 files changed +12
-5
lines changed
Expand file tree Collapse file tree 2 files changed +12
-5
lines changed Original file line number Diff line number Diff line change @@ -192,15 +192,16 @@ function setBlockType(
192192/**
193193 * Returns any block formatting characters (plus trailing space) at the very start of the passed text
194194 * @param text The text to check for leading block characters
195+ * @internal
195196 */
196197export function matchLeadingBlockCharacters ( text : string ) {
197198 // TODO this might be too aggressive... remove based on a whitelist instead?
198- // Match ordered lists prefixes
199- let match = / ^ ( \d + ) \. \s / . exec ( text ) ?. [ 0 ] ;
199+ // Match ordered list markers; see https://spec.commonmark.org/0.30/#ordered-list-marker
200+ let match = / ^ ( \d + ) (?: \. | \) ) \s / . exec ( text ) ?. [ 0 ] ;
200201
201202 // If text is not an ordered list block, check for other block types
202203 if ( ! match ) {
203- // TODO HACK assumes all non-orderedd list block types are non-letter characters followed by a single space
204+ // TODO HACK assumes all non-ordered list block types are non-letter characters followed by a single space
204205 match = / ^ [ ^ a - z A - Z 0 - 9 ] + \s { 1 } (? = [ a - z A - Z 0 - 9 _ * [ ! ] | $ ) + / . exec ( text ) ?. [ 0 ] ;
205206 }
206207
Original file line number Diff line number Diff line change @@ -530,17 +530,23 @@ some text`;
530530
531531 expect ( command ) . toBe ( "" ) ;
532532 } ) ;
533+
533534 it ( "return ordered list leading characters" , ( ) => {
534- const command =
535- commands . matchLeadingBlockCharacters ( "23. -ol item" ) ;
535+ let command = commands . matchLeadingBlockCharacters ( "23. -ol item" ) ;
536536
537537 expect ( command ) . toBe ( "23. " ) ;
538+
539+ command = commands . matchLeadingBlockCharacters ( "23) -ol item" ) ;
540+
541+ expect ( command ) . toBe ( "23) " ) ;
538542 } ) ;
543+
539544 it ( "return unordered list leading characters" , ( ) => {
540545 const command = commands . matchLeadingBlockCharacters ( "- 1 ul item" ) ;
541546
542547 expect ( command ) . toBe ( "- " ) ;
543548 } ) ;
549+
544550 it ( "return heading leading characters" , ( ) => {
545551 const command =
546552 commands . matchLeadingBlockCharacters ( "## Heading level 2" ) ;
You can’t perform that action at this time.
0 commit comments