This repository was archived by the owner on Sep 11, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -153,10 +153,27 @@ export default class Markdown {
153153 ( node . type === 'text' && node . literal === ' ' )
154154 ) {
155155 text = '' ;
156+ continue ;
156157 }
158+
159+ // Break up text nodes on spaces, so that we don't shoot past them without resetting
157160 if ( node . type === 'text' ) {
158- text += node . literal ;
161+ const [ thisPart , ...nextParts ] = node . literal . split ( / ( ) / ) ;
162+ node . literal = thisPart ;
163+ text += thisPart ;
164+
165+ // Add the remaining parts as siblings
166+ nextParts . reverse ( ) . forEach ( part => {
167+ if ( part ) {
168+ const nextNode = new commonmark . Node ( 'text' ) ;
169+ nextNode . literal = part ;
170+ node . insertAfter ( nextNode ) ;
171+ // Make the iterator aware of the newly inserted node
172+ walker . resumeAt ( nextNode , true ) ;
173+ }
174+ } ) ;
159175 }
176+
160177 // We should not do this if previous node was not a textnode, as we can't combine it then.
161178 if ( ( node . type === 'emph' || node . type === 'strong' ) && previousNode . type === 'text' ) {
162179 if ( event . entering ) {
Original file line number Diff line number Diff line change @@ -157,5 +157,12 @@ describe("Markdown parser test", () => {
157157 const md = new Markdown ( testString ) ;
158158 expect ( md . toHTML ( ) ) . toEqual ( expectedResult ) ;
159159 } ) ;
160+
161+ it ( 'resumes applying formatting to the rest of a message after a link' , ( ) => {
162+ const testString = 'http://google.com/_thing_ *does* __not__ exist' ;
163+ const expectedResult = 'http://google.com/_thing_ <em>does</em> <strong>not</strong> exist' ;
164+ const md = new Markdown ( testString ) ;
165+ expect ( md . toHTML ( ) ) . toEqual ( expectedResult ) ;
166+ } ) ;
160167 } ) ;
161168} ) ;
You can’t perform that action at this time.
0 commit comments