Skip to content

Commit

Permalink
feat: support cite-group and cite-detail
Browse files Browse the repository at this point in the history
Adds support for new cite-group syntax.
- transformer.js
  - copyable elements: add cite-group and cite-detail
  - passThrough elements: remove cite-group
- x.js
  - adjust check for articles since x is no w inside cite-detail (inside xref)
- test
  - article.xml: add test case
  - book.xml: add test case
  - add cite-detail test
  - element-cite-group: test article and book output
    Note: git is confused, thinking cite-group was renamed to
    cite-detail.

Resolves #443
  • Loading branch information
pkra committed May 31, 2024
1 parent 964ecee commit dc832cf
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lib/elements/x.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*/
export default function (htmlParentNode, xmlnode) {
// ignore if not xref/x or isBook
if ('xref' !== xmlnode.parentNode.tagName && xmlnode.closest('article'))
if (!xmlnode.closest('xref') && xmlnode.closest('article'))
return;
this.passThrough(htmlParentNode, xmlnode);
};
3 changes: 2 additions & 1 deletion lib/transformer.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ export class Transformer {
'td',
'pre',
'hr',
'cite-group',
'cite-detail',
].forEach(mapTag.bind(null, this.copyElement));
// passThrough elements
[
Expand All @@ -144,7 +146,6 @@ export class Transformer {
'back',
'alternatives',
'title-group',
'cite-group',
'app-group',
'book-title-group',
'private-char',
Expand Down
4 changes: 2 additions & 2 deletions test/article.xml
Original file line number Diff line number Diff line change
Expand Up @@ -420,9 +420,9 @@
</target>
</disp-formula>
</sec>
<!-- inline-formula, disp-formula, tex-math -->
<!-- citegroup, cite-detail-->
<sec disp-level="1" id="citegroup" specific-use="section">
<cite-group><x>[</x><xref ref-type="type" rid="rid1">ref</xref><x>, </x><xref ref-type="fn" rid="rid2">ref</xref><x>]</x></cite-group>
<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>; </x><xref ref-type="bibr" rid="bibr-AEG0" specific-use="cite">AEG08</xref><x>]</x></cite-group>
</sec>

<!-- alt-title -->
Expand Down
5 changes: 5 additions & 0 deletions test/book.xml
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,11 @@
<line indent="1">Indented line.</line>
</simpletabbing>
</sec>
<!-- citegroup, cite-detail-->
<sec disp-level="1" id="citegroup" specific-use="section">
<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>; </x><xref ref-type="bibr" rid="bibr-AEG0" specific-use="cite">AEG08</xref><x>]</x></cite-group>
</sec>

</body>
</book-part>
</book-body>
Expand Down
8 changes: 4 additions & 4 deletions test/element-citegroup.js → test/element-cite-detail.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import { article } from './helper.js';
import tape from 'tape';


tape('Template: cite-group', async function(t) {
t.plan(1);
const document = article;
t.equal(document.querySelectorAll('section#citegroup a').length, 2, 'cite-group passed through, leaving two anchors');
tape('Template: cite-detail', async function(t) {
t.plan(2);

t.equal(article.querySelector('cite-detail').outerHTML, '<cite-detail>, Section 5</cite-detail>', 'cite-detail');
});
27 changes: 27 additions & 0 deletions test/element-cite-group.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*!
* Copyright (c) 2023 American Mathematical Society
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { article, book } from './helper.js';
import tape from 'tape';


tape('Template: cite-group', async function (t) {
t.plan(2);

t.equal(article.querySelector('cite-group').outerHTML, '<cite-group><cite><a role="doc-biblioref" data-ams-ref="bibr" href="#bibr-AEG0">AEG08<cite-detail>, Section 5</cite-detail></a></cite><cite><a role="doc-biblioref" data-ams-ref="bibr" href="#bibr-AEG0">AEG08</a></cite></cite-group>', 'cite-group in article');
t.equal(book.querySelector('cite-group').outerHTML, '<cite-group>[<cite><a role="doc-biblioref" data-ams-ref="bibr" href="#bibr-AEG0">AEG08<cite-detail>, Section 5</cite-detail></a></cite>; <cite><a role="doc-biblioref" data-ams-ref="bibr" href="#bibr-AEG0">AEG08</a></cite>]</cite-group>', 'cite-group in book');

});

0 comments on commit dc832cf

Please sign in to comment.