Skip to content

Commit

Permalink
fix(JATS): Prepend <list-item><label> to first paragraph
Browse files Browse the repository at this point in the history
  • Loading branch information
Nokome Bentley committed May 26, 2023
1 parent e51dd01 commit 7afe909
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 94 deletions.
16 changes: 0 additions & 16 deletions src/codecs/jats/__file_snapshots__/f1000-7-1655-v1.jats.xml
Original file line number Diff line number Diff line change
Expand Up @@ -223,15 +223,12 @@
<list list-type="bullet">
<list-item>
<p>○ </p>
<p>Peer review reports, anonymized or with report author names</p>
</list-item>
<list-item>
<p>○ </p>
<p>Author responses/Rebuttals</p>
</list-item>
<list-item>
<p>○ </p>
<p>Editor decision letters</p>
</list-item>
</list>
<p>Some journals also provide appeal and resubmission information (including previous versions of the article, dates, and actors involved).</p>
Expand All @@ -252,15 +249,12 @@
<list list-type="bullet">
<list-item>
<p>1. </p>
<p>Peer review materials are attached to the article as a single or numerous PDFs. Whether these materials are pulled together into one document or attached as separate documents, there should be some defined mechanism in the JATS XML tagging that would support the capture of any available metadata and identify these files in a machine-readable and interoperable way for publishers to tag this content appropriately.</p>
</list-item>
<list-item>
<p>2. </p>
<p>Peer review materials are appended to the article within the full text (so all is machine readable) as a sub-article component of the XML.</p>
</list-item>
<list-item>
<p>3. </p>
<p>Peer review materials are full-text XML “articles” or “commentaries” in their own right that link bidirectionally to the main article.</p>
</list-item>
</list>
</sec>
Expand Down Expand Up @@ -346,11 +340,9 @@
<list list-type="bullet">
<list-item>
<p>1. </p>
<p>sub-articles &lt;sub-article&gt; to the article being reviewed (sub-articles may be full-text XML or XML metadata plus a link to the PDF)</p>
</list-item>
<list-item>
<p>2. </p>
<p>independent articles &lt;article&gt; (with the appropriate &lt;related-article&gt; links – Peer Reviews MUST link to the version of the article they are reviewing and Author Replies; Decision Letters MUST link to the version of the article they are passing judgment on; and Author Replies MUST link to each Review/Decision Letter it is addressing)</p>
</list-item>
</list>
</sec>
Expand Down Expand Up @@ -413,15 +405,12 @@
<list list-type="bullet">
<list-item>
<p>○ </p>
<p>For Peer Reviews, use @contrib-type=“reviewer”</p>
</list-item>
<list-item>
<p>○ </p>
<p>For Decision Letters, use @contrib-type=“editor”</p>
</list-item>
<list-item>
<p>○ </p>
<p>For Author Reply, use @contrib-type=“author”</p>
</list-item>
</list>
<p>We intend that the @contrib-type attribute value reflects the contributor’s relationship to the peer review process and not the relationship with the document.</p>
Expand Down Expand Up @@ -459,23 +448,18 @@
<list list-type="bullet">
<list-item>
<p>a. </p>
<p>&lt;funding-group&gt;</p>
</list-item>
<list-item>
<p>b. </p>
<p>&lt;app&gt;, &lt;app-group&gt;, &lt;ack&gt;, &lt;glossary&gt;, &lt;back&gt;/&lt;sec&gt;</p>
</list-item>
<list-item>
<p>c. </p>
<p>&lt;supplementary-material&gt;, &lt;inline-supplementary-material&gt;</p>
</list-item>
<list-item>
<p>d. </p>
<p>&lt;bio&gt;</p>
</list-item>
<list-item>
<p>e. </p>
<p>&lt;article-version&gt; Once published, review documents will not be “versioned”. If the reviewer(s) write a review on an updated version of the manuscript, the peer review is a new published object.</p>
</list-item>
</list>
</sec>
Expand Down
74 changes: 0 additions & 74 deletions src/codecs/jats/__file_snapshots__/f1000-7-1655-v1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -457,25 +457,16 @@ content:
- type: Paragraph
content:
- ''
- type: Paragraph
content:
- Peer review reports, anonymized or with report author names
- type: ListItem
content:
- type: Paragraph
content:
- ''
- type: Paragraph
content:
- Author responses/Rebuttals
- type: ListItem
content:
- type: Paragraph
content:
- ''
- type: Paragraph
content:
- Editor decision letters
order: Unordered
meta:
listType: bullet
Expand Down Expand Up @@ -561,38 +552,16 @@ content:
- type: Paragraph
content:
- '1. '
- type: Paragraph
content:
- >-
Peer review materials are attached to the article as a single or
numerous PDFs. Whether these materials are pulled together into
one document or attached as separate documents, there should be
some defined mechanism in the JATS XML tagging that would
support the capture of any available metadata and identify these
files in a machine-readable and interoperable way for publishers
to tag this content appropriately.
- type: ListItem
content:
- type: Paragraph
content:
- '2. '
- type: Paragraph
content:
- >-
Peer review materials are appended to the article within the
full text (so all is machine readable) as a sub-article
component of the XML.
- type: ListItem
content:
- type: Paragraph
content:
- '3. '
- type: Paragraph
content:
- >-
Peer review materials are full-text XML “articles” or
“commentaries” in their own right that link bidirectionally to
the main article.
order: Unordered
meta:
listType: bullet
Expand Down Expand Up @@ -848,26 +817,11 @@ content:
- type: Paragraph
content:
- '1. '
- type: Paragraph
content:
- >-
sub-articles <sub-article> to the article being reviewed
(sub-articles may be full-text XML or XML metadata plus a link
to the PDF)
- type: ListItem
content:
- type: Paragraph
content:
- '2. '
- type: Paragraph
content:
- >-
independent articles <article> (with the appropriate
<related-article> links – Peer Reviews MUST link to the version
of the article they are reviewing and Author Replies; Decision
Letters MUST link to the version of the article they are passing
judgment on; and Author Replies MUST link to each
Review/Decision Letter it is addressing)
order: Unordered
meta:
listType: bullet
Expand Down Expand Up @@ -1020,25 +974,16 @@ content:
- type: Paragraph
content:
- ''
- type: Paragraph
content:
- For Peer Reviews, use @contrib-type=“reviewer”
- type: ListItem
content:
- type: Paragraph
content:
- ''
- type: Paragraph
content:
- For Decision Letters, use @contrib-type=“editor”
- type: ListItem
content:
- type: Paragraph
content:
- ''
- type: Paragraph
content:
- For Author Reply, use @contrib-type=“author”
order: Unordered
meta:
listType: bullet
Expand Down Expand Up @@ -1137,45 +1082,26 @@ content:
- type: Paragraph
content:
- 'a. '
- type: Paragraph
content:
- <funding-group>
- type: ListItem
content:
- type: Paragraph
content:
- 'b. '
- type: Paragraph
content:
- <app>, <app-group>, <ack>, <glossary>, <back>/<sec>
- type: ListItem
content:
- type: Paragraph
content:
- 'c. '
- type: Paragraph
content:
- <supplementary-material>, <inline-supplementary-material>
- type: ListItem
content:
- type: Paragraph
content:
- 'd. '
- type: Paragraph
content:
- <bio>
- type: ListItem
content:
- type: Paragraph
content:
- 'e. '
- type: Paragraph
content:
- >-
<article-version> Once published, review documents will not be
“versioned”. If the reviewer(s) write a review on an updated
version of the manuscript, the peer review is a new published
object.
order: Unordered
meta:
listType: bullet
Expand Down
29 changes: 29 additions & 0 deletions src/codecs/jats/__file_snapshots__/labelled-list-items.jats.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.1 20151215//EN" "JATS-archivearticle1.dtd">
<article xmlns:xlink="http://www.w3.org/1999/xlink" article-type="research-article">
<front>
<article-meta>
<title-group>
<article-title/>
</title-group>
<contrib-group/>
</article-meta>
</front>
<body>
<sec>
<p>Test that list-item labels do not create a new paragraph but are instead prepended to paragraph</p>
<list list-type="bullet">
<list-item>
<p>1) We showed that ...</p>
</list-item>
<list-item>
<p>2) We exploited an ...</p>
</list-item>
<list-item>
<p>3) We followed the ...</p>
</list-item>
</list>
</sec>
</body>
<back/>
</article>
27 changes: 27 additions & 0 deletions src/codecs/jats/__file_snapshots__/labelled-list-items.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
type: Article
content:
- type: Paragraph
content:
- >-
Test that list-item labels do not create a new paragraph but are instead
prepended to paragraph
- type: List
items:
- type: ListItem
content:
- type: Paragraph
content:
- 1) We showed that ...
- type: ListItem
content:
- type: Paragraph
content:
- 2) We exploited an ...
- type: ListItem
content:
- type: Paragraph
content:
- 3) We followed the ...
order: Unordered
meta:
listType: simple
11 changes: 11 additions & 0 deletions src/codecs/jats/__fixtures__/labelled-list-items.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0"?>
<article>
<body>
<p>Test that list-item labels do not create a new paragraph but are instead prepended to paragraph</p>
<list list-type="simple">
<list-item><label>1)</label><p>We showed that ...</p></list-item>
<list-item><label>2)</label><p>We exploited an ...</p></list-item>
<list-item><label>3)</label><p>We followed the ...</p></list-item>
</list>
</body>
</article>
18 changes: 15 additions & 3 deletions src/codecs/jats/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2121,10 +2121,22 @@ function decodeList(elem: xml.Element, state: DecodeState): [stencila.List] {
const order =
type === 'bullet' || type === 'simple' ? 'Unordered' : 'Ascending'
const items = children(elem, 'list-item').map((item): stencila.ListItem => {
// If the list-item's first child is a label then prepend that to the next
// node (usually a paragraph) to avoid it getting wrapped its own paragraph
const children = item.elements ?? []
if (
children.length > 1 &&
children[0].name === 'label' &&
children[1].elements
) {
const label = text(children.shift()!)
// Note: now former child [0] is child [1]
children[0].elements![0].text = label.endsWith(' ')
? label
: label + ' ' + text(children[0])
}
return stencila.listItem({
content: ensureBlockContentArray(
decodeElements(item.elements ?? [], state)
),
content: ensureBlockContentArray(decodeElements(children, state)),
})
})
return [stencila.list({ items, order, meta: { listType: type } })]
Expand Down
3 changes: 2 additions & 1 deletion src/codecs/jats/jats.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ test.each([
'quote.xml',
'nested-list.xml',
'supplementary-material.xml',
'labelled-list-items.xml',
'elife-30274-v1',
'elife-43154-v2',
'elife-46472-v3',
Expand Down Expand Up @@ -330,7 +331,7 @@ test.each([
['ca7917ff-6cb0-1014-9b19-d05ef1e56b05', '468444.xml'],
['d6f14042-6db3-1014-b228-f9da7cb8e4cc', '22275761.xml'],
['e9291f49-6d06-1014-9500-e156797df82e', '501569.xml'],
['87253', '87253.xml']
['87253', '87253.xml'],
])('decode + encode : %s', async (meca, file) => {
const node = unlinkFiles(await jats.read(fixture(`${meca}/content/${file}`)))
expect(await json.dump(node)).toMatchFile(snapshot(`${meca}.json`))
Expand Down

0 comments on commit 7afe909

Please sign in to comment.