From 3a0704853390f923b2590f3494b561132dbebb6e Mon Sep 17 00:00:00 2001 From: Brad Veryard Date: Mon, 30 May 2022 04:50:47 -0400 Subject: [PATCH] fix: missing alt attribute on images even if provided (#679) (#685) close #679 Co-authored-by: Divyansh Singh <40380293+brc-dd@users.noreply.github.com> --- src/node/markdown/plugins/image.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/node/markdown/plugins/image.ts b/src/node/markdown/plugins/image.ts index 641a04c7..59dadcc1 100644 --- a/src/node/markdown/plugins/image.ts +++ b/src/node/markdown/plugins/image.ts @@ -10,6 +10,15 @@ export const imagePlugin = (md: MarkdownIt) => { if (url && !EXTERNAL_URL_RE.test(url) && !/^\.?\//.test(url)) { token.attrSet('src', './' + url) } + + if (token.attrIndex('alt') && token.children != null) { + token.attrs![token.attrIndex('alt')][1] = self.renderInlineAsText( + token.children, + options, + env + ) + } + return self.renderToken(tokens, idx, options) } }