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

Renderer.html() is not invoked if HTML is not preceded by a newline #1601

Closed
octogonz opened this issue Feb 12, 2020 · 2 comments · Fixed by #1602, #1616, qubyte/qubyte-codes#212, geraintwhite/markdown-templator#17 or qubyte/qubyte-codes#214
Labels
category: inline elements L1 - broken Valid usage causes incorrect output OR a crash AND there is no known workaround for the issue

Comments

@octogonz
Copy link
Contributor

octogonz commented Feb 12, 2020

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.

@UziTech UziTech added category: inline elements L1 - broken Valid usage causes incorrect output OR a crash AND there is no known workaround for the issue labels Feb 12, 2020
@UziTech
Copy link
Member

UziTech commented Feb 12, 2020

Thank you for reporting this. It should be fixed in #1602

@octogonz
Copy link
Contributor Author

Awesome, thanks very much! 😁

@UziTech UziTech mentioned this issue Mar 6, 2020
12 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment