Skip to content

Commit 6e9acc4

Browse files
committed
footnotes
1 parent 117a00d commit 6e9acc4

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/generators/jsx-ast/utils/transformer.mjs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,23 @@ import { TAG_TRANSFORMS } from '../constants.mjs';
99
*/
1010
const transformer = tree => {
1111
visit(tree, 'element', node => {
12-
node.tagName =
13-
node.tagName in TAG_TRANSFORMS
14-
? TAG_TRANSFORMS[node.tagName]
15-
: node.tagName;
12+
node.tagName = TAG_TRANSFORMS[node.tagName] || node.tagName;
1613
});
14+
15+
// Are there footnotes?
16+
if (tree.children.at(-1).tagName === 'section') {
17+
const section = tree.children.pop();
18+
// If so, move it into the proper location
19+
// Root -> Article -> Main content
20+
tree.children[2]?.children[1]?.children[0]?.children?.push(
21+
...section.children
22+
);
23+
}
1724
};
1825

1926
/**
2027
* Transforms elements in a syntax tree by replacing tag names according to the mapping.
28+
*
29+
* Also moves any generated root section into its proper location in the AST.
2130
*/
2231
export default () => transformer;

0 commit comments

Comments
 (0)