Skip to content

Commit

Permalink
refactor: refactor label in fn
Browse files Browse the repository at this point in the history
Moves label logic from label.js to fn.js

- fn.js
  - add label creation logic from label.js
- label.js
  - remove fn handling

Part of #452
  • Loading branch information
pkra committed Aug 13, 2024
1 parent fe5bde5 commit 40f8899
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
12 changes: 11 additions & 1 deletion lib/elements/fn.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,22 @@ const getElementToInsertAfter = maybeBadAncestor => (maybeBadAncestor.nextElemen
*/
export default function (htmlParentNode, xmlnode) {
if (xmlnode.closest('tex-math')) xmlnode.remove();
const div = this.createNode('div', '', { role: 'doc-footnote', 'aria-label': `Footnote ${xmlnode.querySelector('label').textContent}` });
const label = xmlnode.querySelector('label');
const div = this.createNode('div', '', { role: 'doc-footnote', 'aria-label': `Footnote ${label.textContent}` });
// NOTE AmerMathSoc/texml-to-html#336 analyzed where fn occurs in publications; might need revisions
// Essentially, we can assume fn occurs inside elements (that turn into) p, h1, and span (from formula markup)
// Since a span ancestor can be inside p (e.g., from inline-formula) we check for the others first.
const maybeBadAncestor = htmlParentNode.closest('p, h1') || htmlParentNode.closest('span');
maybeBadAncestor ? getElementToInsertAfter(maybeBadAncestor).insertAdjacentElement('afterend', div) : htmlParentNode.appendChild(div);
mapAttributes(div, xmlnode);
// label
const span = this.createNode('span', '<sup></sup>', {
'data-ams-doc': 'label'
});
div.appendChild(span);
const superscript = span.firstElementChild;
this.passThrough(superscript, label);
label.remove(); //NOTE: prevent duplicate processing later on

this.passThrough(div, xmlnode);
};
11 changes: 0 additions & 11 deletions lib/elements/label.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,6 @@ import getParentLevel from '../helpers/getParentLevel.js';
* @param {Element} xmlnode
*/
export default function (htmlParentNode, xmlnode) {
// simple cases
// CASE fn
if (xmlnode.parentNode.tagName === 'fn') {
const span = this.createNode('span', '<sup></sup>', {
'data-ams-doc': 'label'
});
htmlParentNode.appendChild(span);
const superscript = span.firstElementChild;
this.passThrough(superscript, xmlnode);
return;
}
// CASE label followed by a title -- we skip (and pull in the label later on when processing title)
if (xmlnode.nextElementSibling?.tagName === 'title') return;
// CASE empty label
Expand Down

0 comments on commit 40f8899

Please sign in to comment.