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

How to override render method of <img> #774

Closed
poberwong opened this issue Jul 26, 2016 · 4 comments
Closed

How to override render method of <img> #774

poberwong opened this issue Jul 26, 2016 · 4 comments

Comments

@poberwong
Copy link

I want to override method of <img>, However, I find that <img> is not recognized as html.
the following method is which I override:

Renderer.prototype.html = function(html) {
  return html;
};

so, which part should be override ?

@joshbruce
Copy link
Member

#989

@fxha
Copy link

fxha commented Mar 12, 2019

I think I have a similar issue with img tags because inline img tags are not recognized as HTML nor image. Is this the expected behavior?

Example:

1. Block <img> tag is recognized as HTML.

foo

<img src="./img1.png">

bar

2. Inline <img> tag is not recognized as HTML and also not as image but ![]() is recognized as image.

foo

foo ![img1](./img1.png) bar <img src="./img1.png"> foobar

bar

@UziTech
Copy link
Member

UziTech commented Mar 12, 2019

@fxha Inline HTML is just plain text according to the commonmark spec so the only way to modify it would be to search for it before passing the string to marked.

const md = `foo

foo ![img1](./img1.png) bar <img src="./img1.png"> foobar

bar`;

md.replace(/<img .*?>/, 'Something else');

marked(md);

@styfle
Copy link
Member

styfle commented Mar 12, 2019

Depending on your use case, you might want to filter out all images by using an allow-list of html tags

See this comment
#1388 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants