@amermathsoc/texml-to-html 17.0.0 → 17.1.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 CHANGED
@@ -2,6 +2,20 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ## [17.1.0](https://github.com/AmerMathSoc/texml-to-html/compare/v17.0.1...v17.1.0) (2024-07-04)
6
+
7
+
8
+ ### Features
9
+
10
+ * **toc-entry.js:** add label/title wrappers ([2165072](https://github.com/AmerMathSoc/texml-to-html/commit/2165072dc60ff9fd7c40ad6f65221eaa6f0924a2)), closes [#451](https://github.com/AmerMathSoc/texml-to-html/issues/451)
11
+
12
+ ### [17.0.1](https://github.com/AmerMathSoc/texml-to-html/compare/v17.0.0...v17.0.1) (2024-06-07)
13
+
14
+
15
+ ### Bug Fixes
16
+
17
+ * handle cite-group, cite-detail inside tex-math ([0df8528](https://github.com/AmerMathSoc/texml-to-html/commit/0df85280d892ee33572f0923f6e56197bbb26a34)), closes [#450](https://github.com/AmerMathSoc/texml-to-html/issues/450)
18
+
5
19
  ## [17.0.0](https://github.com/AmerMathSoc/texml-to-html/compare/v16.1.1...v17.0.0) (2024-06-07)
6
20
 
7
21
 
@@ -0,0 +1,30 @@
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
+ * sc element
19
+ * @param {HTMLElement} htmlParentNode
20
+ * @param {Element} xmlnode
21
+ */
22
+ export default function (htmlParentNode, xmlnode) {
23
+ if (xmlnode.closest('tex-math')) {
24
+ this.passThrough(htmlParentNode, xmlnode);
25
+ return;
26
+ }
27
+ const citeGroup = this.createNode('cite-detail');
28
+ htmlParentNode.appendChild(citeGroup);
29
+ this.passThrough(citeGroup, xmlnode);
30
+ };
@@ -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
+ /**
18
+ * sc element
19
+ * @param {HTMLElement} htmlParentNode
20
+ * @param {Element} xmlnode
21
+ */
22
+ export default function (htmlParentNode, xmlnode) {
23
+ if (xmlnode.closest('tex-math')) {
24
+ this.passThrough(htmlParentNode, xmlnode);
25
+ return;
26
+ }
27
+ const citeGroup = this.createNode('cite-group');
28
+ htmlParentNode.appendChild(citeGroup);
29
+ this.passThrough(citeGroup, xmlnode);
30
+
31
+ };
@@ -27,13 +27,14 @@ export default function (htmlParentNode, xmlnode) {
27
27
  "data-ams-ref": xmlnode.getAttribute('specific-use') // NOTE: specific-use contains `ref@ref-type`-like information (e.g., 'chapter', 'section')
28
28
  });
29
29
  li.appendChild(anchor);
30
- // 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
31
- // NOTE [...].find() HACK for bug with ':scope > ...', jsdom/jsdom#2998
30
+ // NOTE: label/title handling must stay aligned with other cases
32
31
  const label = xmlnode.querySelector(':scope>label');
33
32
  const title = xmlnode.querySelector(':scope>title');
34
33
  const altTitle = xmlnode.querySelector(':scope>alt-title');
35
34
  if (label && label.innerHTML.trim() !== '') {
36
- this.passThrough(anchor, label);
35
+ const labelSpan = this.createNode('span', '', { 'data-ams-doc': 'label' });
36
+ anchor.appendChild(labelSpan);
37
+ this.passThrough(labelSpan, label);
37
38
  anchor.insertAdjacentText('beforeend', '. ');
38
39
  }
39
40
  if (altTitle) {
@@ -43,7 +44,11 @@ export default function (htmlParentNode, xmlnode) {
43
44
  anchor.textContent + altTitleContent
44
45
  );
45
46
  }
46
- if (title) this.passThrough(anchor, title);
47
+ if (title) {
48
+ const titleSpan = this.createNode('span', '', { 'data-ams-doc': 'title' });
49
+ anchor.appendChild(titleSpan);
50
+ this.passThrough(titleSpan, title);
51
+ }
47
52
  // NOTE we expect very simple markup: one contrib group, string-names only
48
53
  const contribGroup = xmlnode.querySelector(':scope>contrib-group');
49
54
  if (contribGroup) {
@@ -80,6 +80,8 @@ import * as algorithm from './elements/algorithm.js';
80
80
  import Tag from './elements/tag.js';
81
81
  import Xrefgroup from './elements/xref-group.js';
82
82
  import TexMath from './elements/tex-math.js';
83
+ import CiteGroup from './elements/cite-group.js';
84
+ import CiteDetail from './elements/cite-detail.js';
83
85
 
84
86
  import copyElement from './helpers/copyElement.js';
85
87
  import { extractContribGroups } from './helpers/extractContribGroups.js';
@@ -126,8 +128,6 @@ export class Transformer {
126
128
  'td',
127
129
  'pre',
128
130
  'hr',
129
- 'cite-group',
130
- 'cite-detail',
131
131
  ].forEach(mapTag.bind(null, this.copyElement));
132
132
  // passThrough elements
133
133
  [
@@ -275,6 +275,8 @@ export class Transformer {
275
275
  tag = Tag.bind(this)
276
276
  'xref-group' = Xrefgroup.bind(this)
277
277
  'tex-math' = TexMath.bind(this)
278
+ 'cite-group' = CiteGroup.bind(this)
279
+ 'cite-detail' = CiteDetail.bind(this)
278
280
 
279
281
  // one-off reuse of imported elements
280
282
  // NOTE if RHS gets re-used more than once, use mapTag in the constructor
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@amermathsoc/texml-to-html",
3
- "version": "17.0.0",
3
+ "version": "17.1.0",
4
4
  "type": "module",
5
5
  "description": "A NodeJS library for converting AMS-style JATS XML to HTML",
6
6
  "scripts": {
package/test/article.xml CHANGED
@@ -419,6 +419,12 @@
419
419
  <tag parens="yes">T</tag>
420
420
  </target>
421
421
  </disp-formula>
422
+ <!-- Formula with cite-group and cite-detail -->
423
+ <disp-formula>
424
+ <tex-math>
425
+ <cite-group><x>[</x><xref ref-type="bibr" rid="bibr-AEG0" specific-use="cite">AEG08<cite-detail><x>, </x>Section 5</cite-detail></xref><x></cite-group>
426
+ </tex-math>
427
+ </disp-formula>
422
428
  </sec>
423
429
  <!-- citegroup, cite-detail-->
424
430
  <sec disp-level="1" id="citegroup" specific-use="section">
@@ -18,7 +18,7 @@ import { article } from './helper.js';
18
18
  import tape from 'tape';
19
19
 
20
20
  tape('inline-formula, disp-formula, tex-math', async function (t) {
21
- t.plan(19);
21
+ t.plan(20);
22
22
  const document = article;
23
23
  const inlineformula = document.querySelector(
24
24
  '#equations [data-ams-doc="math inline"]'
@@ -93,4 +93,6 @@ tape('inline-formula, disp-formula, tex-math', async function (t) {
93
93
  t.ok(document.querySelector('div[data-ams-doc="math text"]'), 'Display Formula of content-type=text');
94
94
  t.equal(document.querySelector('div[data-ams-doc="math text"] > span[data-ams-doc="label"]#textEquation+p').previousElementSibling.innerHTML, '(T)', 'Display Formula of content-type=text, label and paragraph');
95
95
 
96
+ // formula with cite-group and cite-detail
97
+ t.equal(dispWithText[9].innerHTML, ' \\xhref[bibr]{#bibr-AEG0}{AEG08, Section 5} ', 'Formula with cite-group, cite-detail')
96
98
  });
@@ -17,7 +17,7 @@
17
17
  import { book } from './helper.js';
18
18
  import tape from 'tape';
19
19
 
20
- tape('Template: (book) toc, toc-entry', async function(t) {
20
+ tape('Template: (book) toc, toc-entry', async function (t) {
21
21
  t.plan(14);
22
22
  const document = book;
23
23
 
@@ -30,28 +30,28 @@ tape('Template: (book) toc, toc-entry', async function(t) {
30
30
  t.equal(list.children.length, 6, 'Nested toc-entries remain nested')
31
31
  t.equal(
32
32
  list.querySelector('li a[href="#tocid1"][data-ams-ref="chapter"]').innerHTML,
33
- 'Chunk',
33
+ '<span data-ams-doc="title">Chunk</span>',
34
34
  'toc-entry and nav-pointer with href and data-ams-ref'
35
35
  );
36
36
  t.equal(
37
37
  list.querySelector('li a[href="#tocid2"]').innerHTML,
38
- '2. Chunk',
38
+ '<span data-ams-doc="label">2</span>. <span data-ams-doc="title">Chunk</span>',
39
39
  'toc-entry, label, nav-pointer'
40
40
  );
41
41
  t.equal(list.querySelector('ol').children.length, 1, 'Doubly nested toc-entries remain nested');
42
42
  t.equal(
43
43
  list.querySelector('li a[href="#tocid2"]+ol li a[href="#tocid3"]').innerHTML,
44
- '1. SubChunk',
44
+ '<span data-ams-doc="label">1</span>. <span data-ams-doc="title">SubChunk</span>',
45
45
  'Nested toc-entry, label, nav-pointer'
46
46
  );
47
47
  t.equal(
48
48
  list.querySelector('li a[href="#tocid4"]').innerHTML,
49
- '1. SubSubChunk with <span data-ams-href="chapter">Link</span>',
49
+ '<span data-ams-doc="label">1</span>. <span data-ams-doc="title">SubSubChunk with <span data-ams-href="chapter">Link</span></span>',
50
50
  'toc-entry with xref in title'
51
51
  );
52
52
  t.equal(
53
53
  list.querySelector('li a[href="#tocid5"]').innerHTML,
54
- 'Chunk with alt title',
54
+ '<span data-ams-doc="title">Chunk with alt title</span>',
55
55
  'toc-entry with alt-title: content'
56
56
  );
57
57
  t.equal(
@@ -61,7 +61,7 @@ tape('Template: (book) toc, toc-entry', async function(t) {
61
61
  );
62
62
  t.equal(
63
63
  list.querySelector('li a[href="#tocid6"]').innerHTML,
64
- 'Chunk without label but subchunk with label',
64
+ '<span data-ams-doc="title">Chunk without label but subchunk with label</span>',
65
65
  'toc-entry without label but sub-entry with label'
66
66
  );
67
67
  t.equal(
package/test/hacks.js CHANGED
@@ -34,8 +34,6 @@ tape('Hacks', async function (t) {
34
34
 
35
35
  t.equal(document.querySelectorAll('#hacks > p').length, 1, 'If paragraph is empty after postprocessing, it is removed.')
36
36
 
37
- console.log(article.querySelector('cite-group').parentNode.outerHTML)
38
-
39
37
  t.equal(document.querySelector('cite-group').parentNode.tagName, 'P', 'Custom elements remain in paragraph');
40
38
  });
41
39