Skip to content

Commit

Permalink
fix(inline-link-preview): bad handling implementation of tag replacin…
Browse files Browse the repository at this point in the history
…g without the check of nested seek

Signed-off-by: Neko Ayaka <[email protected]>
  • Loading branch information
nekomeowww committed Jul 10, 2024
1 parent 9508c09 commit e11bc00
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ describe('markdown-it', () => {
input: '<a href="foo" class="no-inline-link-preview-b">foo</a>',
expect: expectWrapper('<VPNolebaseInlineLinkPreview href="foo" class="no-inline-link-preview-b">foo</VPNolebaseInlineLinkPreview>'),
},
{
name: 'should render img element',
input: '<a href="/img/es-feature.png" target="_blank"><img src="/img/es-feature.png" /></a>',
expect: expectWrapper('<VPNolebaseInlineLinkPreview href="/img/es-feature.png" target="_blank"><img src="/img/es-feature.png" /></VPNolebaseInlineLinkPreview>'),
},
{
name: 'should not render a element when data-inline-link-preview="false" attribute exist',
input: '<a href="foo" data-inline-link-preview="false">foo</a>',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ export const InlineLinkPreviewElementTransform: PluginWithOptions<{ tag: string
if (/<a.*class="no-inline-link-preview"|".* no-inline-link-preview"|"no-inline-link-preview .*"|".* no-inline-link-preview [^\n\r"\u2028\u2029]*".*>/.test(token.content))
return

if (!transformNextHtmlInlineCloseToken) {
if (!transformNextHtmlInlineCloseToken && /<a/.test(token.content)) {
token.content = token.content.replace(/<a/, `<${tagName}`)
transformNextHtmlInlineCloseToken = true
}
else {
else if (transformNextHtmlInlineCloseToken && /<\/a/.test(token.content)) {
token.content = token.content.replace(/<\/a/, `</${tagName}`)
transformNextHtmlInlineCloseToken = false
}
Expand Down

0 comments on commit e11bc00

Please sign in to comment.