@@ -17,6 +17,7 @@ type Token =
1717 | { type : 'list' , ordered : boolean , items : Token [ ] [ ] }
1818 | { type : 'blockquote' , children : Token [ ] }
1919 | { type : 'codeblock' , language ?: string , content : string }
20+ | { type : 'hr' }
2021
2122function parseMarkdown ( text : string ) : Token [ ] {
2223 const tokens : Token [ ] = [ ]
@@ -50,6 +51,13 @@ function parseMarkdown(text: string): Token[] {
5051 continue
5152 }
5253
54+ // Horizontal rule
55+ if ( / ^ - - - + $ / . test ( line . trim ( ) ) ) {
56+ tokens . push ( { type : 'hr' } )
57+ i ++
58+ continue
59+ }
60+
5361 // Heading
5462 const headingMatch = / ^ ( # { 1 , 6 } ) \s + ( .* ) / . exec ( line )
5563 if ( headingMatch !== null ) {
@@ -110,6 +118,7 @@ function parseMarkdown(text: string): Token[] {
110118 if ( ln . startsWith ( '>' ) ) break // blockquote
111119 if ( / ^ ( # { 1 , 6 } ) \s + / . test ( ln ) ) break // heading
112120 if ( / ^ ( \s * ) ( [ - * + – • ‣ ◦ ○ ⚬ ] | \d + \. ) \s + / . test ( ln ) ) break // list item
121+ if ( / ^ - - - + $ / . test ( ln . trim ( ) ) ) break // horizontal rule
113122
114123 paraLines . push ( ln )
115124 i ++
@@ -499,6 +508,8 @@ function renderTokens(tokens: Token[], keyPrefix = ''): ReactNode[] {
499508 { key } ,
500509 createElement ( 'code' , null , token . content )
501510 )
511+ case 'hr' :
512+ return createElement ( 'hr' , { key } )
502513 default :
503514 return null
504515 }
0 commit comments