Skip to content

Commit

Permalink
fix(newlines). Remove newline chars in text nodes (\n) when parsing…
Browse files Browse the repository at this point in the history
… HTML (bustle#478)

Fixes bustle#333
  • Loading branch information
bantic authored and johnelliott committed Feb 7, 2017
1 parent 06c8e52 commit 85d2fef
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 238 deletions.
8 changes: 7 additions & 1 deletion src/js/parsers/section.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ const SKIPPABLE_ELEMENT_TAG_NAMES = [
'style', 'head', 'title', 'meta'
].map(normalizeTagName);

const NEWLINES = /\n/g;
function sanitize(text) {
text = text.replace(NEWLINES, '');
return text;
}

/**
* parses an element into a section, ignoring any non-markup
* elements contained within
Expand Down Expand Up @@ -171,7 +177,7 @@ class SectionParser {

parseTextNode(textNode) {
let { state } = this;
state.text += textNode.textContent;
state.text += sanitize(textNode.textContent);
}

_updateStateFromElement(element) {
Expand Down
10 changes: 5 additions & 5 deletions tests/helpers/post-abstract.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,7 @@ function parseTextIntoMarkers(text, builder) {
markers = markers.concat( parseTextIntoMarkers(piece, builder) );
}
});
} else if (text.indexOf('*') === -1) {
if (text.length) {
markers.push(builder.marker(text));
}
} else {
} else if (text.indexOf('*') !== -1) {
let markup = builder.markup('b');

let startIndex = text.indexOf('*');
Expand All @@ -133,6 +129,10 @@ function parseTextIntoMarkers(text, builder) {
markers.push(builder.marker(piece, markups));
}
});
} else {
if (text.length) {
markers.push(builder.marker(text));
}
}

return markers;
Expand Down
Loading

0 comments on commit 85d2fef

Please sign in to comment.