Skip to content

Commit

Permalink
fix #213
Browse files Browse the repository at this point in the history
  • Loading branch information
quantizor committed Oct 21, 2018
1 parent a15f3ca commit 6f83e23
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
coverage/**
docs/**
dist/**
**/*.spec.js
17 changes: 17 additions & 0 deletions index.compiler.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2471,6 +2471,23 @@ fun main() {
</p>
</div>
`);
});

it('does not consume trailing whitespace if there is no newline', () => {
const Foo = () => <span>Hello</span>;

render(compiler('<Foo/> World!', { overrides: { Foo } }));

expect(root.innerHTML).toMatchInlineSnapshot(`
<span data-reactroot>
<span>
Hello
</span>
World!
</span>
`);
});
});
Expand Down
15 changes: 8 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ const HTML_COMMENT_R = /^<!--.*?-->/;
*/
const HTML_CUSTOM_ATTR_R = /^(data|aria|x)-[a-z_][a-z\d_.-]*$/;

const HTML_SELF_CLOSING_ELEMENT_R = /^ *<([A-Za-z][\w:]*)(?:\s+((?:<.*?>|[^>])*))?>(?!<\/\1>)\s*/;
const HTML_SELF_CLOSING_ELEMENT_R = /^ *<([a-z][a-z0-9:]*)(?:\s+((?:<.*?>|[^>])*))?\/?>(?!<\/\1>)(\s*\n)?/i;
const INTERPOLATION_R = /^\{.*\}$/;
const LINK_AUTOLINK_BARE_URL_R = /^(https?:\/\/[^\s<]+[^<.,:;"')\]\s])/;
const LINK_AUTOLINK_MAILTO_R = /^<([^ >]+@[^ >]+)>/;
Expand Down Expand Up @@ -1436,12 +1436,13 @@ export function compiler(markdown, options) {
order: PARSE_PRIORITY_MIN,
parse(capture /*, parse, state*/) {
return {
// nbsp -> unicode equivalent for named chars
content: capture[0].replace(HTML_CHAR_CODE_R, (full, inner) => {
return namedCodesToUnicode[inner]
? namedCodesToUnicode[inner]
: full;
}),
content: capture[0]
// nbsp -> unicode equivalent for named chars
.replace(HTML_CHAR_CODE_R, (full, inner) => {
return namedCodesToUnicode[inner]
? namedCodesToUnicode[inner]
: full;
}),
};
},
react(node /*, output, state*/) {
Expand Down

0 comments on commit 6f83e23

Please sign in to comment.