| |
| |
| export default function remarkUnwrapCitationLinks() { |
| return (tree) => { |
| |
| const getTextContent = (node) => { |
| if (!node) return ''; |
| if (node.type === 'text') return node.value || ''; |
| if (Array.isArray(node.children)) { |
| return node.children.map(getTextContent).join(''); |
| } |
| return ''; |
| }; |
|
|
| const visit = (node, parent) => { |
| if (!node || typeof node !== 'object') return; |
|
|
| |
| const children = Array.isArray(node.children) ? node.children : []; |
| for (let i = 0; i < children.length; i++) { |
| const child = children[i]; |
| visit(child, node); |
| } |
|
|
| |
| if (node.type === 'link' && parent && Array.isArray(parent.children)) { |
| |
| const textContent = getTextContent(node); |
|
|
| |
| console.log('🔍 Link trouvé:', { |
| text: textContent, |
| url: node.url, |
| matches: /^@\w+/.test(textContent.trim()) |
| }); |
|
|
| |
| if (textContent && /^@\w+/.test(textContent.trim())) { |
| |
| const index = parent.children.indexOf(node); |
|
|
| if (index !== -1) { |
| console.log('✅ Transformation:', textContent); |
| |
| parent.children[index] = { |
| type: 'text', |
| value: textContent.trim() |
| }; |
| } |
| } |
| } |
| }; |
|
|
| visit(tree, null); |
| }; |
| } |
|
|
|
|