aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Readers/JATS.hs
diff options
context:
space:
mode:
authordespresc <christian.j.j.despres@gmail.com>2020-03-28 18:22:48 -0400
committerdespresc <christian.j.j.despres@gmail.com>2020-04-15 23:03:22 -0400
commit7254a2ae0ba40b29c04b8924f27739614229432b (patch)
tree114e3143953451e3212511e7bf2e178548d3e1bd /src/Text/Pandoc/Readers/JATS.hs
parent83c1ce1d77d3ef058e4e5c645a8eb0379fab780f (diff)
downloadpandoc-7254a2ae0ba40b29c04b8924f27739614229432b.tar.gz
Implement the new Table type
Diffstat (limited to 'src/Text/Pandoc/Readers/JATS.hs')
-rw-r--r--src/Text/Pandoc/Readers/JATS.hs49
1 files changed, 24 insertions, 25 deletions
diff --git a/src/Text/Pandoc/Readers/JATS.hs b/src/Text/Pandoc/Readers/JATS.hs
index 3672b05f6..3dfe9161b 100644
--- a/src/Text/Pandoc/Readers/JATS.hs
+++ b/src/Text/Pandoc/Readers/JATS.hs
@@ -134,14 +134,14 @@ getGraphic :: PandocMonad m
=> Maybe (Inlines, Text) -> Element -> JATS m Inlines
getGraphic mbfigdata e = do
let atVal a = attrValue a e
- (ident, title, caption) =
+ (ident, title, capt) =
case mbfigdata of
- Just (capt, i) -> (i, "fig:" <> atVal "title", capt)
+ Just (capt', i) -> (i, "fig:" <> atVal "title", capt')
Nothing -> (atVal "id", atVal "title",
text (atVal "alt-text"))
attr = (ident, T.words $ atVal "role", [])
imageUrl = atVal "href"
- return $ imageWith attr imageUrl title caption
+ return $ imageWith attr imageUrl title capt
getBlocks :: PandocMonad m => Element -> JATS m Blocks
getBlocks e = mconcat <$>
@@ -230,20 +230,20 @@ parseBlock (Elem e) =
-- implicit figure. otherwise, we emit a div with the contents
case filterChildren (named "graphic") e of
[g] -> do
- caption <- case filterChild (named "caption") e of
- Just t -> mconcat .
- intersperse linebreak <$>
- mapM getInlines
- (filterChildren (const True) t)
- Nothing -> return mempty
- img <- getGraphic (Just (caption, attrValue "id" e)) g
+ capt <- case filterChild (named "caption") e of
+ Just t -> mconcat .
+ intersperse linebreak <$>
+ mapM getInlines
+ (filterChildren (const True) t)
+ Nothing -> return mempty
+ img <- getGraphic (Just (capt, attrValue "id" e)) g
return $ para img
_ -> divWith (attrValue "id" e, ["fig"], []) <$> getBlocks e
parseTable = do
let isCaption x = named "title" x || named "caption" x
- caption <- case filterChild isCaption e of
- Just t -> getInlines t
- Nothing -> return mempty
+ capt <- case filterChild isCaption e of
+ Just t -> getInlines t
+ Nothing -> return mempty
let e' = fromMaybe e $ filterChild (named "tgroup") e
let isColspec x = named "colspec" x || named "col" x
let colspecs = case filterChild (named "colgroup") e' of
@@ -265,26 +265,25 @@ parseBlock (Elem e) =
Just "right" -> AlignRight
Just "center" -> AlignCenter
_ -> AlignDefault
- let toWidth c = case findAttrText (unqual "colwidth") c of
- Just w -> fromMaybe 0
- $ safeRead $ "0" <> T.filter (\x ->
- isDigit x || x == '.') w
- Nothing -> 0 :: Double
+ let toWidth c = do
+ w <- findAttrText (unqual "colwidth") c
+ n <- safeRead $ "0" <> T.filter (\x -> isDigit x || x == '.') w
+ if n > 0 then Just n else Nothing
let numrows = foldl' max 0 $ map length bodyrows
let aligns = case colspecs of
[] -> replicate numrows AlignDefault
cs -> map toAlignment cs
let widths = case colspecs of
- [] -> replicate numrows 0
- cs -> let ws = map toWidth cs
- tot = sum ws
- in if all (> 0) ws
- then map (/ tot) ws
- else replicate numrows 0
+ [] -> replicate numrows Nothing
+ cs -> let ws = map toWidth cs
+ in case sequence ws of
+ Just ws' -> let tot = sum ws'
+ in Just . (/ tot) <$> ws'
+ Nothing -> replicate numrows Nothing
let headrows' = if null headrows
then replicate numrows mempty
else headrows
- return $ table caption (zip aligns widths)
+ return $ table capt (zip aligns widths)
headrows' bodyrows
isEntry x = named "entry" x || named "td" x || named "th" x
parseRow = mapM (parseMixed plain . elContent) . filterChildren isEntry