Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove extraneous, significant whitespace in JATS writer output #4335

Merged
merged 8 commits into from
Mar 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/Text/Pandoc/Writers/JATS.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

Conversion of 'Pandoc' documents to JATS XML.
Reference:
https://jats.nlm.nih.gov/publishing/tag-library/1.1d3/element/mml-math.html
https://jats.nlm.nih.gov/publishing/tag-library
-}
module Text.Pandoc.Writers.JATS ( writeJATS ) where
import Control.Monad.Reader
Expand Down Expand Up @@ -139,7 +139,7 @@ deflistItemToJATS opts term defs = do
term' <- inlinesToJATS opts term
def' <- blocksToJATS opts $ concatMap (map plainToPara) defs
return $ inTagsIndented "def-item" $
inTagsIndented "term" term' $$
inTagsSimple "term" term' $$
inTagsIndented "def" def'

-- | Convert a list of lists of blocks to a list of JATS list items.
Expand All @@ -156,7 +156,7 @@ listItemToJATS :: PandocMonad m
listItemToJATS opts mbmarker item = do
contents <- blocksToJATS opts item
return $ inTagsIndented "list-item" $
maybe empty (\lbl -> inTagsIndented "label" (text lbl)) mbmarker
maybe empty (\lbl -> inTagsSimple "label" (text lbl)) mbmarker
$$ contents

imageMimeType :: String -> [(String, String)] -> (String, String)
Expand Down Expand Up @@ -250,7 +250,7 @@ blockToJATS _ (Para [Image (ident,_,kvs) _ (src, tit)]) = do
"xlink:type"]]
return $ selfClosingTag "graphic" attr
blockToJATS opts (Para lst) =
inTagsIndented "p" <$> inlinesToJATS opts lst
inTagsSimple "p" <$> inlinesToJATS opts lst
blockToJATS opts (LineBlock lns) =
blockToJATS opts $ linesToPara lns
blockToJATS opts (BlockQuote blocks) =
Expand Down Expand Up @@ -326,10 +326,10 @@ tableItemToJATS :: PandocMonad m
-> [Block]
-> JATS m Doc
tableItemToJATS opts isHeader [Plain item] =
inTags True (if isHeader then "th" else "td") [] <$>
inTags False (if isHeader then "th" else "td") [] <$>
inlinesToJATS opts item
tableItemToJATS opts isHeader item =
(inTags True (if isHeader then "th" else "td") [] . vcat) <$>
(inTags False (if isHeader then "th" else "td") [] . vcat) <$>
mapM (blockToJATS opts) item

-- | Convert a list of inline elements to JATS.
Expand Down
38 changes: 12 additions & 26 deletions test/Tests/Writers/JATS.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ infix 4 =:

tests :: [TestTree]
tests = [ testGroup "inline code"
[ "basic" =: code "@&" =?> "<p>\n <monospace>@&amp;</monospace>\n</p>"
, "lang" =: codeWith ("", ["c"], []) "@&" =?> "<p>\n <code language=\"c\">@&amp;</code>\n</p>"
[ "basic" =: code "@&" =?> "<p><monospace>@&amp;</monospace></p>"
, "lang" =: codeWith ("", ["c"], []) "@&" =?> "<p><code language=\"c\">@&amp;</code></p>"
]
, testGroup "block code"
[ "basic" =: codeBlock "@&" =?> "<preformat>@&amp;</preformat>"
Expand All @@ -44,62 +44,48 @@ tests = [ testGroup "inline code"
]
, testGroup "inlines"
[ "Emphasis" =: emph "emphasized"
=?> "<p>\n <italic>emphasized</italic>\n</p>"
=?> "<p><italic>emphasized</italic></p>"
]
, "bullet list" =: bulletList [ plain $ text "first"
, plain $ text "second"
, plain $ text "third"
]
=?> "<list list-type=\"bullet\">\n\
\ <list-item>\n\
\ <p>\n\
\ first\n\
\ </p>\n\
\ <p>first</p>\n\
\ </list-item>\n\
\ <list-item>\n\
\ <p>\n\
\ second\n\
\ </p>\n\
\ <p>second</p>\n\
\ </list-item>\n\
\ <list-item>\n\
\ <p>\n\
\ third\n\
\ </p>\n\
\ <p>third</p>\n\
\ </list-item>\n\
\</list>"
, testGroup "definition lists"
[ "with internal link" =: definitionList [(link "#go" "" (str "testing"),
[plain (text "hi there")])] =?>
"<def-list>\n\
\ <def-item>\n\
\ <term>\n\
\ <xref alt=\"testing\" rid=\"go\">testing</xref>\n\
\ </term>\n\
\ <term><xref alt=\"testing\" rid=\"go\">testing</xref></term>\n\
\ <def>\n\
\ <p>\n\
\ hi there\n\
\ </p>\n\
\ <p>hi there</p>\n\
\ </def>\n\
\ </def-item>\n\
\</def-list>"
]
, testGroup "math"
[ "escape |" =: para (math "\\sigma|_{\\{x\\}}") =?>
"<p>\n\
\ <inline-formula><alternatives>\n\
\ <tex-math><![CDATA[\\sigma|_{\\{x\\}}]]></tex-math>\n\
\ <mml:math display=\"inline\" xmlns:mml=\"http://www.w3.org/1998/Math/MathML\"><mml:mrow><mml:mi>σ</mml:mi><mml:msub><mml:mo stretchy=\"false\" form=\"prefix\">|</mml:mo><mml:mrow><mml:mo stretchy=\"false\" form=\"prefix\">{</mml:mo><mml:mi>x</mml:mi><mml:mo stretchy=\"false\" form=\"postfix\">}</mml:mo></mml:mrow></mml:msub></mml:mrow></mml:math></alternatives></inline-formula>\n\
\</p>"
"<p><inline-formula><alternatives>\n\
\<tex-math><![CDATA[\\sigma|_{\\{x\\}}]]></tex-math>\n\
\<mml:math display=\"inline\" xmlns:mml=\"http://www.w3.org/1998/Math/MathML\"><mml:mrow><mml:mi>σ</mml:mi><mml:msub><mml:mo stretchy=\"false\" form=\"prefix\">|</mml:mo><mml:mrow><mml:mo stretchy=\"false\" form=\"prefix\">{</mml:mo><mml:mi>x</mml:mi><mml:mo stretchy=\"false\" form=\"postfix\">}</mml:mo></mml:mrow></mml:msub></mml:mrow></mml:math></alternatives></inline-formula></p>"
]
, testGroup "headers"
[ "unnumbered header" =:
headerWith ("foo",["unnumbered"],[]) 1
(text "Header 1" <> note (plain $ text "note")) =?>
"<sec id=\"foo\">\n\
\ <title>Header 1<fn>\n\
\ <p>\n\
\ note\n\
\ </p>\n\
\ <p>note</p>\n\
\ </fn></title>\n\
\</sec>"
, "unnumbered sub header" =:
Expand Down
4 changes: 2 additions & 2 deletions test/jats-reader.native
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Pandoc (Meta {unMeta = fromList [("author",MetaList [MetaInlines [Str "John",Space,Str "MacFarlane"]]),("title",MetaInlines [Str "Pandoc",Space,Str "Test",Space,Str "Suite"])]})
[Para [Str "This",Space,Str "is",Space,Str "a",Space,Str "set",Space,Str "of",Space,Str "tests",Space,Str "for",Space,Str "pandoc.",Space,Str "Most",Space,Str "of",Space,Str "them",Space,Str "are",Space,Str "adapted",Space,Str "from",Space,Str "John",SoftBreak,Str "Gruber's",Space,Str "markdown",Space,Str "test",Space,Str "suite."]
[Para [Str "This",Space,Str "is",Space,Str "a",Space,Str "set",Space,Str "of",Space,Str "tests",Space,Str "for",Space,Str "pandoc.",Space,Str "Most",Space,Str "of",Space,Str "them",Space,Str "are",Space,Str "adapted",Space,Str "from",Space,Str "John",Space,Str "Gruber's",Space,Str "markdown",Space,Str "test",Space,Str "suite."]
,Header 1 ("headers",[],[]) [Str "Headers"]
,Header 2 ("level-2-with-an-embedded-link",[],[]) [Str "Level",Space,Str "2",Space,Str "with",Space,Str "an",SoftBreak,Link ("",[],[]) [Str "embedded",SoftBreak,Str "link"] ("/url","")]
,Header 3 ("level-3-with-emphasis",[],[]) [Str "Level",Space,Str "3",Space,Str "with",Space,Emph [Str "emphasis"]]
Expand All @@ -13,7 +13,7 @@ Pandoc (Meta {unMeta = fromList [("author",MetaList [MetaInlines [Str "John",Spa
,Para [Str "with",Space,Str "no",Space,Str "blank",Space,Str "line"]
,Header 1 ("paragraphs",[],[]) [Str "Paragraphs"]
,Para [Str "Here's",Space,Str "a",Space,Str "regular",Space,Str "paragraph."]
,Para [Str "In",Space,Str "Markdown",Space,Str "1.0.0",Space,Str "and",Space,Str "earlier.",Space,Str "Version",Space,Str "8.",Space,Str "This",Space,Str "line",Space,Str "turns",Space,Str "into",Space,Str "a",SoftBreak,Str "list",Space,Str "item.",Space,Str "Because",Space,Str "a",Space,Str "hard-wrapped",Space,Str "line",Space,Str "in",Space,Str "the",Space,Str "middle",Space,Str "of",Space,Str "a",Space,Str "paragraph",SoftBreak,Str "looked",Space,Str "like",Space,Str "a",Space,Str "list",Space,Str "item."]
,Para [Str "In",Space,Str "Markdown",Space,Str "1.0.0",Space,Str "and",Space,Str "earlier.",Space,Str "Version",Space,Str "8.",Space,Str "This",Space,Str "line",Space,Str "turns",Space,Str "into",Space,Str "a",Space,Str "list",Space,Str "item.",Space,Str "Because",Space,Str "a",Space,Str "hard-wrapped",Space,Str "line",Space,Str "in",Space,Str "the",Space,Str "middle",Space,Str "of",Space,Str "a",Space,Str "paragraph",Space,Str "looked",Space,Str "like",Space,Str "a",Space,Str "list",Space,Str "item."]
,Para [Str "Here's",Space,Str "one",Space,Str "with",Space,Str "a",Space,Str "bullet.",Space,Str "*",Space,Str "criminey."]
,Para [Str "There",Space,Str "should",Space,Str "be",Space,Str "a",Space,Str "hard",Space,Str "line",Space,Str "break",LineBreak,Str "here."]
,Header 1 ("block-quotes",[],[]) [Str "Block",Space,Str "Quotes"]
Expand Down
Loading