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 (#478)

Fixes #333
  • Loading branch information
bantic committed Aug 30, 2016
1 parent 6969f5c commit 6036b90
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 @@ -167,7 +173,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 6036b90

Please sign in to comment.