-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Closed
Labels
L1 - brokenValid usage causes incorrect output OR a crash AND there is no known workaround for the issueValid usage causes incorrect output OR a crash AND there is no known workaround for the issuecategory: inline elements
Description
Describe the bug
The renderer option allows a custom renderer to intercept various markdown elements before the output is written. However, these events do not work correctly for HTML markdown expressions:
If HTML markdown is not immediately preceded by a blank line, then the Renderer.html() event is skipped -- even though the content is ultimately rendered as HTML. This is a bug.
To Reproduce
Example input with CORRECT output:
const marked = require('marked');
class CustomRenderer extends marked.Renderer {
constructor(options) { super(options); }
html(text) {
console.log(`html(): ` + JSON.stringify(text));
return text;
}
text(text) {
console.log(`text(): ` + JSON.stringify(text));
return text;
}
}
const input1 = `
HTML Image:
<img alt="MY IMAGE" src="example.png" />
`;
marked(input1, { renderer: new CustomRenderer() });
// OUTPUT:
//
// text(): "HTML Image:"
// html(): "<img alt=\"MY IMAGE\" src=\"example.png\" />\n"Example input with INCORRECT output:
const marked = require('marked');
class CustomRenderer extends marked.Renderer {
constructor(options) { super(options); }
html(text) {
console.log(`html(): ` + JSON.stringify(text));
return text;
}
text(text) {
console.log(`text(): ` + JSON.stringify(text));
return text;
}
}
// NOTE THERE IS MISSING NEWLINE BEFORE THE <IMG> TAG:
const input2 = `
HTML Image:
<img alt="MY IMAGE" src="example.png" />
`;
marked(input2, { renderer: new CustomRenderer() });
// OUTPUT:
//
// text(): "HTML Image:\n"Expected behavior
The Renderer.html() event SHOULD be invoked for both of the above inputs. The newline should not matter, because the markup is rendered as HTML either way.
styfle
Metadata
Metadata
Assignees
Labels
L1 - brokenValid usage causes incorrect output OR a crash AND there is no known workaround for the issueValid usage causes incorrect output OR a crash AND there is no known workaround for the issuecategory: inline elements