diff options
| -rw-r--r-- | src/Text/Pandoc/Writers/JATS.hs | 13 | ||||
| -rw-r--r-- | src/Text/Pandoc/Writers/JATS/Table.hs | 7 | ||||
| -rw-r--r-- | test/command/8344.md | 90 | ||||
| -rw-r--r-- | test/tables/nordics.jats_archiving | 6 |
4 files changed, 109 insertions, 7 deletions
diff --git a/src/Text/Pandoc/Writers/JATS.hs b/src/Text/Pandoc/Writers/JATS.hs index 7847f2bda..b9ecafa0e 100644 --- a/src/Text/Pandoc/Writers/JATS.hs +++ b/src/Text/Pandoc/Writers/JATS.hs @@ -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) diff --git a/src/Text/Pandoc/Writers/JATS/Table.hs b/src/Text/Pandoc/Writers/JATS/Table.hs index 56aef3b87..7f0c614d0 100644 --- a/src/Text/Pandoc/Writers/JATS/Table.hs +++ b/src/Text/Pandoc/Writers/JATS/Table.hs @@ -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" diff --git a/test/command/8344.md b/test/command/8344.md new file mode 100644 index 000000000..c95c75aab --- /dev/null +++ b/test/command/8344.md @@ -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> +``` diff --git a/test/tables/nordics.jats_archiving b/test/tables/nordics.jats_archiving index 5ac78bacd..29bf2e837 100644 --- a/test/tables/nordics.jats_archiving +++ b/test/tables/nordics.jats_archiving @@ -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> |
