Repository navigation
Description
Background
The JATS spec does not allow you to have block quotes (i.e. <disp-quote>) inside footnotes (i.e. <fn>).
Frankly, I think this is an odd and unreasonable restriction. Some authors – and some disciplines, such as legal scholarship – make heavy use of footnotes. As far as I know, there's nothing fundamentally wrong with placing a block quote inside a footnote.
Problem
I am encountering real-world examples of this problem, so I need some sort of workaround.
To be clear, here's an example of invalid JATS:
<fn>
<p> ... </p>
<disp-quote> ... </disp-quote>
</fn>
This JATS XML would fail validation with the error: Element fn content does not follow the DTD, expecting (label? , p+), got (p disp-quote)
Steps to recreate
Pandoc version: 2.7.2
Files: jats_example.zip
To reproduce the issue described above
pandoc -s --metadata-file metadata.json --to jats example.md -o output.xml- Validate
output.xmlusing the PMC online validation tool: https://www.ncbi.nlm.nih.gov/pmc/tools/xmlchecker - The validation tool will display the errors described above
Solution
After examining the JATS spec, I think I have a solid workaround. I want to wrap the <disp-quote> element in a <p> element. This will ensure the JATS is valid while while only minimally changing the semantic meaning. Unless it's too much work, it would be nice if we could also include a specific-use attribute.
So in practice, we would convert this:
<fn>
<p> ... </p>
<disp-quote> ... </disp-quote>
</fn>
Into this:
<fn>
<p> ... </p>
<p specific-use="wrapper">
<disp-quote> ... </disp-quote>
</p>
</fn>
For sure, this is a little weird. From a semantic (or even just commonsense) standpoint, it doesn't make sense to have a block quote inside a paragraph. But this is allowed / valid in JATS. In fact, here's a proof of concept demonstrating that it's valid / okay to wrap a <disp-quote> in a <p> tag. You can download this file and run it through the PMC Validator to confirm.
Finally, in case it's unclear, I only want to wrap <disp-quote> when nested inside <fn> (i.e. I don't want to wrap all <disp-quote>).
Questions
First, I can't decide if this fix should be made directly in the core JATS writer or only in my code (e.g. using a custom filter). Personally, I am leaning toward the core JATS writer because, imo, the JATS writer should strive to produce valid JATS and thus everyone would benefit from this fix. However, I can also imagine y'all feeling like this problem is too specific and should be solved in the client's code rather than Pandoc. And, of course, it's really not my decision to make. So... Let me know what y'all think.
Second, if y'all think this should be solved in the client's code, then I could use some help writing a Lua filter for this use case. I have successfully written some basic Lua filters in the past, but this problem is proving trickier than I expected. Seems like Pandoc's AST expects paragraphs to include a list of inline elements but I'm trying to nest a block quote which also a block element. Anyway, for whatever reason, it's not working as expected, so any advice would be very much appreciated.
Thanks again for maintaining Pandoc! It's an amazing tool!
Activity
jgm commentedon Jun 10, 2019
I think it makes sense to make pandoc do this transformation when generating JATS.
coryschires commentedon Jun 10, 2019
Okay, great!
I don't want to slam you all at once with a bunch of issues. But I am seeing a few very similar problems, and it probably makes sense to at least show you the full scope of these problems, so that you can consider the issue comprehensively.
<list-item>) include block quotes (i.e.<disp-quote>)<caption>element includes as<list>Both these problems are very similar to the one outlined above:
<p>.I'd be happy to write up each of these as separate issues with recreation examples, etc – whatever is most convenient for you.
And overall, I'm happy to help in any way I can. Just let me know what I can do.
Thanks again!
jgm commentedon Jun 10, 2019
Is it safe to assume that
<p>inside a node?<p>?coryschires commentedon Jun 11, 2019
Good questions. The JATS spec should be helpful here as they strictly specify how elements may be nested. For the full story, I recommend looking at the Document Hierarchy Diagrams.
But to answer your question:
<fn>– Footnotes may contain(label? , p+)which means 0-1<label>and/or 0+<p>. So in this case I think it would make sense to wrap a paragraph around any element nested within an<fn>other thanlabelorp.<caption>– Captions may contain(title? , p*)which means 0-1<title>and/or 0+<p>. So, I think it would make sense to wrap a paragraph around any element nested within a<caption>other thantitleorp.<list-item>– List items may contain(label? , title? , (p | def-list | list)+)which means 0-1<label>, 0-1<title>, and 0+<p>,<def-list>, or<list>in any order. So the<list-item>element allows a greater variety of child elements, which may make your solution slightly more complex. But, similar to the other elements, a solution could be to wrap any element not included in that list.Hopefully that helps! Let me know if you have any other questions.
jgm commentedon Jun 11, 2019
OK, according to the spec,
<p>can contain:That covers all block-level elements, as rendered by pandoc, except:
refs)Here's the complete list:
jgm commentedon Jun 11, 2019
So I think what you suggest is basically right:
Inside
<fn>, wrap everything other than a Para in a<p>. If the note contains a Header or Div with idrefs, which is theoretically possible, this will break. Special-case Header by downgrading to<p>; special-case Div#refs by downgrading to regularDiv.Inside
<list-item>, wrap everything other than a Para or a List in a<p>. Special-case Headers, which can't be wrapped, by downgrading them to<p>.We don't yet need to worry about
<caption>, because pandoc doesn't yet allow block-level content there.I think the cleanest way to do the wrapping is to add a
needsWrapparameter toblocksToJATSwith typeBlock -> Bool.blocksToJATScan then handle the wrapping.jgm commentedon Jun 11, 2019
Done. If you could use this version to generate some documents and make sure they validate, that would be great.
coryschires commentedon Jun 11, 2019
Wow so fast! I'd be happy to test this fix against my problem articles and follow up.
I do have a related question though... Is there an easy way for me to install the bleeding edge in order to test this? (Otherwise, I could wait for you to cut a new version which would also be fine with me.)
If it matters, currently I am installing via Dockerfile:
jgm commentedon Jun 11, 2019
You could try https://github.com/pandoc-extras/pandoc-nightly
(by tomorrow it should include this change)
Or follow the instructions on the website for installation from source.
coryschires commentedon Jun 11, 2019
Great! I can test it tomorrow using the nightly build. I'll follow up on this thread to let you know how it works.
Thanks again!
coryschires commentedon Jun 17, 2019
Following up here... I am testing my documents against the latest version,
2.7.3. Good news and bad news:Good news
The
<p specific-use="wrapper">workaround discussed in this issue appears to be working very well. I have tested against the ~10 articles where I have encountered this bug in the wild and all of them are fixed 💥Bad news
I believe version 2.7.3 also introduced a fairly major regression in the JATS writer. I suspect the bug was introduced in #5511:
I agree that grouping footnotes at the end of the document is better. However, this change created a bug where JATS output fails validation if the document does not contain any footnotes. The specific validation error I am seeing is:
If it's not obvious, that means that
<fn-group>must contain at least one child<fn>. So I assume the fix would requireifcondition or something like that:Finally, I can confirm that when I add a footnote(s) anywhere in the document, the validation error disappears.
Would you like me to create a separate issue for this bug?
jgm commentedon Jun 21, 2019
@mb21 has fixed this regression, thanks for the testing!