Skip to content

Commit 40b5253

Browse files
committed
JATS writer: improve representation of divs
The writer now checks if the element used to represent (non-special) divs has any `<boxed-text>` specific attributes. If it does, the writer keeps wrapping the div contents in a `<boxed-text>`, as it did before. Otherwise, the writer falls back to the more appropriate `<p>` element or simply unwraps the div if the wrapping element wouldn't have any attributes. The new behavior gives better semantic results in most cases, as `<boxed-text>` should be used for text that "is outside the flow of the narrative text", which doesn't apply to most divs. "Special" divs, like those used to mark sections, are not affected by this change.
1 parent 15ddf41 commit 40b5253

4 files changed

Lines changed: 30 additions & 74 deletions

File tree

src/Text/Pandoc/Writers/JATS.hs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -360,11 +360,21 @@ blockToJATS opts (Div (ident,[cls],kvs) bs) | cls `elem` ["fig", "caption", "tab
360360
return $ inTags True cls attr contents
361361
blockToJATS opts (Div (ident,_,kvs) bs) = do
362362
contents <- blocksToJATS opts bs
363-
let attr = [("id", escapeNCName ident) | not (T.null ident)] ++
364-
[("xml:lang",l) | ("lang",l) <- kvs] ++
365-
[(k,v) | (k,v) <- kvs, k `elem` ["specific-use",
366-
"content-type", "orientation", "position"]]
367-
return $ inTags True "boxed-text" attr contents
363+
-- Attributes that are allowed on both @<p>@ and @<boxed-text>@ elements
364+
let generic_attr = [("id", escapeNCName ident) | not (T.null ident)] ++
365+
[("xml:lang",l) | ("lang",l) <- kvs] ++
366+
[(k,v) | (k,v) <- kvs, k `elem` ["specific-use",
367+
"content-type"]]
368+
let boxed_attr = [(k,v) | (k,v) <- kvs, k `elem` ["orientation", "position"]]
369+
let attr = generic_attr <> boxed_attr
370+
return $
371+
if null attr
372+
then contents
373+
else -- The contents must be wrapped in an appropriate element.
374+
let element = if null boxed_attr
375+
then "p"
376+
else "boxed-text"
377+
in inTags True element (generic_attr <> boxed_attr) contents
368378
blockToJATS opts (Header _ _ title) = do
369379
title' <- inlinesToJATS opts (map fixLineBreak title)
370380
return $ inTagsSimple "title" title'

test/writer.jats_archiving

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -576,41 +576,23 @@ These should not be escaped: \$ \\ \&gt; \[ \{</preformat>
576576
<sec id="html-blocks">
577577
<title>HTML Blocks</title>
578578
<p>Simple block on one line:</p>
579-
<boxed-text>
580-
<p>foo</p>
581-
</boxed-text>
579+
<p>foo</p>
582580
<p>And nested without indentation:</p>
583-
<boxed-text>
584-
<boxed-text>
585-
<boxed-text>
586-
<p>foo</p>
587-
</boxed-text>
588-
</boxed-text>
589-
<boxed-text>
590-
<p>bar</p>
591-
</boxed-text>
592-
</boxed-text>
581+
<p>foo</p>
582+
<p>bar</p>
593583
<p>Interpreted markdown in a table:</p>
594584
<p>This is <italic>emphasized</italic></p>
595585
<p>And this is <bold>strong</bold></p>
596586
<p>Here’s a simple block:</p>
597-
<boxed-text>
598-
<p>foo</p>
599-
</boxed-text>
587+
<p>foo</p>
600588
<p>This should be a code block, though:</p>
601589
<preformat>&lt;div&gt;
602590
foo
603591
&lt;/div&gt;</preformat>
604592
<p>As should this:</p>
605593
<preformat>&lt;div&gt;foo&lt;/div&gt;</preformat>
606594
<p>Now, nested:</p>
607-
<boxed-text>
608-
<boxed-text>
609-
<boxed-text>
610-
<p>foo</p>
611-
</boxed-text>
612-
</boxed-text>
613-
</boxed-text>
595+
<p>foo</p>
614596
<p>This should just be an HTML comment:</p>
615597
<p>Multiline:</p>
616598
<p>Code block:</p>

test/writer.jats_articleauthoring

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -573,41 +573,23 @@ These should not be escaped: \$ \\ \&gt; \[ \{</preformat>
573573
<sec id="html-blocks">
574574
<title>HTML Blocks</title>
575575
<p>Simple block on one line:</p>
576-
<boxed-text>
577-
<p>foo</p>
578-
</boxed-text>
576+
<p>foo</p>
579577
<p>And nested without indentation:</p>
580-
<boxed-text>
581-
<boxed-text>
582-
<boxed-text>
583-
<p>foo</p>
584-
</boxed-text>
585-
</boxed-text>
586-
<boxed-text>
587-
<p>bar</p>
588-
</boxed-text>
589-
</boxed-text>
578+
<p>foo</p>
579+
<p>bar</p>
590580
<p>Interpreted markdown in a table:</p>
591581
<p>This is <italic>emphasized</italic></p>
592582
<p>And this is <bold>strong</bold></p>
593583
<p>Here’s a simple block:</p>
594-
<boxed-text>
595-
<p>foo</p>
596-
</boxed-text>
584+
<p>foo</p>
597585
<p>This should be a code block, though:</p>
598586
<preformat>&lt;div&gt;
599587
foo
600588
&lt;/div&gt;</preformat>
601589
<p>As should this:</p>
602590
<preformat>&lt;div&gt;foo&lt;/div&gt;</preformat>
603591
<p>Now, nested:</p>
604-
<boxed-text>
605-
<boxed-text>
606-
<boxed-text>
607-
<p>foo</p>
608-
</boxed-text>
609-
</boxed-text>
610-
</boxed-text>
592+
<p>foo</p>
611593
<p>This should just be an HTML comment:</p>
612594
<p>Multiline:</p>
613595
<p>Code block:</p>

test/writer.jats_publishing

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -576,41 +576,23 @@ These should not be escaped: \$ \\ \&gt; \[ \{</preformat>
576576
<sec id="html-blocks">
577577
<title>HTML Blocks</title>
578578
<p>Simple block on one line:</p>
579-
<boxed-text>
580-
<p>foo</p>
581-
</boxed-text>
579+
<p>foo</p>
582580
<p>And nested without indentation:</p>
583-
<boxed-text>
584-
<boxed-text>
585-
<boxed-text>
586-
<p>foo</p>
587-
</boxed-text>
588-
</boxed-text>
589-
<boxed-text>
590-
<p>bar</p>
591-
</boxed-text>
592-
</boxed-text>
581+
<p>foo</p>
582+
<p>bar</p>
593583
<p>Interpreted markdown in a table:</p>
594584
<p>This is <italic>emphasized</italic></p>
595585
<p>And this is <bold>strong</bold></p>
596586
<p>Here’s a simple block:</p>
597-
<boxed-text>
598-
<p>foo</p>
599-
</boxed-text>
587+
<p>foo</p>
600588
<p>This should be a code block, though:</p>
601589
<preformat>&lt;div&gt;
602590
foo
603591
&lt;/div&gt;</preformat>
604592
<p>As should this:</p>
605593
<preformat>&lt;div&gt;foo&lt;/div&gt;</preformat>
606594
<p>Now, nested:</p>
607-
<boxed-text>
608-
<boxed-text>
609-
<boxed-text>
610-
<p>foo</p>
611-
</boxed-text>
612-
</boxed-text>
613-
</boxed-text>
595+
<p>foo</p>
614596
<p>This should just be an HTML comment:</p>
615597
<p>Multiline:</p>
616598
<p>Code block:</p>

0 commit comments

Comments
 (0)