Skip to content

Commit

Permalink
fix(rtl): replace ellipsis span anchor content with bdi (#3123)
Browse files Browse the repository at this point in the history
  • Loading branch information
userquin authored Jan 3, 2025
1 parent e986de7 commit e59f5db
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
36 changes: 30 additions & 6 deletions composables/content-render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,40 @@ export function nodeToVNode(node: Node): VNode | string | null {
}

if ('children' in node) {
if (node.name === 'a' && (node.attributes.href?.startsWith('/') || node.attributes.href?.startsWith('.'))) {
node.attributes.to = node.attributes.href
if (node.name === 'a') {
if (node.attributes.href?.startsWith('/') || node.attributes.href?.startsWith('.')) {
node.attributes.to = node.attributes.href

const { href: _href, target: _target, ...attrs } = node.attributes
return h(
RouterLink as any,
attrs,
() => node.children.map(treeToVNode),
)
}

const { href: _href, target: _target, ...attrs } = node.attributes
// fix #3122
return h(
RouterLink as any,
attrs,
() => node.children.map(treeToVNode),
node.name,
node.attributes,
node.children.map((n: Node) => {
// replace span.ellipsis with bdi.ellipsis inside links
if (n && n.type === ELEMENT_NODE && n.name !== 'bdi' && n.attributes?.class?.includes('ellipsis')) {
const children = n.children.splice(0, n.children.length)
const bdi = {
...n,
name: 'bdi',
children,
} satisfies ElementNode
children.forEach((n: Node) => n.parent = bdi)
return treeToVNode(bdi)
}

return treeToVNode(n)
}),
)
}

return h(
node.name,
node.attributes,
Expand Down
2 changes: 1 addition & 1 deletion tests/nuxt/__snapshots__/content-rich.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ exports[`content-rich > link + mention 1`] = `
rel="nofollow noopener noreferrer"
target="_blank"
><span class="invisible">https://</span
><span class="ellipsis">github.com/ayoayco/astro-react</span
><bdi class="ellipsis">github.com/ayoayco/astro-react</bdi
><span class="invisible">ive-library/pull/203</span></a
>
</p>
Expand Down

0 comments on commit e59f5db

Please sign in to comment.