JATS writer: use <break/> for LineBreak...

in the limited contexts that accept it.

Closes #8344.
This commit is contained in:
John MacFarlane
2022-10-01 17:46:13 -07:00
parent 89e7e9b636
commit dd07d8002f
4 changed files with 109 additions and 7 deletions
+11 -2
View File
@@ -135,8 +135,11 @@ docToJATS opts (Pandoc meta blocks) = do
formatTime defaultTimeLocale "%F" day)
]
Just x -> x
title' <- inlinesToJATS opts $ map fixLineBreak
(lookupMetaInlines "title" meta)
let context = defField "body" main
$ defField "back" back
$ resetField "title" title'
$ resetField "date" date
$ defField "mathml" (case writerHTMLMathMethod opts of
MathML -> True
@@ -249,6 +252,12 @@ codeAttr opts (ident,classes,kvs) = (lang, attr)
"platforms", "position", "specific-use"]]
lang = languageFor opts classes
-- <break/> is only allowed as a direct child of <td> or <title> or
-- <article-title>
fixLineBreak :: Inline -> Inline
fixLineBreak LineBreak = RawInline (Format "jats") "<break/>"
fixLineBreak x = x
-- | Convert a Pandoc block element to JATS.
blockToJATS :: PandocMonad m => WriterOptions -> Block -> JATS m (Doc Text)
blockToJATS _ Null = return empty
@@ -257,7 +266,7 @@ blockToJATS opts (Div (id',"section":_,kvs) (Header _lvl _ ils : xs)) = do
| not (T.null id')]
let otherAttrs = ["sec-type", "specific-use"]
let attribs = idAttr ++ [(k,v) | (k,v) <- kvs, k `elem` otherAttrs]
title' <- inlinesToJATS opts ils
title' <- inlinesToJATS opts (map fixLineBreak ils)
contents <- blocksToJATS opts xs
return $ inTags True "sec" attribs $
inTagsSimple "title" title' $$ contents
@@ -287,7 +296,7 @@ blockToJATS opts (Div (ident,_,kvs) bs) = do
"content-type", "orientation", "position"]]
return $ inTags True "boxed-text" attr contents
blockToJATS opts (Header _ _ title) = do
title' <- inlinesToJATS opts title
title' <- inlinesToJATS opts (map fixLineBreak title)
return $ inTagsSimple "title" title'
-- No Plain, everything needs to be in a block-level tag
blockToJATS opts (Plain lst) = blockToJATS opts (Para lst)
+6 -1
View File
@@ -234,8 +234,13 @@ tableCellToJats :: PandocMonad m
tableCellToJats opts ctype colAlign (Cell attr align rowspan colspan item) = do
blockToJats <- asks jatsBlockWriter
inlinesToJats <- asks jatsInlinesWriter
let fixBreak LineBreak = RawInline (Format "jats") "<break/>"
fixBreak x = x
let cellContents = \case
[Plain inlines] -> inlinesToJats opts inlines
[Plain inlines] -> inlinesToJats opts
(map fixBreak inlines)
-- Note: <break/> is allowed only as a direct
-- child of <td>, so we don't use walk.
blocks -> blockToJats needsWrapInCell opts blocks
let tag' = case ctype of
BodyCell -> "td"
+90
View File
@@ -0,0 +1,90 @@
```
% pandoc -t jats -s
---
title: |-
My\
document
...
# Section\
with line break
Paragraph\
with line break
--------
A B
--- ---
1\ 3
2 4
*1\ 5\
2* 6
7
--------
^D
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.2 20190208//EN"
"JATS-archivearticle1.dtd">
<article xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:xlink="http://www.w3.org/1999/xlink" dtd-version="1.2" article-type="other">
<front>
<journal-meta>
<journal-id></journal-id>
<journal-title-group>
</journal-title-group>
<issn></issn>
<publisher>
<publisher-name></publisher-name>
</publisher>
</journal-meta>
<article-meta>
<title-group>
<article-title>My<break/>document</article-title>
</title-group>
<permissions>
</permissions>
</article-meta>
</front>
<body>
<sec id="section">
<title>Section<break/></title>
<p>with line break</p>
<p>Paragraph
with line break</p>
<table-wrap>
<table>
<colgroup>
<col width="7%" />
<col width="7%" />
</colgroup>
<thead>
<tr>
<th align="left">A</th>
<th align="left">B</th>
</tr>
</thead>
<tbody>
<tr>
<td align="left">1<break/>2</td>
<td align="left">3 4</td>
</tr>
<tr>
<td align="left"><italic>1
2</italic></td>
<td align="left">5<break/>6</td>
</tr>
<tr>
<td align="left"></td>
<td align="left">7</td>
</tr>
</tbody>
</table>
</table-wrap>
</sec>
</body>
<back>
</back>
</article>
```
+2 -4
View File
@@ -13,10 +13,8 @@
<tr>
<th align="center">Name</th>
<th align="center">Capital</th>
<th align="center">Population
(in 2018)</th>
<th align="center">Area
(in km<sup>2</sup>)</th>
<th align="center">Population<break/>(in 2018)</th>
<th align="center">Area<break/>(in km<sup>2</sup>)</th>
</tr>
</thead>
<tfoot>