Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes issue #11 (nested ems) #12

Merged
merged 3 commits into from
Feb 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,12 @@ const rules = {
return htmlTag('a', output(node.content, state), { href: markdown.sanitizeUrl(node.target) }, state);
}
}),
em: markdown.defaultRules.em,
em: Object.assign({ }, markdown.defaultRules.em, {
parse: function(capture, parse, state) {
const parsed = markdown.defaultRules.em.parse(capture, parse, Object.assign({ }, state, { inEmphasis: true }));
return state.inEmphasis ? parsed.content : parsed;
},
}),
strong: markdown.defaultRules.strong,
u: markdown.defaultRules.u,
strike: Object.assign({ }, markdown.defaultRules.del, {
Expand Down Expand Up @@ -298,6 +303,7 @@ function toHTML(source, options) {
const state = {
inline: true,
inQuote: false,
inEmphasis: false,
escapeHTML: options.escapeHTML,
cssModuleNames: options.cssModuleNames || null
};
Expand Down
7 changes: 7 additions & 0 deletions test/oddities.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,10 @@ test('Spoiler edge-cases', () => {
expect(markdown.toHTML('||||||'))
.toBe('<span class="d-spoiler">|</span>|');
});

test('Nested <em>', () => {
expect(markdown.toHTML('_hello world *foo bar* hello world_'))
.toBe('<em>hello world foo bar hello world</em>');
expect(markdown.toHTML('_hello world *foo __blah__ bar* hello world_'))
.toBe('<em>hello world foo <u>blah</u> bar hello world</em>');
});