Skip to content

Commit

Permalink
Add provision for title
Browse files Browse the repository at this point in the history
  • Loading branch information
kamoe committed Oct 15, 2023
1 parent 86955cf commit 3761b15
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions src/Text/Pandoc/Readers/JATS.hs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ parseBlock (CRef x) = return $ plain $ str $ T.toUpper x
parseBlock (Elem e) = do
sectionLevel <- gets jatsSectionLevel
let parseBlockWithHeader = wrapWithHeader (sectionLevel+1) (getBlocks e)

case qName (elName e) of
"book" -> parseBook
"book-part-wrapper" -> parseBook
Expand Down Expand Up @@ -237,6 +237,9 @@ parseBlock (Elem e) = do
"toc-entry" -> parseBlockWithHeader
"toc-group" -> parseBlockWithHeader
"legend" -> parseBlockWithHeader
"dedication" -> parseBlockWithHeader
"foreword" -> parseBlockWithHeader
"preface" -> parseBlockWithHeader
"?xml" -> return mempty
_ -> getBlocks e
where parseMixed container conts = do
Expand Down Expand Up @@ -382,19 +385,28 @@ parseBlock (Elem e) = do
parseElement = filterChildren isEntry
wrapWithHeader n mBlocks = do
isBook <- gets jatsBook
let n' = if isBook || n == 0 then n + 1 else n
let n' = case (filterChild (named "title") e >>= maybeAttrValue "display-as") of
Just t -> read $ T.unpack t
Nothing -> if isBook || n == 0 then n + 1 else n
headerText <- case filterChild (named "title") e of
Just t -> getInlines t
Nothing -> return mempty
Just t -> case maybeAttrValue "supress" t of
Just s -> if s == "no"
then getInlines t
else return mempty
Nothing -> getInlines t
Nothing -> do
let name = qName (elName e)
if (name == "dedication" || name == "foreword" || name == "preface")
then return $ str $ T.toUpper name
else return mempty
oldN <- gets jatsSectionLevel
modify $ \st -> st{ jatsSectionLevel = n }
blocks <- mBlocks
let ident = attrValue "id" e
modify $ \st -> st{ jatsSectionLevel = oldN }
return $ (if
headerText == mempty
then mempty
else headerWith (ident,[],[]) n' headerText) <> blocks
return $ (if headerText == mempty
then mempty
else headerWith (ident,[],[]) n' headerText) <> blocks
parseBook = do
modify $ \st -> st{ jatsBook = True }
getBlocks e
Expand Down

0 comments on commit 3761b15

Please sign in to comment.