Skip to content

Commit

Permalink
Change to use alt on images
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Sep 20, 2023
1 parent ce67c66 commit 0e2c003
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
15 changes: 10 additions & 5 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/**
* @typedef {import('mdast').PhrasingContent} PhrasingContent
* @typedef {import('mdast').Root} Root
*/

Expand Down Expand Up @@ -31,11 +32,15 @@ export default function remarkUnlink() {
node.type === 'imageReference' ||
node.type === 'definition')
) {
parent.children.splice(
index,
1,
...('children' in node ? node.children : [])
)
/** @type {Array<PhrasingContent>} */
const replacement =
'children' in node
? node.children
: 'alt' in node && typeof node.alt === 'string'
? [{type: 'text', value: node.alt}]
: []

parent.children.splice(index, 1, ...replacement)
return index
}
})
Expand Down
2 changes: 2 additions & 0 deletions test/fixtures/document/output.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ Section content may include some links.

## section 2

some images are here also

More content.
1 change: 1 addition & 0 deletions test/fixtures/image-in-link/output.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
image

0 comments on commit 0e2c003

Please sign in to comment.