Skip to content

Commit 6d2e934

Browse files
authored
Merge pull request #155 from accordproject/dl-softbreaks
fix(markdown-html): updates softbreaks
2 parents 7b141d8 + 0c31959 commit 6d2e934

File tree

3 files changed

+24
-9
lines changed

3 files changed

+24
-9
lines changed

packages/markdown-html/src/ToHtmlStringVisitor.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,10 @@ class ToHtmlStringVisitor {
135135
parameters.result += '\n<hr>\n';
136136
break;
137137
case 'Linebreak':
138-
parameters.result += '<br>\n';
138+
parameters.result += '<br>';
139139
break;
140140
case 'Softbreak':
141-
parameters.result += '<wbr>';
141+
parameters.result += '\n';
142142
break;
143143
case 'Link':
144144
parameters.result += `<a href="${thing.destination}" title=${thing.title}>${ToHtmlStringVisitor.visitChildren(this, thing)}</a>`;

packages/markdown-html/src/__snapshots__/HtmlTransformer.test.js.snap

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -398,10 +398,17 @@ exports[`html converts clause.md to html 2`] = `
398398
"<html>
399399
<body>
400400
<div class=\\"document\\">
401-
<p>This is a fixed interest loan to the amount of <span class=\\"variable\\" id=\\"loanAmount\\">100000.0</span><wbr>at the yearly interest rate of <span class=\\"variable\\" id=\\"rate\\">2.5</span>%<wbr>with a loan term of <span class=\\"variable\\" id=\\"loanDuration\\">15</span>,<wbr>and monthly payments of <span class=\\"computed\\">667.0</span></p>
402-
<p>This is a fixed interest loan to the amount of 100000.0<wbr>at the yearly interest rate of 2.5%<wbr>with a loan term of 15,<wbr>and monthly payments of 667.0</p>
401+
<p>This is a fixed interest loan to the amount of <span class=\\"variable\\" id=\\"loanAmount\\">100000.0</span>
402+
at the yearly interest rate of <span class=\\"variable\\" id=\\"rate\\">2.5</span>%
403+
with a loan term of <span class=\\"variable\\" id=\\"loanDuration\\">15</span>,
404+
and monthly payments of <span class=\\"computed\\">667.0</span></p>
405+
<p>This is a fixed interest loan to the amount of 100000.0
406+
at the yearly interest rate of 2.5%
407+
with a loan term of 15,
408+
and monthly payments of 667.0</p>
403409
<div class=\\"clause\\" clauseid=\\"bar\\" src=\\"foo\\">
404-
<p>this is<wbr>multiline <span class=\\"variable\\" id=\\"rate\\">2.5</span></p>
410+
<p>this is
411+
multiline <span class=\\"variable\\" id=\\"rate\\">2.5</span></p>
405412
<p>content</p>
406413
</div>
407414
</div>

packages/markdown-html/src/rules.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,18 @@ const TEXT_RULE = {
3232

3333
// text nodes will be of type 3
3434
if (el.nodeType === 3 && !isIgnorable(el)) {
35-
return {
36-
'$class': `${NS_PREFIX_CommonMarkModel}${'Text'}`,
37-
text: el.nodeValue,
38-
};
35+
const textArray = el.nodeValue.split('\n');
36+
const textNodes = textArray.map(text => {
37+
if (text) {
38+
return {
39+
'$class': `${NS_PREFIX_CommonMarkModel}${'Text'}`,
40+
text,
41+
};
42+
}
43+
});
44+
45+
const result = [...textNodes].map((node, i) => i < textNodes.length - 1 ? [node, { '$class': `${NS_PREFIX_CommonMarkModel}${'Softbreak'}` }] : [node]).reduce((a, b) => a.concat(b)).filter(n => !!n);
46+
return result;
3947
}
4048
}
4149
};

0 commit comments

Comments
 (0)