@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.
Files changed (166) hide show
  1. package/CHANGELOG.md +1414 -0
  2. package/LICENSE +202 -0
  3. package/NOTICE +5 -0
  4. package/README.md +16 -0
  5. package/examples/cli.js +6 -0
  6. package/ldom.js +6 -0
  7. package/lib/doms.js +30 -0
  8. package/lib/elements/abstract.js +34 -0
  9. package/lib/elements/algorithm.js +78 -0
  10. package/lib/elements/app.js +35 -0
  11. package/lib/elements/article-metadata-json.js +167 -0
  12. package/lib/elements/article-title.js +26 -0
  13. package/lib/elements/article.js +28 -0
  14. package/lib/elements/attrib.js +41 -0
  15. package/lib/elements/bold.js +32 -0
  16. package/lib/elements/book-meta-json.js +134 -0
  17. package/lib/elements/book-meta.js +33 -0
  18. package/lib/elements/book-title.js +26 -0
  19. package/lib/elements/boxed-text.js +31 -0
  20. package/lib/elements/break.js +25 -0
  21. package/lib/elements/caption.js +52 -0
  22. package/lib/elements/compound-kwd.js +27 -0
  23. package/lib/elements/def-item.js +26 -0
  24. package/lib/elements/def-list.js +30 -0
  25. package/lib/elements/def.js +29 -0
  26. package/lib/elements/disp-formula-group.js +30 -0
  27. package/lib/elements/disp-quote.js +33 -0
  28. package/lib/elements/email.js +28 -0
  29. package/lib/elements/ext-link.js +38 -0
  30. package/lib/elements/fig.js +32 -0
  31. package/lib/elements/fn.js +42 -0
  32. package/lib/elements/formula.js +51 -0
  33. package/lib/elements/front.js +64 -0
  34. package/lib/elements/funding-group.js +26 -0
  35. package/lib/elements/graphic.js +49 -0
  36. package/lib/elements/img.js +28 -0
  37. package/lib/elements/italic.js +33 -0
  38. package/lib/elements/kwd-group.js +29 -0
  39. package/lib/elements/kwd.js +26 -0
  40. package/lib/elements/label.js +101 -0
  41. package/lib/elements/line.js +31 -0
  42. package/lib/elements/meta-name.js +29 -0
  43. package/lib/elements/meta-value.js +27 -0
  44. package/lib/elements/mixed-citation.js +35 -0
  45. package/lib/elements/monospace.js +35 -0
  46. package/lib/elements/notes.js +36 -0
  47. package/lib/elements/p.js +29 -0
  48. package/lib/elements/preface.js +33 -0
  49. package/lib/elements/ref-list.js +50 -0
  50. package/lib/elements/ref.js +28 -0
  51. package/lib/elements/roman.js +34 -0
  52. package/lib/elements/sans-serif.js +34 -0
  53. package/lib/elements/sc.js +35 -0
  54. package/lib/elements/sec-meta.js +35 -0
  55. package/lib/elements/sec.js +89 -0
  56. package/lib/elements/secheading.js +43 -0
  57. package/lib/elements/simpletabbing.js +29 -0
  58. package/lib/elements/statement.js +31 -0
  59. package/lib/elements/string-name.js +28 -0
  60. package/lib/elements/styled-content.js +32 -0
  61. package/lib/elements/subj-group.js +29 -0
  62. package/lib/elements/subject.js +26 -0
  63. package/lib/elements/subtitle.js +29 -0
  64. package/lib/elements/table.js +28 -0
  65. package/lib/elements/tag.js +50 -0
  66. package/lib/elements/target.js +39 -0
  67. package/lib/elements/term.js +31 -0
  68. package/lib/elements/tex-math.js +34 -0
  69. package/lib/elements/text.js +29 -0
  70. package/lib/elements/toc-entry.js +63 -0
  71. package/lib/elements/toc.js +35 -0
  72. package/lib/elements/underline.js +26 -0
  73. package/lib/elements/x.js +27 -0
  74. package/lib/elements/xref-group.js +36 -0
  75. package/lib/elements/xref.js +89 -0
  76. package/lib/hacks.js +43 -0
  77. package/lib/head.js +38 -0
  78. package/lib/helpers/copyElement.js +29 -0
  79. package/lib/helpers/extractContribGroups.js +94 -0
  80. package/lib/helpers/generateByline.js +35 -0
  81. package/lib/helpers/getParentLevel.js +24 -0
  82. package/lib/helpers/helpers-tex.js +54 -0
  83. package/lib/helpers/mapAttributes.js +54 -0
  84. package/lib/helpers/mapColorAttributes.js +36 -0
  85. package/lib/helpers/unnest.js +34 -0
  86. package/lib/transformer.js +311 -0
  87. package/out.html +550 -0
  88. package/package.json +39 -0
  89. package/test/article--alttitle.xml +146 -0
  90. package/test/article--nometa.xml +40 -0
  91. package/test/article-alttitle-meta-snapshot.json +94 -0
  92. package/test/article-meta-snapshot.json +129 -0
  93. package/test/article-nometa-meta-snapshot.json +46 -0
  94. package/test/article.xml +593 -0
  95. package/test/attribute-content-type.js +26 -0
  96. package/test/attribute-has-qed-box.js +28 -0
  97. package/test/attribute-hidden.js +27 -0
  98. package/test/attribute-rowspan-colspan.js +27 -0
  99. package/test/attribute-specific-use.js +27 -0
  100. package/test/attribute-style.js +27 -0
  101. package/test/book-meta-snapshot.json +78 -0
  102. package/test/book.xml +292 -0
  103. package/test/copyElement.js +38 -0
  104. package/test/element-abstract-title.js +27 -0
  105. package/test/element-algorithm.js +56 -0
  106. package/test/element-article.js +24 -0
  107. package/test/element-attrib.js +27 -0
  108. package/test/element-back-app-group-app.js +28 -0
  109. package/test/element-bold.js +26 -0
  110. package/test/element-book-meta.js +37 -0
  111. package/test/element-book-preface.js +29 -0
  112. package/test/element-book-ref-list.js +32 -0
  113. package/test/element-book.js +33 -0
  114. package/test/element-boxed-text.js +28 -0
  115. package/test/element-break.js +27 -0
  116. package/test/element-citegroup.js +25 -0
  117. package/test/element-compound-kwd.js +24 -0
  118. package/test/element-def-list-def-item-def-term.js +43 -0
  119. package/test/element-disp-formula-group.js +27 -0
  120. package/test/element-disp-quote.js +31 -0
  121. package/test/element-email.js +26 -0
  122. package/test/element-ext-link.js +30 -0
  123. package/test/element-fig-subfig-label.js +38 -0
  124. package/test/element-fn.js +40 -0
  125. package/test/element-front.js +45 -0
  126. package/test/element-funding-group.js +29 -0
  127. package/test/element-graphic-inline-graphic.js +40 -0
  128. package/test/element-img.js +30 -0
  129. package/test/element-inline-formula-disp-formula-tex-math.js +91 -0
  130. package/test/element-italic.js +28 -0
  131. package/test/element-kwd-group.js +28 -0
  132. package/test/element-kwd.js +27 -0
  133. package/test/element-mixed-citation.js +32 -0
  134. package/test/element-monospace.js +27 -0
  135. package/test/element-notes.js +42 -0
  136. package/test/element-p-p.js +27 -0
  137. package/test/element-ref-list-ref-label.js +40 -0
  138. package/test/element-roman.js +27 -0
  139. package/test/element-sans-serif.js +27 -0
  140. package/test/element-sc.js +27 -0
  141. package/test/element-sec-app-front-matter-part-dedication-title-label.js +87 -0
  142. package/test/element-sec-meta.js +43 -0
  143. package/test/element-secheading.js +28 -0
  144. package/test/element-simpletabbing-line.js +31 -0
  145. package/test/element-statement-label-title.js +120 -0
  146. package/test/element-string-name.js +27 -0
  147. package/test/element-stripEmptyLabel.js +26 -0
  148. package/test/element-styled-content.js +28 -0
  149. package/test/element-subtitle.js +36 -0
  150. package/test/element-table-wrap-group.js +30 -0
  151. package/test/element-table-wrap.js +51 -0
  152. package/test/element-table.js +34 -0
  153. package/test/element-tag.js +38 -0
  154. package/test/element-target.js +33 -0
  155. package/test/element-toc-toc-entry.js +77 -0
  156. package/test/element-underline.js +27 -0
  157. package/test/element-verse-group.js +28 -0
  158. package/test/element-x.js +30 -0
  159. package/test/element-xref-group.js +26 -0
  160. package/test/element-xref.js +32 -0
  161. package/test/hacks.js +37 -0
  162. package/test/helper-mapColorAttributes.js +27 -0
  163. package/test/helper.js +26 -0
  164. package/test/setHead.js +32 -0
  165. package/test/unit/abstract.js +35 -0
  166. 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
+ };