Skip to content

Commit cae7098

Browse files
authoredAug 23, 2019
Merge pull request #281 from kevindew/vanishing-or-duplicating-spacing
Consistently handle inline elements with spaces
2 parents 80297ce + b73068c commit cae7098

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed
 

‎src/node.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,15 @@ function flankingWhitespace (node) {
2222
var trailing = ''
2323

2424
if (!node.isBlock) {
25-
var hasLeading = /^[ \r\n\t]/.test(node.textContent)
26-
var hasTrailing = /[ \r\n\t]$/.test(node.textContent)
25+
var hasLeading = /^\s/.test(node.textContent)
26+
var hasTrailing = /\s$/.test(node.textContent)
27+
var blankWithSpaces = node.isBlank && hasLeading && hasTrailing
2728

2829
if (hasLeading && !isFlankedByWhitespace('left', node)) {
2930
leading = ' '
3031
}
31-
if (hasTrailing && !isFlankedByWhitespace('right', node)) {
32+
33+
if (!blankWithSpaces && hasTrailing && !isFlankedByWhitespace('right', node)) {
3234
trailing = ' '
3335
}
3436
}

‎test/index.html

+14
Original file line numberDiff line numberDiff line change
@@ -888,6 +888,20 @@ <h2>This is a header.</h2>
888888
<pre class="expected">![](http://example.com/logo.png)</pre>
889889
</div>
890890

891+
<div class="case" data-name="text separated by a space in an element">
892+
<div class="input">
893+
<p>Foo<span> </span>Bar</p>
894+
</div>
895+
<pre class="expected">Foo Bar</pre>
896+
</div>
897+
898+
<div class="case" data-name="text separated by a non-breaking space in an element">
899+
<div class="input">
900+
<p>Foo<span>&nbsp;</span>Bar</p>
901+
</div>
902+
<pre class="expected">Foo Bar</pre>
903+
</div>
904+
891905
<!-- /TEST CASES -->
892906

893907
<script src="turndown-test.browser.js"></script>

0 commit comments

Comments
 (0)
Please sign in to comment.