@amermathsoc/texml-to-html 15.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1414 -0
- package/LICENSE +202 -0
- package/NOTICE +5 -0
- package/README.md +16 -0
- package/examples/cli.js +6 -0
- package/ldom.js +6 -0
- package/lib/doms.js +30 -0
- package/lib/elements/abstract.js +34 -0
- package/lib/elements/algorithm.js +78 -0
- package/lib/elements/app.js +35 -0
- package/lib/elements/article-metadata-json.js +167 -0
- package/lib/elements/article-title.js +26 -0
- package/lib/elements/article.js +28 -0
- package/lib/elements/attrib.js +41 -0
- package/lib/elements/bold.js +32 -0
- package/lib/elements/book-meta-json.js +134 -0
- package/lib/elements/book-meta.js +33 -0
- package/lib/elements/book-title.js +26 -0
- package/lib/elements/boxed-text.js +31 -0
- package/lib/elements/break.js +25 -0
- package/lib/elements/caption.js +52 -0
- package/lib/elements/compound-kwd.js +27 -0
- package/lib/elements/def-item.js +26 -0
- package/lib/elements/def-list.js +30 -0
- package/lib/elements/def.js +29 -0
- package/lib/elements/disp-formula-group.js +30 -0
- package/lib/elements/disp-quote.js +33 -0
- package/lib/elements/email.js +28 -0
- package/lib/elements/ext-link.js +38 -0
- package/lib/elements/fig.js +32 -0
- package/lib/elements/fn.js +42 -0
- package/lib/elements/formula.js +51 -0
- package/lib/elements/front.js +64 -0
- package/lib/elements/funding-group.js +26 -0
- package/lib/elements/graphic.js +49 -0
- package/lib/elements/img.js +28 -0
- package/lib/elements/italic.js +33 -0
- package/lib/elements/kwd-group.js +29 -0
- package/lib/elements/kwd.js +26 -0
- package/lib/elements/label.js +101 -0
- package/lib/elements/line.js +31 -0
- package/lib/elements/meta-name.js +29 -0
- package/lib/elements/meta-value.js +27 -0
- package/lib/elements/mixed-citation.js +35 -0
- package/lib/elements/monospace.js +35 -0
- package/lib/elements/notes.js +36 -0
- package/lib/elements/p.js +29 -0
- package/lib/elements/preface.js +33 -0
- package/lib/elements/ref-list.js +50 -0
- package/lib/elements/ref.js +28 -0
- package/lib/elements/roman.js +34 -0
- package/lib/elements/sans-serif.js +34 -0
- package/lib/elements/sc.js +35 -0
- package/lib/elements/sec-meta.js +35 -0
- package/lib/elements/sec.js +89 -0
- package/lib/elements/secheading.js +43 -0
- package/lib/elements/simpletabbing.js +29 -0
- package/lib/elements/statement.js +31 -0
- package/lib/elements/string-name.js +28 -0
- package/lib/elements/styled-content.js +32 -0
- package/lib/elements/subj-group.js +29 -0
- package/lib/elements/subject.js +26 -0
- package/lib/elements/subtitle.js +29 -0
- package/lib/elements/table.js +28 -0
- package/lib/elements/tag.js +50 -0
- package/lib/elements/target.js +39 -0
- package/lib/elements/term.js +31 -0
- package/lib/elements/tex-math.js +34 -0
- package/lib/elements/text.js +29 -0
- package/lib/elements/toc-entry.js +63 -0
- package/lib/elements/toc.js +35 -0
- package/lib/elements/underline.js +26 -0
- package/lib/elements/x.js +27 -0
- package/lib/elements/xref-group.js +36 -0
- package/lib/elements/xref.js +89 -0
- package/lib/hacks.js +43 -0
- package/lib/head.js +38 -0
- package/lib/helpers/copyElement.js +29 -0
- package/lib/helpers/extractContribGroups.js +94 -0
- package/lib/helpers/generateByline.js +35 -0
- package/lib/helpers/getParentLevel.js +24 -0
- package/lib/helpers/helpers-tex.js +54 -0
- package/lib/helpers/mapAttributes.js +54 -0
- package/lib/helpers/mapColorAttributes.js +36 -0
- package/lib/helpers/unnest.js +34 -0
- package/lib/transformer.js +311 -0
- package/out.html +550 -0
- package/package.json +39 -0
- package/test/article--alttitle.xml +146 -0
- package/test/article--nometa.xml +40 -0
- package/test/article-alttitle-meta-snapshot.json +94 -0
- package/test/article-meta-snapshot.json +129 -0
- package/test/article-nometa-meta-snapshot.json +46 -0
- package/test/article.xml +593 -0
- package/test/attribute-content-type.js +26 -0
- package/test/attribute-has-qed-box.js +28 -0
- package/test/attribute-hidden.js +27 -0
- package/test/attribute-rowspan-colspan.js +27 -0
- package/test/attribute-specific-use.js +27 -0
- package/test/attribute-style.js +27 -0
- package/test/book-meta-snapshot.json +78 -0
- package/test/book.xml +292 -0
- package/test/copyElement.js +38 -0
- package/test/element-abstract-title.js +27 -0
- package/test/element-algorithm.js +56 -0
- package/test/element-article.js +24 -0
- package/test/element-attrib.js +27 -0
- package/test/element-back-app-group-app.js +28 -0
- package/test/element-bold.js +26 -0
- package/test/element-book-meta.js +37 -0
- package/test/element-book-preface.js +29 -0
- package/test/element-book-ref-list.js +32 -0
- package/test/element-book.js +33 -0
- package/test/element-boxed-text.js +28 -0
- package/test/element-break.js +27 -0
- package/test/element-citegroup.js +25 -0
- package/test/element-compound-kwd.js +24 -0
- package/test/element-def-list-def-item-def-term.js +43 -0
- package/test/element-disp-formula-group.js +27 -0
- package/test/element-disp-quote.js +31 -0
- package/test/element-email.js +26 -0
- package/test/element-ext-link.js +30 -0
- package/test/element-fig-subfig-label.js +38 -0
- package/test/element-fn.js +40 -0
- package/test/element-front.js +45 -0
- package/test/element-funding-group.js +29 -0
- package/test/element-graphic-inline-graphic.js +40 -0
- package/test/element-img.js +30 -0
- package/test/element-inline-formula-disp-formula-tex-math.js +91 -0
- package/test/element-italic.js +28 -0
- package/test/element-kwd-group.js +28 -0
- package/test/element-kwd.js +27 -0
- package/test/element-mixed-citation.js +32 -0
- package/test/element-monospace.js +27 -0
- package/test/element-notes.js +42 -0
- package/test/element-p-p.js +27 -0
- package/test/element-ref-list-ref-label.js +40 -0
- package/test/element-roman.js +27 -0
- package/test/element-sans-serif.js +27 -0
- package/test/element-sc.js +27 -0
- package/test/element-sec-app-front-matter-part-dedication-title-label.js +87 -0
- package/test/element-sec-meta.js +43 -0
- package/test/element-secheading.js +28 -0
- package/test/element-simpletabbing-line.js +31 -0
- package/test/element-statement-label-title.js +120 -0
- package/test/element-string-name.js +27 -0
- package/test/element-stripEmptyLabel.js +26 -0
- package/test/element-styled-content.js +28 -0
- package/test/element-subtitle.js +36 -0
- package/test/element-table-wrap-group.js +30 -0
- package/test/element-table-wrap.js +51 -0
- package/test/element-table.js +34 -0
- package/test/element-tag.js +38 -0
- package/test/element-target.js +33 -0
- package/test/element-toc-toc-entry.js +77 -0
- package/test/element-underline.js +27 -0
- package/test/element-verse-group.js +28 -0
- package/test/element-x.js +30 -0
- package/test/element-xref-group.js +26 -0
- package/test/element-xref.js +32 -0
- package/test/hacks.js +37 -0
- package/test/helper-mapColorAttributes.js +27 -0
- package/test/helper.js +26 -0
- package/test/setHead.js +32 -0
- package/test/unit/abstract.js +35 -0
- package/texml-to-html.js +32 -0
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) 2023 American Mathematical Society
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { node2macro, } from '../helpers/helpers-tex.js';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* tag element
|
|
21
|
+
* @param {HTMLElement} htmlParentNode
|
|
22
|
+
* @param {Element} xmlnode
|
|
23
|
+
*/
|
|
24
|
+
export default function (htmlParentNode, xmlnode) {
|
|
25
|
+
// usually, tag appears inside tex-math
|
|
26
|
+
if (xmlnode.closest('tex-math')) {
|
|
27
|
+
// rewrite to macro
|
|
28
|
+
const macroName = (xmlnode.getAttribute('parens') === 'yes') ? 'tag' : 'tag*';
|
|
29
|
+
node2macro.apply(this, [htmlParentNode, xmlnode, macroName]);
|
|
30
|
+
|
|
31
|
+
// tag extraction
|
|
32
|
+
// if some tag in the equation is linked, we store all tags as part of a JSON array in the data-ams-tag attribute on the HTML parent
|
|
33
|
+
if (!xmlnode.closest('disp-formula').querySelector('target tag')) return;
|
|
34
|
+
const tagArray = htmlParentNode.hasAttribute('data-ams-tags') ? JSON.parse(htmlParentNode.getAttribute('data-ams-tags')) : [];
|
|
35
|
+
tagArray.push(this.passthroughIntoHTMLString(xmlnode)); // NOTE we only need passThroughIntoHTMLString here, i.e., we don't need to escape active TeX characters, because node2macro already ran and modified xmlnode
|
|
36
|
+
htmlParentNode.setAttribute('data-ams-tags', JSON.stringify(tagArray));
|
|
37
|
+
}
|
|
38
|
+
// rarely, it appears in "text equations" (cf. formula.js, target.js)
|
|
39
|
+
else if (xmlnode.closest('disp-formula[content-type="text"]')) {
|
|
40
|
+
const span = this.createNode('span', '', { 'data-ams-doc': 'label', id: xmlnode.parentNode.id }); // NOTE: tag should always have a <target> parent with an ID.
|
|
41
|
+
if (xmlnode.getAttribute('parens') === 'yes') span.insertAdjacentText('afterbegin', '(')
|
|
42
|
+
this.passThrough(span, xmlnode);
|
|
43
|
+
if (xmlnode.getAttribute('parens') === 'yes') span.insertAdjacentText('beforeend', ')')
|
|
44
|
+
htmlParentNode.prepend(span);
|
|
45
|
+
}
|
|
46
|
+
// tag extraction
|
|
47
|
+
// if some tag in the equation is linked, we store all tags in a special element in the HTML parent
|
|
48
|
+
const tagsElement = htmlParentNode.closest('[data-ams-doc~="math"]').firstElementChild;
|
|
49
|
+
if (tagsElement?.getAttribute('data-ams-doc') === 'tags') tagsElement.insertAdjacentHTML('beforeend', `<span>${this.passthroughIntoHTMLString(xmlnode.cloneNode(true))}</span>`);
|
|
50
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) 2023 American Mathematical Society
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import mapAttributes from '../helpers/mapAttributes.js';
|
|
18
|
+
import { node2macro } from '../helpers/helpers-tex.js';
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* target element
|
|
22
|
+
* @param {HTMLElement} htmlParentNode
|
|
23
|
+
* @param {Element} xmlnode
|
|
24
|
+
*/
|
|
25
|
+
export default function (htmlParentNode, xmlnode) {
|
|
26
|
+
if (xmlnode.closest('tex-math')) {
|
|
27
|
+
node2macro.apply(this, [htmlParentNode, xmlnode, `cssId{${xmlnode.id}}`, false]);
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
// NOTE: inside a "text equation" we pass it through; the tag child will pick up the ID.
|
|
31
|
+
if (xmlnode.parentNode.tagName === 'disp-formula' && xmlnode.parentNode.getAttribute('content-type') === 'text') {
|
|
32
|
+
this.passThrough(htmlParentNode, xmlnode);
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
const span = this.createNode('span');
|
|
36
|
+
htmlParentNode.appendChild(span);
|
|
37
|
+
mapAttributes(span, xmlnode);
|
|
38
|
+
this.passThrough(span, xmlnode);
|
|
39
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) 2023 American Mathematical Society
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import mapAttributes from '../helpers/mapAttributes.js';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* term element
|
|
21
|
+
* @param {HTMLElement} htmlParentNode
|
|
22
|
+
* @param {Element} xmlnode
|
|
23
|
+
*/
|
|
24
|
+
export default function (htmlParentNode, xmlnode) {
|
|
25
|
+
const dt = this.createNode('dt');
|
|
26
|
+
mapAttributes(dt, xmlnode);
|
|
27
|
+
// NOTE DT gets id from def-item; cf. def-item.js
|
|
28
|
+
dt.setAttribute('id', xmlnode.parentNode.id);
|
|
29
|
+
htmlParentNode.appendChild(dt);
|
|
30
|
+
this.passThrough(dt, xmlnode);
|
|
31
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) 2023 American Mathematical Society
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* tex-math element
|
|
19
|
+
* @param {HTMLElement} htmlParentNode
|
|
20
|
+
* @param {Element} xmlnode
|
|
21
|
+
*/
|
|
22
|
+
export default function (htmlParentNode, xmlnode) {
|
|
23
|
+
// nested tex-math: unwrapped but with $...$
|
|
24
|
+
if (xmlnode.parentNode.closest('tex-math')) {
|
|
25
|
+
htmlParentNode.insertAdjacentText('beforeend', '$');
|
|
26
|
+
this.passThrough(htmlParentNode, xmlnode);
|
|
27
|
+
htmlParentNode.insertAdjacentText('beforeend', '$');
|
|
28
|
+
return; // NOTE should only occur in implicit text mode (\tag{} // <tag /> etc) or within <text> elements (which are not JATS/BITS and thus occur nowhere else)
|
|
29
|
+
}
|
|
30
|
+
// Otherwise we copy and pass-through
|
|
31
|
+
const element = this.createNode('tex-math');
|
|
32
|
+
htmlParentNode.appendChild(element);
|
|
33
|
+
this.passThrough(element, xmlnode);
|
|
34
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) 2023 American Mathematical Society
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { node2macro } from '../helpers/helpers-tex.js';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* text element
|
|
21
|
+
* @param {HTMLElement} htmlParentNode
|
|
22
|
+
* @param {Element} xmlnode
|
|
23
|
+
*/
|
|
24
|
+
export default function (htmlParentNode, xmlnode) {
|
|
25
|
+
// NOTE currently no else as <text> only appears in <tex-math>
|
|
26
|
+
if (xmlnode.closest('tex-math')) {
|
|
27
|
+
node2macro.apply(this, [htmlParentNode, xmlnode, 'text', true]);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) 2023 American Mathematical Society
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* toc-entry element
|
|
19
|
+
* @param {HTMLElement} htmlParentNode
|
|
20
|
+
* @param {Element} xmlnode
|
|
21
|
+
*/
|
|
22
|
+
export default function (htmlParentNode, xmlnode) {
|
|
23
|
+
const li = this.createNode('li');
|
|
24
|
+
htmlParentNode.appendChild(li);
|
|
25
|
+
const anchor = this.createNode('a', '', {
|
|
26
|
+
href: `#${xmlnode.querySelector('nav-pointer').getAttribute('rid')}`,
|
|
27
|
+
});
|
|
28
|
+
li.appendChild(anchor);
|
|
29
|
+
// NOTE unify label/title processing with label() - requires some form of new wrapper around content in lieu of heading (or have it add the anchor but then the nav-pointer will be odd to pull in). See #398
|
|
30
|
+
// NOTE [...].find() HACK for bug with ':scope > ...', jsdom/jsdom#2998
|
|
31
|
+
const label = xmlnode.querySelector(':scope>label');
|
|
32
|
+
const title = xmlnode.querySelector(':scope>title');
|
|
33
|
+
const altTitle = xmlnode.querySelector(':scope>alt-title');
|
|
34
|
+
if (label && label.innerHTML.trim() !== '') {
|
|
35
|
+
this.passThrough(anchor, label);
|
|
36
|
+
anchor.insertAdjacentText('beforeend', '. ');
|
|
37
|
+
}
|
|
38
|
+
if (altTitle) {
|
|
39
|
+
const altTitleContent = altTitle.textContent;
|
|
40
|
+
anchor.setAttribute(
|
|
41
|
+
'data-ams-doc-alttitle',
|
|
42
|
+
anchor.textContent + altTitleContent
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
if (title) this.passThrough(anchor, title);
|
|
46
|
+
// NOTE we expect very simple markup: one contrib group, string-names only
|
|
47
|
+
const contribGroup = xmlnode.querySelector(':scope>contrib-group');
|
|
48
|
+
if (contribGroup) {
|
|
49
|
+
const names = [...contribGroup.querySelectorAll('string-name')];
|
|
50
|
+
if (names.length > 0) li.insertAdjacentHTML('beforeend', '<br>');
|
|
51
|
+
li.insertAdjacentHTML(
|
|
52
|
+
'beforeend',
|
|
53
|
+
names.map((node) => `<em>${node.textContent}</em>`).join(', ')
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
if (!xmlnode.querySelector('toc-entry')) return;
|
|
57
|
+
// nested toc-entries means we have a sub-toc
|
|
58
|
+
const ol = this.createNode('ol');
|
|
59
|
+
li.appendChild(ol);
|
|
60
|
+
[...xmlnode.childNodes]
|
|
61
|
+
.filter((node) => node.tagName === 'toc-entry')
|
|
62
|
+
.forEach(this.recurseTheDom.bind(null, ol));
|
|
63
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) 2023 American Mathematical Society
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* toc element
|
|
19
|
+
* @param {HTMLElement} htmlParentNode
|
|
20
|
+
* @param {Element} xmlnode
|
|
21
|
+
*/
|
|
22
|
+
export default function (htmlParentNode, xmlnode) {
|
|
23
|
+
const nav = this.createNode('nav', '', {
|
|
24
|
+
role: 'doc-toc',
|
|
25
|
+
'data-ams-doc-level': '0',
|
|
26
|
+
id: xmlnode.id,
|
|
27
|
+
});
|
|
28
|
+
htmlParentNode.appendChild(nav);
|
|
29
|
+
this.recurseTheDom(nav, xmlnode.querySelector('title-group'));
|
|
30
|
+
const ol = this.createNode('ol');
|
|
31
|
+
nav.appendChild(ol);
|
|
32
|
+
[...xmlnode.childNodes]
|
|
33
|
+
.filter((node) => node.tagName === 'toc-entry')
|
|
34
|
+
.forEach(this.recurseTheDom.bind(null, ol));
|
|
35
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) 2023 American Mathematical Society
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* underline element
|
|
19
|
+
* @param {HTMLElement} htmlParentNode
|
|
20
|
+
* @param {Element} xmlnode
|
|
21
|
+
*/
|
|
22
|
+
export default function (htmlParentNode, xmlnode) {
|
|
23
|
+
const node = this.createNode('u');
|
|
24
|
+
htmlParentNode.appendChild(node);
|
|
25
|
+
this.passThrough(node, xmlnode);
|
|
26
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) 2023 American Mathematical Society
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* x element
|
|
19
|
+
* @param {HTMLElement} htmlParentNode
|
|
20
|
+
* @param {Element} xmlnode
|
|
21
|
+
*/
|
|
22
|
+
export default function (htmlParentNode, xmlnode) {
|
|
23
|
+
// ignore if not xref/x or isBook
|
|
24
|
+
if ('xref' !== xmlnode.parentNode.tagName && xmlnode.closest('article'))
|
|
25
|
+
return;
|
|
26
|
+
this.passThrough(htmlParentNode, xmlnode);
|
|
27
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) 2023 American Mathematical Society
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* xref-group element
|
|
19
|
+
* @param {HTMLElement} htmlParentNode
|
|
20
|
+
* @param {Element} xmlnode
|
|
21
|
+
*/
|
|
22
|
+
export default function (htmlParentNode, xmlnode) {
|
|
23
|
+
const refType = xmlnode.getAttribute('ref-type');
|
|
24
|
+
const refrange = xmlnode.getAttribute('middle');
|
|
25
|
+
if (xmlnode.parentNode.closest('tex-math')) {
|
|
26
|
+
// NOTE: no use case so far; cf. #428 for code example
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
const span = this.createNode('span', '', {
|
|
30
|
+
'data-ams-doc': 'refgroup',
|
|
31
|
+
'data-ams-ref': refType,
|
|
32
|
+
'data-ams-refrange': refrange
|
|
33
|
+
});
|
|
34
|
+
htmlParentNode.appendChild(span);
|
|
35
|
+
this.passThrough(span, xmlnode);
|
|
36
|
+
};
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) 2023 American Mathematical Society
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { unnestLinks } from '../helpers/unnest.js';
|
|
18
|
+
import { replaceTeXCharactersInNodes } from '../helpers/helpers-tex.js';
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* xref element
|
|
22
|
+
* @param {HTMLElement} htmlParentNode
|
|
23
|
+
* @param {Element} xmlnode
|
|
24
|
+
*/
|
|
25
|
+
export default function (htmlParentNode, xmlnode) {
|
|
26
|
+
// case toc-entry//xref
|
|
27
|
+
const tocEntryAncestor = xmlnode.closest('toc-entry');
|
|
28
|
+
if (tocEntryAncestor) {
|
|
29
|
+
this.passThrough(htmlParentNode, xmlnode);
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
const refType = xmlnode.getAttribute('ref-type');
|
|
33
|
+
const isFootnoteRef = refType === 'fn';
|
|
34
|
+
// case tex-math/xref, tex-math/text/xref (with a check for footnotes in tex-math)
|
|
35
|
+
const texmathAncestor = xmlnode.closest('tex-math');
|
|
36
|
+
const foonoteAncestor = xmlnode.closest('fn');
|
|
37
|
+
if (
|
|
38
|
+
texmathAncestor &&
|
|
39
|
+
!(
|
|
40
|
+
foonoteAncestor &&
|
|
41
|
+
[...texmathAncestor.querySelectorAll('*')].includes(foonoteAncestor)
|
|
42
|
+
)
|
|
43
|
+
) {
|
|
44
|
+
const rid = xmlnode.getAttribute('rid');
|
|
45
|
+
htmlParentNode.insertAdjacentText(
|
|
46
|
+
'beforeend',
|
|
47
|
+
`\\xhref[${refType}]{#${rid}}{`
|
|
48
|
+
);
|
|
49
|
+
if (isFootnoteRef) htmlParentNode.insertAdjacentText('beforeend', `{}^{`);
|
|
50
|
+
replaceTeXCharactersInNodes(xmlnode);
|
|
51
|
+
this.passThrough(htmlParentNode, xmlnode);
|
|
52
|
+
if (isFootnoteRef) htmlParentNode.insertAdjacentText('beforeend', `}`);
|
|
53
|
+
htmlParentNode.insertAdjacentText('beforeend', `}`);
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
const rid = xmlnode.getAttribute('rid');
|
|
57
|
+
if (!rid) {
|
|
58
|
+
const span = this.createNode('span', '', {
|
|
59
|
+
'data-ams-ref': 'notrid'
|
|
60
|
+
});
|
|
61
|
+
htmlParentNode.appendChild(span);
|
|
62
|
+
this.passThrough(span, xmlnode);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
const anchor = this.createNode('a', '', {
|
|
66
|
+
href: `#${rid}`,
|
|
67
|
+
'data-ams-ref': refType
|
|
68
|
+
});
|
|
69
|
+
const typeToRole = {
|
|
70
|
+
fn: 'doc-noteref',
|
|
71
|
+
bibr: 'doc-biblioref'
|
|
72
|
+
};
|
|
73
|
+
if (typeToRole[refType]) anchor.setAttribute('role', typeToRole[refType]);
|
|
74
|
+
if (refType === 'bibr') {
|
|
75
|
+
const cite = this.createNode('cite');
|
|
76
|
+
cite.appendChild(anchor);
|
|
77
|
+
htmlParentNode.appendChild(cite);
|
|
78
|
+
} else {
|
|
79
|
+
htmlParentNode.appendChild(anchor);
|
|
80
|
+
}
|
|
81
|
+
// handle nested xref
|
|
82
|
+
const linkChild = xmlnode.childNodes.find(node => node.tagName === 'xref' || node.tagName === 'ext-link');
|
|
83
|
+
if (linkChild) unnestLinks(this.recurseTheDom, this.createNode, xmlnode, anchor, linkChild)
|
|
84
|
+
else this.passThrough(anchor, xmlnode);
|
|
85
|
+
// footonote ref gets wrapped in <sup>
|
|
86
|
+
if (isFootnoteRef) {
|
|
87
|
+
anchor.innerHTML = `<sup>${anchor.innerHTML}</sup>`;
|
|
88
|
+
}
|
|
89
|
+
};
|
package/lib/hacks.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) 2023 American Mathematical Society
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
// From https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Content_categories#phrasing_content
|
|
18
|
+
// Note: 'a', 'del', 'ins', 'link', 'map', 'meta' have additional constraints that we ignore since they shouldn't occur in our content
|
|
19
|
+
const phrasingContentTags = ['abbr', 'audio', 'b', 'bdo', 'br', 'button', 'canvas', 'cite', 'code', 'data', 'datalist', 'dfn', 'em', 'embed', 'i', 'iframe', 'img', 'input', 'kbd', 'label', 'mark', 'math', 'meter', 'noscript', 'object', 'output', 'picture', 'progress', 'q', 'ruby', 'samp', 'script', 'select', 'small', 'span', 'strong', 'sub', 'sup', 'svg', 'textarea', 'time', 'u', 'var', 'video', 'wbr', 'a', 'del', 'ins', 'link', 'map', 'meta']
|
|
20
|
+
/**
|
|
21
|
+
* Moves non-phrasing content out of paragraph node. Works around texml#104
|
|
22
|
+
* @param {HTMLElement} node
|
|
23
|
+
*/
|
|
24
|
+
const sanitizeParagraph = node => {
|
|
25
|
+
const childrenArray = [...node.children];
|
|
26
|
+
const maybeBadChild = childrenArray.find(child => !phrasingContentTags.includes(child.tagName.toLowerCase()));
|
|
27
|
+
if (!maybeBadChild) return;
|
|
28
|
+
console.log(`Info: texml-to-html: fixing non-phrasing in paragraph, cf. texml#104, near ID ${node.closest('[id]')?.getAttribute('id')}`)
|
|
29
|
+
const remainingChildren = childrenArray.slice(childrenArray.indexOf(maybeBadChild)).reverse();
|
|
30
|
+
remainingChildren.forEach(child => node.insertAdjacentElement('afterend', child));
|
|
31
|
+
if (node.innerHTML.trim() === '') {
|
|
32
|
+
node.remove();
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Wrapper around hacks
|
|
38
|
+
* @param {Document} document
|
|
39
|
+
*/
|
|
40
|
+
export const applyHacks = document => {
|
|
41
|
+
// workaround texml#104
|
|
42
|
+
document.querySelectorAll('p').forEach(sanitizeParagraph);
|
|
43
|
+
}
|
package/lib/head.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) 2023 American Mathematical Society
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Populates the HTML document head.
|
|
19
|
+
* @param {Document} xmldoc - the XML document
|
|
20
|
+
* @param {Document} htmldoc - the HTML document
|
|
21
|
+
*/
|
|
22
|
+
export const setHead = (xmldoc, htmldoc) => {
|
|
23
|
+
// add charset and viewport meta tag
|
|
24
|
+
htmldoc.head.insertAdjacentHTML('afterbegin', `<meta charset="utf-8"><meta content="width=device-width, initial-scale=1" name="viewport">`);
|
|
25
|
+
// set title
|
|
26
|
+
const xmlTitle =
|
|
27
|
+
xmldoc.querySelector('front>article-meta>title-group>alt-title') ||
|
|
28
|
+
xmldoc.querySelector(
|
|
29
|
+
'book-meta>book-title-group>book-title, front>article-meta>title-group>article-title'
|
|
30
|
+
);
|
|
31
|
+
htmldoc.title = xmlTitle ? xmlTitle.textContent : 'AMS Publication';
|
|
32
|
+
|
|
33
|
+
const root = xmldoc.querySelector('article, book');
|
|
34
|
+
const lang = root.getAttribute('xml:lang') || 'en';
|
|
35
|
+
htmldoc.querySelector('html').setAttribute('lang', lang);
|
|
36
|
+
htmldoc.querySelector('html').setAttribute('dir', 'ltr');
|
|
37
|
+
};
|
|
38
|
+
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) 2023 American Mathematical Society
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import mapAttributes from '../helpers/mapAttributes.js';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Creates a (limited) copy of the element
|
|
21
|
+
* @param {HTMLElement} htmlParentNode
|
|
22
|
+
* @param {Element} xmlnode
|
|
23
|
+
*/
|
|
24
|
+
export default function (htmlParentNode, xmlnode) {
|
|
25
|
+
const copy = this.createNode(xmlnode.tagName);
|
|
26
|
+
htmlParentNode.appendChild(copy);
|
|
27
|
+
mapAttributes(copy, xmlnode);
|
|
28
|
+
this.passThrough(copy, xmlnode);
|
|
29
|
+
};
|