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

v11.0.0. yields "Uncaught Error: renderer 'options' does not exist" in code that worked in versions up to v10.0.0 #3117

Closed
teehemkay opened this issue Dec 3, 2023 · 3 comments · Fixed by #3118
Labels
L2 - annoying Similar to L1 - broken but there is a known workaround available for the issue

Comments

@teehemkay
Copy link

Marked version:

11.0.0

Describe the bug

The following code that overrides the link renderer with a version that force opening external links in another window, which worked before v11.0.0. now yield a the following error message Uncaught Error: renderer 'options' does not exist

// from https://github.com/markedjs/marked/issues/655#issuecomment-712380889
const renderer = new marked.Renderer();
const linkRenderer = renderer.link;
renderer.link = (href, title, text) => {
  const html = linkRenderer.call(renderer, href, title, text);
  return href.startsWith('/')
    ? html
    : html.replace(
        /^<a /,
        `<a target="_blank" rel="noreferrer noopener nofollow" `
      );
};

marked.use({ renderer });

To Reproduce
Steps to reproduce the behavior:

Customize marked with the above link renderer

Expected behavior

The the custom link renderer works without yielding an error

@teehemkay teehemkay changed the title v11.0.0. yields "Uncaught Error: renderer 'options' does not exist" in code that worked versions up to v10.0.0 v11.0.0. yields "Uncaught Error: renderer 'options' does not exist" in code that worked in versions up to v10.0.0 Dec 3, 2023
@UziTech
Copy link
Member

UziTech commented Dec 3, 2023

Yes that is because marked.use({ renderer }); is supposed to be an object with the renderer methods not a renderer class. If you change it to the following it should work.

// from https://github.com/markedjs/marked/issues/655#issuecomment-712380889
const markedRenderer = new marked.Renderer();
const linkRenderer = markedRenderer.link;
const renderer = {
  link(href, title, text) {
    const html = linkRenderer.call(this, href, title, text);
    return href.startsWith('/')
      ? html
      : html.replace(
        /^<a /,
        '<a target="_blank" rel="noreferrer noopener nofollow" '
      );
  }
};

marked.use({ renderer });

This is something that was only enforced in typescript until v11. Maybe we should ignore the options property instead of throw an error.

@UziTech UziTech added the L2 - annoying Similar to L1 - broken but there is a known workaround available for the issue label Dec 3, 2023
@UziTech
Copy link
Member

UziTech commented Dec 3, 2023

I created a fix (#3118) to skip the properties instead of throwing an error if the class is used.

@teehemkay
Copy link
Author

Thanks a LOT for the explanation and quick fix.
I really appreciate it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
L2 - annoying Similar to L1 - broken but there is a known workaround available for the issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants