File tree Expand file tree Collapse file tree 3 files changed +34
-10
lines changed Expand file tree Collapse file tree 3 files changed +34
-10
lines changed Original file line number Diff line number Diff line change @@ -140,17 +140,17 @@ class ToMarkdownStringVisitor {
140140 * @param {* } parameters the parameters
141141 */
142142 visit ( thing , parameters ) {
143-
143+ const nodeText = thing . text ? thing . text : '' ;
144144 switch ( thing . getType ( ) ) {
145145 case 'CodeBlock' :
146146 ToMarkdownStringVisitor . newBlock ( parameters , 2 ) ;
147- parameters . result += `\`\`\`${ thing . info ? ' ' + thing . info : '' } \n${ ToMarkdownStringVisitor . escapeCodeBlock ( thing . text ) } \`\`\`` ;
147+ parameters . result += `\`\`\`${ thing . info ? ' ' + thing . info : '' } \n${ ToMarkdownStringVisitor . escapeCodeBlock ( nodeText ) } \`\`\`` ;
148148 break ;
149149 case 'Code' :
150- parameters . result += `\`${ thing . text } \`` ;
150+ parameters . result += `\`${ nodeText } \`` ;
151151 break ;
152152 case 'HtmlInline' :
153- parameters . result += thing . text ;
153+ parameters . result += nodeText ;
154154 break ;
155155 case 'Emph' :
156156 parameters . result += `*${ ToMarkdownStringVisitor . visitChildren ( this , thing ) } *` ;
@@ -196,10 +196,10 @@ class ToMarkdownStringVisitor {
196196 break ;
197197 case 'HtmlBlock' :
198198 ToMarkdownStringVisitor . newBlock ( parameters , 2 ) ;
199- parameters . result += ` ${ thing . text } ` ;
199+ parameters . result += nodeText ;
200200 break ;
201201 case 'Text' :
202- parameters . result += thing . text ;
202+ parameters . result += nodeText ;
203203 break ;
204204 case 'List' : {
205205 const first = thing . start ? parseInt ( thing . start ) : 1 ;
Original file line number Diff line number Diff line change @@ -902,7 +902,10 @@ Object {
902902 " nodes" : Array [
903903 Object {
904904 " $class" : " org.accordproject.commonmark.CodeBlock" ,
905- " text" : undefined ,
905+ " text" : " this
906+ is a
907+ code block .
908+ " ,
906909 },
907910 Object {
908911 " $class" : " org.accordproject.commonmark.Paragraph" ,
@@ -982,7 +985,10 @@ Object {
982985 " nodes" : Array [
983986 Object {
984987 " $class" : " org.accordproject.commonmark.CodeBlock" ,
985- " text" : undefined ,
988+ " text" : " this
989+ is a
990+ code block .
991+ " ,
986992 },
987993 Object {
988994 " $class" : " org.accordproject.commonmark.Paragraph" ,
Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ const NS_CICERO = 'org.accordproject.ciceromark';
2020
2121/**
2222 * Removes nodes if they are an empty paragraph
23- * @param {* } input the current result of slateToCiceroMarkDom
23+ * @param {* } input - the current result of slateToCiceroMarkDom
2424 * @returns {* } the final result of slateToCiceroMarkDom
2525 */
2626const removeEmptyParagraphs = ( input ) => {
@@ -38,6 +38,24 @@ const removeEmptyParagraphs = (input) => {
3838 return input ;
3939} ;
4040
41+ /**
42+ * Gather the text for the node
43+ * @param {* } input - the current slate node
44+ * @returns {string } the text contained in the slate node
45+ */
46+ const getText = ( input ) => {
47+ let result = '' ;
48+ if ( input . text ) {
49+ result += input . text ;
50+ }
51+ if ( input . nodes ) {
52+ input . nodes . forEach ( node => {
53+ result += getText ( node ) ;
54+ } ) ;
55+ }
56+ return result ;
57+ } ;
58+
4159/**
4260 * Converts a Slate document node to CiceroMark DOM (as JSON)
4361 * @param {* } document the Slate document node
@@ -118,7 +136,7 @@ function _recursive(parent, nodes) {
118136 result = { $class : `${ NS } .BlockQuote` , nodes : [ ] } ;
119137 break ;
120138 case 'code_block' :
121- result = { $class : `${ NS } .CodeBlock` , text : node . text } ;
139+ result = { $class : `${ NS } .CodeBlock` , text : getText ( node ) } ;
122140 break ;
123141 case 'html_block' :
124142 result = { $class : `${ NS } .HtmlBlock` , text : node . text } ;
You can’t perform that action at this time.
0 commit comments