@@ -44,10 +44,11 @@ class ToMarkdownStringVisitor {
4444 static visitChildren ( visitor , thing , parameters ) {
4545 if ( ! parameters ) {
4646 parameters = { } ;
47- parameters . result = '' ;
48- parameters . first = false ;
4947 parameters . indent = 0 ;
48+ parameters . first = false ;
49+ parameters . blockIndent = 0 ;
5050 }
51+ parameters . result = '' ;
5152
5253 if ( thing . nodes ) {
5354 thing . nodes . forEach ( node => {
@@ -63,11 +64,12 @@ class ToMarkdownStringVisitor {
6364 * @param {* } parametersOut - the current parameters
6465 * @return {* } the new parameters with first set to true
6566 */
66- static mkParametersIn ( parametersOut ) {
67+ static mkParametersInBlock ( parametersOut ) {
6768 let parameters = { } ;
6869 parameters . result = '' ;
69- parameters . first = true ;
70+ parameters . first = false ;
7071 parameters . indent = parametersOut . indent ; // Same indentation
72+ parameters . blockIndent = parametersOut . blockIndent + 1 ;
7173 return parameters ;
7274 }
7375
@@ -81,6 +83,7 @@ class ToMarkdownStringVisitor {
8183 parameters . result = '' ;
8284 parameters . first = true ;
8385 parameters . indent = parametersOut . indent + 1 ; // Increases indentation
86+ parameters . blockIndent = parametersOut . blockIndent ;
8487 return parameters ;
8588 }
8689
@@ -93,6 +96,15 @@ class ToMarkdownStringVisitor {
9396 return new Array ( parameters . indent * 3 + 1 ) . join ( ' ' ) ;
9497 }
9598
99+ /**
100+ * Create blockQuote indendation
101+ * @param {* } parameters - the current parameters
102+ * @return {string } prefix for blockquote indentation
103+ */
104+ static mkIndentBlock ( parameters ) {
105+ return '> ' . repeat ( parameters . blockIndent ) ;
106+ }
107+
96108 /**
97109 * Create Setext heading
98110 * @param {number } level - the heading level
@@ -121,8 +133,10 @@ class ToMarkdownStringVisitor {
121133 * @param {* } level - number of new lines
122134 */
123135 static newBlock ( parameters , level ) {
124- const newlines = parameters . first ? '' : Array ( level ) . fill ( '\n' ) . join ( '' ) ;
136+ const fixLevel = parameters . blockIndent === 0 ? level : 1 ;
137+ const newlines = parameters . first ? '' : Array ( fixLevel ) . fill ( '\n' ) . join ( '' ) ;
125138 parameters . result += newlines ;
139+ parameters . result += ToMarkdownStringVisitor . mkIndentBlock ( parameters ) ;
126140 }
127141
128142 /**
@@ -159,9 +173,8 @@ class ToMarkdownStringVisitor {
159173 parameters . result += `**${ ToMarkdownStringVisitor . visitChildren ( this , thing ) } **` ;
160174 break ;
161175 case 'BlockQuote' : {
162- const parametersIn = ToMarkdownStringVisitor . mkParametersIn ( parameters ) ;
163- ToMarkdownStringVisitor . newBlock ( parameters , 2 ) ;
164- parameters . result += `> ${ ToMarkdownStringVisitor . visitChildren ( this , thing , parametersIn ) } ` ;
176+ const parametersIn = ToMarkdownStringVisitor . mkParametersInBlock ( parameters ) ;
177+ parameters . result += `${ ToMarkdownStringVisitor . visitChildren ( this , thing , parametersIn ) } ` ;
165178 }
166179 break ;
167180 case 'Heading' : {
@@ -182,7 +195,7 @@ class ToMarkdownStringVisitor {
182195 parameters . result += '\\\n' ;
183196 break ;
184197 case 'Softbreak' :
185- parameters . result += '\n' ;
198+ parameters . result += '\n' + ToMarkdownStringVisitor . mkIndentBlock ( parameters ) ;
186199 break ;
187200 case 'Link' :
188201 parameters . result += `[${ ToMarkdownStringVisitor . visitChildren ( this , thing ) } ](${ thing . destination } "${ thing . title ? thing . title : '' } ")` ;
@@ -192,7 +205,7 @@ class ToMarkdownStringVisitor {
192205 break ;
193206 case 'Paragraph' :
194207 ToMarkdownStringVisitor . newBlock ( parameters , 2 ) ;
195- parameters . result += `${ ToMarkdownStringVisitor . visitChildren ( this , thing ) } ` ;
208+ parameters . result += `${ ToMarkdownStringVisitor . visitChildren ( this , thing , parameters ) } ` ;
196209 break ;
197210 case 'HtmlBlock' :
198211 ToMarkdownStringVisitor . newBlock ( parameters , 2 ) ;
0 commit comments