{-# LANGUAGE OverloadedStrings #-}
module Text.Pandoc.Readers.DocBook ( readDocBook ) where
import Control.Monad.State.Strict
import Data.Char (isSpace, toUpper)
import Data.Default
import Data.Either (rights)
import Data.Foldable (asum)
import Data.Generics
import Data.List (intersperse,elemIndex)
import Data.Maybe (fromMaybe,mapMaybe)
import Data.Text (Text)
import qualified Data.Text as T
import Text.HTML.TagSoup.Entity (lookupEntity)
import Text.Pandoc.Builder
import Text.Pandoc.Class.PandocMonad (PandocMonad, report)
import Text.Pandoc.Options
import Text.Pandoc.Logging (LogMessage(..))
import Text.Pandoc.Shared (crFilter, safeRead, extractSpaces)
import Text.TeXMath (readMathML, writeTeX)
import Text.XML.Light
type DB m = StateT DBState m
data DBState = DBState{ DBState -> Int
dbSectionLevel :: Int
, DBState -> QuoteType
dbQuoteType :: QuoteType
, DBState -> Meta
dbMeta :: Meta
, DBState -> Bool
dbBook :: Bool
, DBState -> Inlines
dbFigureTitle :: Inlines
, DBState -> Text
dbFigureId :: Text
, DBState -> [Content]
dbContent :: [Content]
} deriving Int -> DBState -> ShowS
[DBState] -> ShowS
DBState -> String
(Int -> DBState -> ShowS)
-> (DBState -> String) -> ([DBState] -> ShowS) -> Show DBState
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DBState] -> ShowS
$cshowList :: [DBState] -> ShowS
show :: DBState -> String
$cshow :: DBState -> String
showsPrec :: Int -> DBState -> ShowS
$cshowsPrec :: Int -> DBState -> ShowS
Show
instance Default DBState where
def :: DBState
def = DBState :: Int
-> QuoteType
-> Meta
-> Bool
-> Inlines
-> Text
-> [Content]
-> DBState
DBState{ dbSectionLevel :: Int
dbSectionLevel = Int
0
, dbQuoteType :: QuoteType
dbQuoteType = QuoteType
DoubleQuote
, dbMeta :: Meta
dbMeta = Meta
forall a. Monoid a => a
mempty
, dbBook :: Bool
dbBook = Bool
False
, dbFigureTitle :: Inlines
dbFigureTitle = Inlines
forall a. Monoid a => a
mempty
, dbFigureId :: Text
dbFigureId = Text
forall a. Monoid a => a
mempty
, dbContent :: [Content]
dbContent = [] }
readDocBook :: PandocMonad m => ReaderOptions -> Text -> m Pandoc
readDocBook :: ReaderOptions -> Text -> m Pandoc
readDocBook ReaderOptions
_ Text
inp = do
let tree :: [Content]
tree = [Content] -> [Content]
normalizeTree ([Content] -> [Content])
-> (Text -> [Content]) -> Text -> [Content]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> [Content]
forall s. XmlSource s => s -> [Content]
parseXML (Text -> [Content]) -> (Text -> Text) -> Text -> [Content]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text
handleInstructions (Text -> [Content]) -> Text -> [Content]
forall a b. (a -> b) -> a -> b
$ Text -> Text
crFilter Text
inp
([Blocks]
bs, DBState
st') <- (StateT DBState m [Blocks] -> DBState -> m ([Blocks], DBState))
-> DBState -> StateT DBState m [Blocks] -> m ([Blocks], DBState)
forall a b c. (a -> b -> c) -> b -> a -> c
flip StateT DBState m [Blocks] -> DBState -> m ([Blocks], DBState)
forall s (m :: * -> *) a. StateT s m a -> s -> m (a, s)
runStateT (DBState
forall a. Default a => a
def{ dbContent :: [Content]
dbContent = [Content]
tree }) (StateT DBState m [Blocks] -> m ([Blocks], DBState))
-> StateT DBState m [Blocks] -> m ([Blocks], DBState)
forall a b. (a -> b) -> a -> b
$ (Content -> StateT DBState m Blocks)
-> [Content] -> StateT DBState m [Blocks]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM Content -> StateT DBState m Blocks
forall (m :: * -> *). PandocMonad m => Content -> DB m Blocks
parseBlock [Content]
tree
Pandoc -> m Pandoc
forall (m :: * -> *) a. Monad m => a -> m a
return (Pandoc -> m Pandoc) -> Pandoc -> m Pandoc
forall a b. (a -> b) -> a -> b
$ Meta -> [Block] -> Pandoc
Pandoc (DBState -> Meta
dbMeta DBState
st') (Blocks -> [Block]
forall a. Many a -> [a]
toList (Blocks -> [Block]) -> ([Blocks] -> Blocks) -> [Blocks] -> [Block]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Blocks] -> Blocks
forall a. Monoid a => [a] -> a
mconcat ([Blocks] -> [Block]) -> [Blocks] -> [Block]
forall a b. (a -> b) -> a -> b
$ [Blocks]
bs)
handleInstructions :: Text -> Text
handleInstructions :: Text -> Text
handleInstructions = String -> Text
T.pack (String -> Text) -> (Text -> String) -> Text -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShowS
handleInstructions' ShowS -> (Text -> String) -> Text -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> String
T.unpack
handleInstructions' :: String -> String
handleInstructions' :: ShowS
handleInstructions' (Char
'<':Char
'?':Char
'a':Char
's':Char
'c':Char
'i':Char
'i':Char
'd':Char
'o':Char
'c':Char
'-':Char
'b':Char
'r':Char
'?':Char
'>':String
xs) = Char
'<'Char -> ShowS
forall a. a -> [a] -> [a]
:Char
'b'Char -> ShowS
forall a. a -> [a] -> [a]
:Char
'r'Char -> ShowS
forall a. a -> [a] -> [a]
:Char
'/'Char -> ShowS
forall a. a -> [a] -> [a]
:Char
'>'Char -> ShowS
forall a. a -> [a] -> [a]
: ShowS
handleInstructions' String
xs
handleInstructions' String
xs = case (Char -> Bool) -> String -> (String, String)
forall a. (a -> Bool) -> [a] -> ([a], [a])
break (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
==Char
'<') String
xs of
(String
ys, []) -> String
ys
([], Char
'<':String
zs) -> Char
'<' Char -> ShowS
forall a. a -> [a] -> [a]
: ShowS
handleInstructions' String
zs
(String
ys, String
zs) -> String
ys String -> ShowS
forall a. [a] -> [a] -> [a]
++ ShowS
handleInstructions' String
zs
getFigure :: PandocMonad m => Element -> DB m Blocks
getFigure :: Element -> DB m Blocks
getFigure Element
e = do
Inlines
tit <- case (Element -> Bool) -> Element -> Maybe Element
filterChild (Text -> Element -> Bool
named Text
"title") Element
e of
Just Element
t -> Element -> StateT DBState m Inlines
forall (m :: * -> *). PandocMonad m => Element -> DB m Inlines
getInlines Element
t
Maybe Element
Nothing -> Inlines -> StateT DBState m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return Inlines
forall a. Monoid a => a
mempty
let ident :: Text
ident = String -> Element -> Text
attrValue String
"id" Element
e
(DBState -> DBState) -> StateT DBState m ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify ((DBState -> DBState) -> StateT DBState m ())
-> (DBState -> DBState) -> StateT DBState m ()
forall a b. (a -> b) -> a -> b
$ \DBState
st -> DBState
st{ dbFigureTitle :: Inlines
dbFigureTitle = Inlines
tit, dbFigureId :: Text
dbFigureId = Text
ident }
Blocks
res <- Element -> DB m Blocks
forall (m :: * -> *). PandocMonad m => Element -> DB m Blocks
getBlocks Element
e
(DBState -> DBState) -> StateT DBState m ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify ((DBState -> DBState) -> StateT DBState m ())
-> (DBState -> DBState) -> StateT DBState m ()
forall a b. (a -> b) -> a -> b
$ \DBState
st -> DBState
st{ dbFigureTitle :: Inlines
dbFigureTitle = Inlines
forall a. Monoid a => a
mempty, dbFigureId :: Text
dbFigureId = Text
forall a. Monoid a => a
mempty }
Blocks -> DB m Blocks
forall (m :: * -> *) a. Monad m => a -> m a
return Blocks
res
normalizeTree :: [Content] -> [Content]
normalizeTree :: [Content] -> [Content]
normalizeTree = (forall a. Data a => a -> a) -> forall a. Data a => a -> a
everywhere (([Content] -> [Content]) -> a -> a
forall a b. (Typeable a, Typeable b) => (b -> b) -> a -> a
mkT [Content] -> [Content]
go)
where go :: [Content] -> [Content]
go :: [Content] -> [Content]
go (Text (CData CDataKind
CDataRaw String
_ Maybe Line
_):[Content]
xs) = [Content]
xs
go (Text (CData CDataKind
CDataText String
s1 Maybe Line
z):Text (CData CDataKind
CDataText String
s2 Maybe Line
_):[Content]
xs) =
CData -> Content
Text (CDataKind -> String -> Maybe Line -> CData
CData CDataKind
CDataText (String
s1 String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
s2) Maybe Line
z)Content -> [Content] -> [Content]
forall a. a -> [a] -> [a]
:[Content]
xs
go (Text (CData CDataKind
CDataText String
s1 Maybe Line
z):CRef String
r:[Content]
xs) =
CData -> Content
Text (CDataKind -> String -> Maybe Line -> CData
CData CDataKind
CDataText (String
s1 String -> ShowS
forall a. [a] -> [a] -> [a]
++ ShowS
convertEntity String
r) Maybe Line
z)Content -> [Content] -> [Content]
forall a. a -> [a] -> [a]
:[Content]
xs
go (CRef String
r:Text (CData CDataKind
CDataText String
s1 Maybe Line
z):[Content]
xs) =
CData -> Content
Text (CDataKind -> String -> Maybe Line -> CData
CData CDataKind
CDataText (ShowS
convertEntity String
r String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
s1) Maybe Line
z)Content -> [Content] -> [Content]
forall a. a -> [a] -> [a]
:[Content]
xs
go (CRef String
r1:CRef String
r2:[Content]
xs) =
CData -> Content
Text (CDataKind -> String -> Maybe Line -> CData
CData CDataKind
CDataText (ShowS
convertEntity String
r1 String -> ShowS
forall a. [a] -> [a] -> [a]
++ ShowS
convertEntity String
r2) Maybe Line
forall a. Maybe a
Nothing)Content -> [Content] -> [Content]
forall a. a -> [a] -> [a]
:[Content]
xs
go [Content]
xs = [Content]
xs
convertEntity :: String -> String
convertEntity :: ShowS
convertEntity String
e = String -> Maybe String -> String
forall a. a -> Maybe a -> a
Data.Maybe.fromMaybe ((Char -> Char) -> ShowS
forall a b. (a -> b) -> [a] -> [b]
map Char -> Char
toUpper String
e) (String -> Maybe String
lookupEntity String
e)
attrValue :: String -> Element -> Text
attrValue :: String -> Element -> Text
attrValue String
attr Element
elt =
Text -> (String -> Text) -> Maybe String -> Text
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Text
"" String -> Text
T.pack ((QName -> Bool) -> [Attr] -> Maybe String
lookupAttrBy (\QName
x -> QName -> String
qName QName
x String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== String
attr) (Element -> [Attr]
elAttribs Element
elt))
named :: Text -> Element -> Bool
named :: Text -> Element -> Bool
named Text
s Element
e = QName -> String
qName (Element -> QName
elName Element
e) String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== Text -> String
T.unpack Text
s
addMetadataFromElement :: PandocMonad m => Element -> DB m Blocks
addMetadataFromElement :: Element -> DB m Blocks
addMetadataFromElement Element
e = do
case (Element -> Bool) -> Element -> Maybe Element
filterChild (Text -> Element -> Bool
named Text
"title") Element
e of
Maybe Element
Nothing -> () -> StateT DBState m ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
Just Element
z -> do
Element -> DB m Inlines
forall (m :: * -> *). PandocMonad m => Element -> DB m Inlines
getInlines Element
z DB m Inlines
-> (Inlines -> StateT DBState m ()) -> StateT DBState m ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Text -> Inlines -> StateT DBState m ()
forall (m :: * -> *) a.
(PandocMonad m, ToMetaValue a) =>
Text -> a -> DB m ()
addMeta Text
"title"
Text -> Element -> StateT DBState m ()
forall (m :: * -> *).
PandocMonad m =>
Text -> Element -> StateT DBState m ()
addMetaField Text
"subtitle" Element
z
case (Element -> Bool) -> Element -> Maybe Element
filterChild (Text -> Element -> Bool
named Text
"authorgroup") Element
e of
Maybe Element
Nothing -> () -> StateT DBState m ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
Just Element
z -> Text -> Element -> StateT DBState m ()
forall (m :: * -> *).
PandocMonad m =>
Text -> Element -> StateT DBState m ()
addMetaField Text
"author" Element
z
Text -> Element -> StateT DBState m ()
forall (m :: * -> *).
PandocMonad m =>
Text -> Element -> StateT DBState m ()
addMetaField Text
"subtitle" Element
e
Text -> Element -> StateT DBState m ()
forall (m :: * -> *).
PandocMonad m =>
Text -> Element -> StateT DBState m ()
addMetaField Text
"author" Element
e
Text -> Element -> StateT DBState m ()
forall (m :: * -> *).
PandocMonad m =>
Text -> Element -> StateT DBState m ()
addMetaField Text
"date" Element
e
Text -> Element -> StateT DBState m ()
forall (m :: * -> *).
PandocMonad m =>
Text -> Element -> StateT DBState m ()
addMetaField Text
"release" Element
e
Text -> Element -> StateT DBState m ()
forall (m :: * -> *).
PandocMonad m =>
Text -> Element -> StateT DBState m ()
addMetaField Text
"releaseinfo" Element
e
Blocks -> DB m Blocks
forall (m :: * -> *) a. Monad m => a -> m a
return Blocks
forall a. Monoid a => a
mempty
where addMetaField :: Text -> Element -> StateT DBState m ()
addMetaField Text
fieldname Element
elt =
case (Element -> Bool) -> Element -> [Element]
filterChildren (Text -> Element -> Bool
named Text
fieldname) Element
elt of
[] -> () -> StateT DBState m ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
[Element
z] -> Element -> DB m Inlines
forall (m :: * -> *). PandocMonad m => Element -> DB m Inlines
getInlines Element
z DB m Inlines
-> (Inlines -> StateT DBState m ()) -> StateT DBState m ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Text -> Inlines -> StateT DBState m ()
forall (m :: * -> *) a.
(PandocMonad m, ToMetaValue a) =>
Text -> a -> DB m ()
addMeta Text
fieldname
[Element]
zs -> (Element -> DB m Inlines)
-> [Element] -> StateT DBState m [Inlines]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM Element -> DB m Inlines
forall (m :: * -> *). PandocMonad m => Element -> DB m Inlines
getInlines [Element]
zs StateT DBState m [Inlines]
-> ([Inlines] -> StateT DBState m ()) -> StateT DBState m ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Text -> [Inlines] -> StateT DBState m ()
forall (m :: * -> *) a.
(PandocMonad m, ToMetaValue a) =>
Text -> a -> DB m ()
addMeta Text
fieldname
addMeta :: PandocMonad m => ToMetaValue a => Text -> a -> DB m ()
addMeta :: Text -> a -> DB m ()
addMeta Text
field a
val = (DBState -> DBState) -> DB m ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify (Text -> a -> DBState -> DBState
forall a b. (HasMeta a, ToMetaValue b) => Text -> b -> a -> a
setMeta Text
field a
val)
instance HasMeta DBState where
setMeta :: Text -> b -> DBState -> DBState
setMeta Text
field b
v DBState
s = DBState
s {dbMeta :: Meta
dbMeta = Text -> b -> Meta -> Meta
forall a b. (HasMeta a, ToMetaValue b) => Text -> b -> a -> a
setMeta Text
field b
v (DBState -> Meta
dbMeta DBState
s)}
deleteMeta :: Text -> DBState -> DBState
deleteMeta Text
field DBState
s = DBState
s {dbMeta :: Meta
dbMeta = Text -> Meta -> Meta
forall a. HasMeta a => Text -> a -> a
deleteMeta Text
field (DBState -> Meta
dbMeta DBState
s)}
isBlockElement :: Content -> Bool
isBlockElement :: Content -> Bool
isBlockElement (Elem Element
e) = QName -> String
qName (Element -> QName
elName Element
e) String -> [String] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [String]
blockTags
isBlockElement Content
_ = Bool
False
blockTags :: [String]
blockTags :: [String]
blockTags =
[ String
"abstract"
, String
"ackno"
, String
"answer"
, String
"appendix"
, String
"appendixinfo"
, String
"area"
, String
"areaset"
, String
"areaspec"
, String
"article"
, String
"articleinfo"
, String
"attribution"
, String
"authorinitials"
, String
"bibliodiv"
, String
"biblioentry"
, String
"bibliography"
, String
"bibliomisc"
, String
"bibliomixed"
, String
"blockquote"
, String
"book"
, String
"bookinfo"
, String
"bridgehead"
, String
"calloutlist"
, String
"caption"
, String
"chapter"
, String
"chapterinfo"
, String
"epigraph"
, String
"example"
, String
"figure"
, String
"formalpara"
, String
"glossary"
, String
"glossaryinfo"
, String
"glossdiv"
, String
"glossee"
, String
"glosseealso"
, String
"glosslist"
, String
"glosssee"
, String
"glossseealso"
, String
"index"
, String
"info"
, String
"informalexample"
, String
"informaltable"
, String
"itemizedlist"
, String
"linegroup"
, String
"literallayout"
, String
"mediaobject"
, String
"orderedlist"
, String
"para"
, String
"preface"
, String
"procedure"
, String
"programlisting"
, String
"qandadiv"
, String
"question"
, String
"refsect1"
, String
"refsect1info"
, String
"refsect2"
, String
"refsect2info"
, String
"refsect3"
, String
"refsect3info"
, String
"refsection"
, String
"refsectioninfo"
, String
"screen"
, String
"sect1"
, String
"sect1info"
, String
"sect2"
, String
"sect2info"
, String
"sect3"
, String
"sect3info"
, String
"sect4"
, String
"sect4info"
, String
"sect5"
, String
"sect5info"
, String
"section"
, String
"sectioninfo"
, String
"simpara"
, String
"simplesect"
, String
"substeps"
, String
"subtitle"
, String
"table"
, String
"title"
, String
"titleabbrev"
, String
"toc"
, String
"variablelist"
] [String] -> [String] -> [String]
forall a. [a] -> [a] -> [a]
++ [String]
admonitionTags
admonitionTags :: [String]
admonitionTags :: [String]
admonitionTags = [String
"important",String
"caution",String
"note",String
"tip",String
"warning"]
trimNl :: Text -> Text
trimNl :: Text -> Text
trimNl = (Char -> Bool) -> Text -> Text
T.dropAround (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'\n')
addToStart :: Inlines -> Blocks -> Blocks
addToStart :: Inlines -> Blocks -> Blocks
addToStart Inlines
toadd Blocks
bs =
case Blocks -> [Block]
forall a. Many a -> [a]
toList Blocks
bs of
(Para [Inline]
xs : [Block]
rest) -> Inlines -> Blocks
para (Inlines
toadd Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> [Inline] -> Inlines
forall a. [a] -> Many a
fromList [Inline]
xs) Blocks -> Blocks -> Blocks
forall a. Semigroup a => a -> a -> a
<> [Block] -> Blocks
forall a. [a] -> Many a
fromList [Block]
rest
[Block]
_ -> Blocks
bs
getMediaobject :: PandocMonad m => Element -> DB m Inlines
getMediaobject :: Element -> DB m Inlines
getMediaobject Element
e = do
Inlines
figTitle <- (DBState -> Inlines) -> DB m Inlines
forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets DBState -> Inlines
dbFigureTitle
Text
ident <- (DBState -> Text) -> StateT DBState m Text
forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets DBState -> Text
dbFigureId
(Text
imageUrl, Attr
attr) <-
case (Element -> Bool) -> Element -> Maybe Element
filterChild (Text -> Element -> Bool
named Text
"imageobject") Element
e of
Maybe Element
Nothing -> (Text, Attr) -> StateT DBState m (Text, Attr)
forall (m :: * -> *) a. Monad m => a -> m a
return (Text
forall a. Monoid a => a
mempty, Attr
nullAttr)
Just Element
z -> case (Element -> Bool) -> Element -> Maybe Element
filterChild (Text -> Element -> Bool
named Text
"imagedata") Element
z of
Maybe Element
Nothing -> (Text, Attr) -> StateT DBState m (Text, Attr)
forall (m :: * -> *) a. Monad m => a -> m a
return (Text
forall a. Monoid a => a
mempty, Attr
nullAttr)
Just Element
i -> let atVal :: String -> Text
atVal String
a = String -> Element -> Text
attrValue String
a Element
i
w :: [(Text, Text)]
w = case String -> Text
atVal String
"width" of
Text
"" -> []
Text
d -> [(Text
"width", Text
d)]
h :: [(Text, Text)]
h = case String -> Text
atVal String
"depth" of
Text
"" -> []
Text
d -> [(Text
"height", Text
d)]
id' :: Text
id' = case String -> Text
atVal String
"id" of
Text
x | Text -> Bool
T.null Text
x -> Text
ident
| Bool
otherwise -> Text
x
cs :: [Text]
cs = Text -> [Text]
T.words (Text -> [Text]) -> Text -> [Text]
forall a b. (a -> b) -> a -> b
$ String -> Text
atVal String
"role"
atr :: Attr
atr = (Text
id', [Text]
cs, [(Text, Text)]
w [(Text, Text)] -> [(Text, Text)] -> [(Text, Text)]
forall a. [a] -> [a] -> [a]
++ [(Text, Text)]
h)
in (Text, Attr) -> StateT DBState m (Text, Attr)
forall (m :: * -> *) a. Monad m => a -> m a
return (String -> Text
atVal String
"fileref", Attr
atr)
let getCaption :: Element -> StateT DBState m Inlines
getCaption Element
el = case (Element -> Bool) -> Element -> Maybe Element
filterChild (\Element
x -> Text -> Element -> Bool
named Text
"caption" Element
x
Bool -> Bool -> Bool
|| Text -> Element -> Bool
named Text
"textobject" Element
x
Bool -> Bool -> Bool
|| Text -> Element -> Bool
named Text
"alt" Element
x) Element
el of
Maybe Element
Nothing -> Inlines -> StateT DBState m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return Inlines
forall a. Monoid a => a
mempty
Just Element
z -> [Inlines] -> Inlines
forall a. Monoid a => [a] -> a
mconcat ([Inlines] -> Inlines)
-> StateT DBState m [Inlines] -> StateT DBState m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
(Content -> StateT DBState m Inlines)
-> [Content] -> StateT DBState m [Inlines]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM Content -> StateT DBState m Inlines
forall (m :: * -> *). PandocMonad m => Content -> DB m Inlines
parseInline (Element -> [Content]
elContent Element
z)
let (DB m Inlines
capt, Text
title) = if Inlines -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null Inlines
figTitle
then (Element -> DB m Inlines
forall (m :: * -> *). PandocMonad m => Element -> DB m Inlines
getCaption Element
e, Text
"")
else (Inlines -> DB m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return Inlines
figTitle, Text
"fig:")
(Inlines -> Inlines) -> DB m Inlines -> DB m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Attr -> Text -> Text -> Inlines -> Inlines
imageWith Attr
attr Text
imageUrl Text
title) DB m Inlines
capt
getBlocks :: PandocMonad m => Element -> DB m Blocks
getBlocks :: Element -> DB m Blocks
getBlocks Element
e = [Blocks] -> Blocks
forall a. Monoid a => [a] -> a
mconcat ([Blocks] -> Blocks) -> StateT DBState m [Blocks] -> DB m Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
(Content -> DB m Blocks) -> [Content] -> StateT DBState m [Blocks]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM Content -> DB m Blocks
forall (m :: * -> *). PandocMonad m => Content -> DB m Blocks
parseBlock (Element -> [Content]
elContent Element
e)
parseBlock :: PandocMonad m => Content -> DB m Blocks
parseBlock :: Content -> DB m Blocks
parseBlock (Text (CData CDataKind
CDataRaw String
_ Maybe Line
_)) = Blocks -> DB m Blocks
forall (m :: * -> *) a. Monad m => a -> m a
return Blocks
forall a. Monoid a => a
mempty
parseBlock (Text (CData CDataKind
_ String
s Maybe Line
_)) = if (Char -> Bool) -> String -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all Char -> Bool
isSpace String
s
then Blocks -> DB m Blocks
forall (m :: * -> *) a. Monad m => a -> m a
return Blocks
forall a. Monoid a => a
mempty
else Blocks -> DB m Blocks
forall (m :: * -> *) a. Monad m => a -> m a
return (Blocks -> DB m Blocks) -> Blocks -> DB m Blocks
forall a b. (a -> b) -> a -> b
$ Inlines -> Blocks
plain (Inlines -> Blocks) -> Inlines -> Blocks
forall a b. (a -> b) -> a -> b
$ Inlines -> Inlines
trimInlines (Inlines -> Inlines) -> Inlines -> Inlines
forall a b. (a -> b) -> a -> b
$ Text -> Inlines
text (Text -> Inlines) -> Text -> Inlines
forall a b. (a -> b) -> a -> b
$ String -> Text
T.pack String
s
parseBlock (CRef String
x) = Blocks -> DB m Blocks
forall (m :: * -> *) a. Monad m => a -> m a
return (Blocks -> DB m Blocks) -> Blocks -> DB m Blocks
forall a b. (a -> b) -> a -> b
$ Inlines -> Blocks
plain (Inlines -> Blocks) -> Inlines -> Blocks
forall a b. (a -> b) -> a -> b
$ Text -> Inlines
str (Text -> Inlines) -> Text -> Inlines
forall a b. (a -> b) -> a -> b
$ Text -> Text
T.toUpper (Text -> Text) -> Text -> Text
forall a b. (a -> b) -> a -> b
$ String -> Text
T.pack String
x
parseBlock (Elem Element
e) =
case QName -> String
qName (Element -> QName
elName Element
e) of
String
"toc" -> DB m Blocks
skip
String
"index" -> DB m Blocks
skip
String
"para" -> (Inlines -> Blocks) -> [Content] -> DB m Blocks
forall (m :: * -> *).
PandocMonad m =>
(Inlines -> Blocks) -> [Content] -> DB m Blocks
parseMixed Inlines -> Blocks
para (Element -> [Content]
elContent Element
e)
String
"formalpara" -> do
Blocks
tit <- case (Element -> Bool) -> Element -> Maybe Element
filterChild (Text -> Element -> Bool
named Text
"title") Element
e of
Just Element
t -> Attr -> Blocks -> Blocks
divWith (Text
"",[Text
"formalpara-title"],[]) (Blocks -> Blocks) -> (Inlines -> Blocks) -> Inlines -> Blocks
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
Inlines -> Blocks
para (Inlines -> Blocks) -> (Inlines -> Inlines) -> Inlines -> Blocks
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Inlines -> Inlines
strong (Inlines -> Blocks) -> StateT DBState m Inlines -> DB m Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Element -> StateT DBState m Inlines
forall (m :: * -> *). PandocMonad m => Element -> DB m Inlines
getInlines Element
t
Maybe Element
Nothing -> Blocks -> DB m Blocks
forall (m :: * -> *) a. Monad m => a -> m a
return Blocks
forall a. Monoid a => a
mempty
(Blocks
tit Blocks -> Blocks -> Blocks
forall a. Semigroup a => a -> a -> a
<>) (Blocks -> Blocks) -> DB m Blocks -> DB m Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Inlines -> Blocks) -> [Content] -> DB m Blocks
forall (m :: * -> *).
PandocMonad m =>
(Inlines -> Blocks) -> [Content] -> DB m Blocks
parseMixed Inlines -> Blocks
para (Element -> [Content]
elContent Element
e)
String
"simpara" -> (Inlines -> Blocks) -> [Content] -> DB m Blocks
forall (m :: * -> *).
PandocMonad m =>
(Inlines -> Blocks) -> [Content] -> DB m Blocks
parseMixed Inlines -> Blocks
para (Element -> [Content]
elContent Element
e)
String
"ackno" -> (Inlines -> Blocks) -> [Content] -> DB m Blocks
forall (m :: * -> *).
PandocMonad m =>
(Inlines -> Blocks) -> [Content] -> DB m Blocks
parseMixed Inlines -> Blocks
para (Element -> [Content]
elContent Element
e)
String
"epigraph" -> DB m Blocks
parseBlockquote
String
"blockquote" -> DB m Blocks
parseBlockquote
String
"attribution" -> DB m Blocks
skip
String
"titleabbrev" -> DB m Blocks
skip
String
"authorinitials" -> DB m Blocks
skip
String
"bibliography" -> Int -> DB m Blocks
forall (m :: * -> *).
PandocMonad m =>
Int -> StateT DBState m Blocks
sect Int
0
String
"bibliodiv" ->
case (Element -> Bool) -> Element -> Maybe Element
filterChild (Text -> Element -> Bool
named Text
"title") Element
e of
Just Element
_ -> Int -> DB m Blocks
forall (m :: * -> *).
PandocMonad m =>
Int -> StateT DBState m Blocks
sect Int
1
Maybe Element
Nothing -> Blocks -> DB m Blocks
forall (m :: * -> *) a. Monad m => a -> m a
return Blocks
forall a. Monoid a => a
mempty
String
"biblioentry" -> (Inlines -> Blocks) -> [Content] -> DB m Blocks
forall (m :: * -> *).
PandocMonad m =>
(Inlines -> Blocks) -> [Content] -> DB m Blocks
parseMixed Inlines -> Blocks
para (Element -> [Content]
elContent Element
e)
String
"bibliomisc" -> (Inlines -> Blocks) -> [Content] -> DB m Blocks
forall (m :: * -> *).
PandocMonad m =>
(Inlines -> Blocks) -> [Content] -> DB m Blocks
parseMixed Inlines -> Blocks
para (Element -> [Content]
elContent Element
e)
String
"bibliomixed" -> (Inlines -> Blocks) -> [Content] -> DB m Blocks
forall (m :: * -> *).
PandocMonad m =>
(Inlines -> Blocks) -> [Content] -> DB m Blocks
parseMixed Inlines -> Blocks
para (Element -> [Content]
elContent Element
e)
String
"equation" -> Inlines -> Blocks
para (Inlines -> Blocks) -> StateT DBState m Inlines -> DB m Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Element -> (Text -> Inlines) -> StateT DBState m Inlines
forall (m :: * -> *).
Monad m =>
Element -> (Text -> Inlines) -> m Inlines
equation Element
e Text -> Inlines
displayMath
String
"informalequation" -> Inlines -> Blocks
para (Inlines -> Blocks) -> StateT DBState m Inlines -> DB m Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Element -> (Text -> Inlines) -> StateT DBState m Inlines
forall (m :: * -> *).
Monad m =>
Element -> (Text -> Inlines) -> m Inlines
equation Element
e Text -> Inlines
displayMath
String
"glosssee" -> Inlines -> Blocks
para (Inlines -> Blocks) -> (Inlines -> Inlines) -> Inlines -> Blocks
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (\Inlines
ils -> Text -> Inlines
text Text
"See " Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines
ils Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Text -> Inlines
str Text
".")
(Inlines -> Blocks) -> StateT DBState m Inlines -> DB m Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Element -> StateT DBState m Inlines
forall (m :: * -> *). PandocMonad m => Element -> DB m Inlines
getInlines Element
e
String
"glossseealso" -> Inlines -> Blocks
para (Inlines -> Blocks) -> (Inlines -> Inlines) -> Inlines -> Blocks
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (\Inlines
ils -> Text -> Inlines
text Text
"See also " Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines
ils Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Text -> Inlines
str Text
".")
(Inlines -> Blocks) -> StateT DBState m Inlines -> DB m Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Element -> StateT DBState m Inlines
forall (m :: * -> *). PandocMonad m => Element -> DB m Inlines
getInlines Element
e
String
"glossary" -> Int -> DB m Blocks
forall (m :: * -> *).
PandocMonad m =>
Int -> StateT DBState m Blocks
sect Int
0
String
"glossdiv" -> [(Inlines, [Blocks])] -> Blocks
definitionList ([(Inlines, [Blocks])] -> Blocks)
-> StateT DBState m [(Inlines, [Blocks])] -> DB m Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
(Element -> StateT DBState m (Inlines, [Blocks]))
-> [Element] -> StateT DBState m [(Inlines, [Blocks])]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM Element -> StateT DBState m (Inlines, [Blocks])
forall (m :: * -> *).
PandocMonad m =>
Element -> StateT DBState m (Inlines, [Blocks])
parseGlossEntry ((Element -> Bool) -> Element -> [Element]
filterChildren (Text -> Element -> Bool
named Text
"glossentry") Element
e)
String
"glosslist" -> [(Inlines, [Blocks])] -> Blocks
definitionList ([(Inlines, [Blocks])] -> Blocks)
-> StateT DBState m [(Inlines, [Blocks])] -> DB m Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
(Element -> StateT DBState m (Inlines, [Blocks]))
-> [Element] -> StateT DBState m [(Inlines, [Blocks])]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM Element -> StateT DBState m (Inlines, [Blocks])
forall (m :: * -> *).
PandocMonad m =>
Element -> StateT DBState m (Inlines, [Blocks])
parseGlossEntry ((Element -> Bool) -> Element -> [Element]
filterChildren (Text -> Element -> Bool
named Text
"glossentry") Element
e)
String
"chapter" -> (DBState -> DBState) -> StateT DBState m ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify (\DBState
st -> DBState
st{ dbBook :: Bool
dbBook = Bool
True}) StateT DBState m () -> DB m Blocks -> DB m Blocks
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Int -> DB m Blocks
forall (m :: * -> *).
PandocMonad m =>
Int -> StateT DBState m Blocks
sect Int
0
String
"appendix" -> Int -> DB m Blocks
forall (m :: * -> *).
PandocMonad m =>
Int -> StateT DBState m Blocks
sect Int
0
String
"preface" -> Int -> DB m Blocks
forall (m :: * -> *).
PandocMonad m =>
Int -> StateT DBState m Blocks
sect Int
0
String
"bridgehead" -> Inlines -> Blocks
para (Inlines -> Blocks) -> (Inlines -> Inlines) -> Inlines -> Blocks
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Inlines -> Inlines
strong (Inlines -> Blocks) -> StateT DBState m Inlines -> DB m Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Element -> StateT DBState m Inlines
forall (m :: * -> *). PandocMonad m => Element -> DB m Inlines
getInlines Element
e
String
"sect1" -> Int -> DB m Blocks
forall (m :: * -> *).
PandocMonad m =>
Int -> StateT DBState m Blocks
sect Int
1
String
"sect2" -> Int -> DB m Blocks
forall (m :: * -> *).
PandocMonad m =>
Int -> StateT DBState m Blocks
sect Int
2
String
"sect3" -> Int -> DB m Blocks
forall (m :: * -> *).
PandocMonad m =>
Int -> StateT DBState m Blocks
sect Int
3
String
"sect4" -> Int -> DB m Blocks
forall (m :: * -> *).
PandocMonad m =>
Int -> StateT DBState m Blocks
sect Int
4
String
"sect5" -> Int -> DB m Blocks
forall (m :: * -> *).
PandocMonad m =>
Int -> StateT DBState m Blocks
sect Int
5
String
"section" -> (DBState -> Int) -> StateT DBState m Int
forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets DBState -> Int
dbSectionLevel StateT DBState m Int -> (Int -> DB m Blocks) -> DB m Blocks
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Int -> DB m Blocks
forall (m :: * -> *).
PandocMonad m =>
Int -> StateT DBState m Blocks
sect (Int -> DB m Blocks) -> (Int -> Int) -> Int -> DB m Blocks
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Int -> Int -> Int
forall a. Num a => a -> a -> a
+Int
1)
String
"simplesect" ->
(DBState -> Int) -> StateT DBState m Int
forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets DBState -> Int
dbSectionLevel StateT DBState m Int -> (Int -> DB m Blocks) -> DB m Blocks
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=
Attr -> Int -> DB m Blocks
forall (m :: * -> *).
PandocMonad m =>
Attr -> Int -> StateT DBState m Blocks
sectWith (String -> Element -> Text
attrValue String
"id" Element
e,[Text
"unnumbered"],[]) (Int -> DB m Blocks) -> (Int -> Int) -> Int -> DB m Blocks
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Int -> Int -> Int
forall a. Num a => a -> a -> a
+Int
1)
String
"refsect1" -> Int -> DB m Blocks
forall (m :: * -> *).
PandocMonad m =>
Int -> StateT DBState m Blocks
sect Int
1
String
"refsect2" -> Int -> DB m Blocks
forall (m :: * -> *).
PandocMonad m =>
Int -> StateT DBState m Blocks
sect Int
2
String
"refsect3" -> Int -> DB m Blocks
forall (m :: * -> *).
PandocMonad m =>
Int -> StateT DBState m Blocks
sect Int
3
String
"refsection" -> (DBState -> Int) -> StateT DBState m Int
forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets DBState -> Int
dbSectionLevel StateT DBState m Int -> (Int -> DB m Blocks) -> DB m Blocks
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Int -> DB m Blocks
forall (m :: * -> *).
PandocMonad m =>
Int -> StateT DBState m Blocks
sect (Int -> DB m Blocks) -> (Int -> Int) -> Int -> DB m Blocks
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Int -> Int -> Int
forall a. Num a => a -> a -> a
+Int
1)
String
l | String
l String -> [String] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [String]
admonitionTags -> Text -> DB m Blocks
forall (m :: * -> *).
PandocMonad m =>
Text -> StateT DBState m Blocks
parseAdmonition (Text -> DB m Blocks) -> Text -> DB m Blocks
forall a b. (a -> b) -> a -> b
$ String -> Text
T.pack String
l
String
"area" -> DB m Blocks
skip
String
"areaset" -> DB m Blocks
skip
String
"areaspec" -> DB m Blocks
skip
String
"qandadiv" -> (DBState -> Int) -> StateT DBState m Int
forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets DBState -> Int
dbSectionLevel StateT DBState m Int -> (Int -> DB m Blocks) -> DB m Blocks
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Int -> DB m Blocks
forall (m :: * -> *).
PandocMonad m =>
Int -> StateT DBState m Blocks
sect (Int -> DB m Blocks) -> (Int -> Int) -> Int -> DB m Blocks
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Int -> Int -> Int
forall a. Num a => a -> a -> a
+Int
1)
String
"question" -> Inlines -> Blocks -> Blocks
addToStart (Inlines -> Inlines
strong (Text -> Inlines
str Text
"Q:") Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Text -> Inlines
str Text
" ") (Blocks -> Blocks) -> DB m Blocks -> DB m Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Element -> DB m Blocks
forall (m :: * -> *). PandocMonad m => Element -> DB m Blocks
getBlocks Element
e
String
"answer" -> Inlines -> Blocks -> Blocks
addToStart (Inlines -> Inlines
strong (Text -> Inlines
str Text
"A:") Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Text -> Inlines
str Text
" ") (Blocks -> Blocks) -> DB m Blocks -> DB m Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Element -> DB m Blocks
forall (m :: * -> *). PandocMonad m => Element -> DB m Blocks
getBlocks Element
e
String
"abstract" -> Blocks -> Blocks
blockQuote (Blocks -> Blocks) -> DB m Blocks -> DB m Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Element -> DB m Blocks
forall (m :: * -> *). PandocMonad m => Element -> DB m Blocks
getBlocks Element
e
String
"calloutlist" -> [Blocks] -> Blocks
bulletList ([Blocks] -> Blocks) -> StateT DBState m [Blocks] -> DB m Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> StateT DBState m [Blocks]
callouts
String
"itemizedlist" -> [Blocks] -> Blocks
bulletList ([Blocks] -> Blocks) -> StateT DBState m [Blocks] -> DB m Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> StateT DBState m [Blocks]
listitems
String
"orderedlist" -> do
let listStyle :: ListNumberStyle
listStyle = case String -> Element -> Text
attrValue String
"numeration" Element
e of
Text
"arabic" -> ListNumberStyle
Decimal
Text
"loweralpha" -> ListNumberStyle
LowerAlpha
Text
"upperalpha" -> ListNumberStyle
UpperAlpha
Text
"lowerroman" -> ListNumberStyle
LowerRoman
Text
"upperroman" -> ListNumberStyle
UpperRoman
Text
_ -> ListNumberStyle
Decimal
let start :: Int
start = Int -> Maybe Int -> Int
forall a. a -> Maybe a -> a
fromMaybe Int
1 (Maybe Int -> Int) -> Maybe Int -> Int
forall a b. (a -> b) -> a -> b
$
(Element -> Bool) -> Element -> Maybe Element
filterElement (Text -> Element -> Bool
named Text
"listitem") Element
e
Maybe Element -> (Element -> Maybe Int) -> Maybe Int
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Text -> Maybe Int
forall (m :: * -> *) a. (MonadPlus m, Read a) => Text -> m a
safeRead (Text -> Maybe Int) -> (Element -> Text) -> Element -> Maybe Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Element -> Text
attrValue String
"override"
ListAttributes -> [Blocks] -> Blocks
orderedListWith (Int
start,ListNumberStyle
listStyle,ListNumberDelim
DefaultDelim)
([Blocks] -> Blocks) -> StateT DBState m [Blocks] -> DB m Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> StateT DBState m [Blocks]
listitems
String
"variablelist" -> [(Inlines, [Blocks])] -> Blocks
definitionList ([(Inlines, [Blocks])] -> Blocks)
-> StateT DBState m [(Inlines, [Blocks])] -> DB m Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> StateT DBState m [(Inlines, [Blocks])]
deflistitems
String
"procedure" -> [Blocks] -> Blocks
bulletList ([Blocks] -> Blocks) -> StateT DBState m [Blocks] -> DB m Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> StateT DBState m [Blocks]
steps
String
"figure" -> Element -> DB m Blocks
forall (m :: * -> *). PandocMonad m => Element -> DB m Blocks
getFigure Element
e
String
"mediaobject" -> Inlines -> Blocks
para (Inlines -> Blocks) -> StateT DBState m Inlines -> DB m Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Element -> StateT DBState m Inlines
forall (m :: * -> *). PandocMonad m => Element -> DB m Inlines
getMediaobject Element
e
String
"caption" -> DB m Blocks
skip
String
"info" -> Element -> DB m Blocks
forall (m :: * -> *). PandocMonad m => Element -> DB m Blocks
addMetadataFromElement Element
e
String
"articleinfo" -> Element -> DB m Blocks
forall (m :: * -> *). PandocMonad m => Element -> DB m Blocks
addMetadataFromElement Element
e
String
"sectioninfo" -> DB m Blocks
skip
String
"refsectioninfo" -> DB m Blocks
skip
String
"refsect1info" -> DB m Blocks
skip
String
"refsect2info" -> DB m Blocks
skip
String
"refsect3info" -> DB m Blocks
skip
String
"sect1info" -> DB m Blocks
skip
String
"sect2info" -> DB m Blocks
skip
String
"sect3info" -> DB m Blocks
skip
String
"sect4info" -> DB m Blocks
skip
String
"sect5info" -> DB m Blocks
skip
String
"chapterinfo" -> DB m Blocks
skip
String
"glossaryinfo" -> DB m Blocks
skip
String
"appendixinfo" -> DB m Blocks
skip
String
"bookinfo" -> Element -> DB m Blocks
forall (m :: * -> *). PandocMonad m => Element -> DB m Blocks
addMetadataFromElement Element
e
String
"article" -> (DBState -> DBState) -> StateT DBState m ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify (\DBState
st -> DBState
st{ dbBook :: Bool
dbBook = Bool
False }) StateT DBState m () -> DB m Blocks -> DB m Blocks
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
Element -> DB m Blocks
forall (m :: * -> *). PandocMonad m => Element -> DB m Blocks
addMetadataFromElement Element
e DB m Blocks -> DB m Blocks -> DB m Blocks
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Element -> DB m Blocks
forall (m :: * -> *). PandocMonad m => Element -> DB m Blocks
getBlocks Element
e
String
"book" -> (DBState -> DBState) -> StateT DBState m ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify (\DBState
st -> DBState
st{ dbBook :: Bool
dbBook = Bool
True }) StateT DBState m () -> DB m Blocks -> DB m Blocks
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
Element -> DB m Blocks
forall (m :: * -> *). PandocMonad m => Element -> DB m Blocks
addMetadataFromElement Element
e DB m Blocks -> DB m Blocks -> DB m Blocks
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Element -> DB m Blocks
forall (m :: * -> *). PandocMonad m => Element -> DB m Blocks
getBlocks Element
e
String
"table" -> DB m Blocks
parseTable
String
"informaltable" -> DB m Blocks
parseTable
String
"informalexample" -> Attr -> Blocks -> Blocks
divWith (Text
"", [Text
"informalexample"], []) (Blocks -> Blocks) -> DB m Blocks -> DB m Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
Element -> DB m Blocks
forall (m :: * -> *). PandocMonad m => Element -> DB m Blocks
getBlocks Element
e
String
"linegroup" -> [Inlines] -> Blocks
lineBlock ([Inlines] -> Blocks) -> StateT DBState m [Inlines] -> DB m Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> StateT DBState m [Inlines]
lineItems
String
"literallayout" -> DB m Blocks
codeBlockWithLang
String
"screen" -> DB m Blocks
codeBlockWithLang
String
"programlisting" -> DB m Blocks
codeBlockWithLang
String
"?xml" -> Blocks -> DB m Blocks
forall (m :: * -> *) a. Monad m => a -> m a
return Blocks
forall a. Monoid a => a
mempty
String
"title" -> Blocks -> DB m Blocks
forall (m :: * -> *) a. Monad m => a -> m a
return Blocks
forall a. Monoid a => a
mempty
String
"subtitle" -> Blocks -> DB m Blocks
forall (m :: * -> *) a. Monad m => a -> m a
return Blocks
forall a. Monoid a => a
mempty
String
_ -> DB m Blocks
skip DB m Blocks -> DB m Blocks -> DB m Blocks
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Element -> DB m Blocks
forall (m :: * -> *). PandocMonad m => Element -> DB m Blocks
getBlocks Element
e
where skip :: DB m Blocks
skip = do
m () -> StateT DBState m ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m () -> StateT DBState m ()) -> m () -> StateT DBState m ()
forall a b. (a -> b) -> a -> b
$ LogMessage -> m ()
forall (m :: * -> *). PandocMonad m => LogMessage -> m ()
report (LogMessage -> m ()) -> LogMessage -> m ()
forall a b. (a -> b) -> a -> b
$ Text -> LogMessage
IgnoredElement (Text -> LogMessage) -> Text -> LogMessage
forall a b. (a -> b) -> a -> b
$ String -> Text
T.pack (String -> Text) -> String -> Text
forall a b. (a -> b) -> a -> b
$ QName -> String
qName (Element -> QName
elName Element
e)
Blocks -> DB m Blocks
forall (m :: * -> *) a. Monad m => a -> m a
return Blocks
forall a. Monoid a => a
mempty
codeBlockWithLang :: DB m Blocks
codeBlockWithLang = do
let classes' :: [Text]
classes' = case String -> Element -> Text
attrValue String
"language" Element
e of
Text
"" -> []
Text
x -> [Text
x]
Blocks -> DB m Blocks
forall (m :: * -> *) a. Monad m => a -> m a
return (Blocks -> DB m Blocks) -> Blocks -> DB m Blocks
forall a b. (a -> b) -> a -> b
$ Attr -> Text -> Blocks
codeBlockWith (String -> Element -> Text
attrValue String
"id" Element
e, [Text]
classes', [])
(Text -> Blocks) -> Text -> Blocks
forall a b. (a -> b) -> a -> b
$ Text -> Text
trimNl (Text -> Text) -> Text -> Text
forall a b. (a -> b) -> a -> b
$ String -> Text
T.pack (String -> Text) -> String -> Text
forall a b. (a -> b) -> a -> b
$ Element -> String
strContentRecursive Element
e
parseBlockquote :: DB m Blocks
parseBlockquote = do
Blocks
attrib <- case (Element -> Bool) -> Element -> Maybe Element
filterChild (Text -> Element -> Bool
named Text
"attribution") Element
e of
Maybe Element
Nothing -> Blocks -> DB m Blocks
forall (m :: * -> *) a. Monad m => a -> m a
return Blocks
forall a. Monoid a => a
mempty
Just Element
z -> Inlines -> Blocks
para (Inlines -> Blocks)
-> ([Inlines] -> Inlines) -> [Inlines] -> Blocks
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Text -> Inlines
str Text
"— " Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<>) (Inlines -> Inlines)
-> ([Inlines] -> Inlines) -> [Inlines] -> Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Inlines] -> Inlines
forall a. Monoid a => [a] -> a
mconcat
([Inlines] -> Blocks) -> StateT DBState m [Inlines] -> DB m Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
(Content -> StateT DBState m Inlines)
-> [Content] -> StateT DBState m [Inlines]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM Content -> StateT DBState m Inlines
forall (m :: * -> *). PandocMonad m => Content -> DB m Inlines
parseInline (Element -> [Content]
elContent Element
z)
Blocks
contents <- Element -> DB m Blocks
forall (m :: * -> *). PandocMonad m => Element -> DB m Blocks
getBlocks Element
e
Blocks -> DB m Blocks
forall (m :: * -> *) a. Monad m => a -> m a
return (Blocks -> DB m Blocks) -> Blocks -> DB m Blocks
forall a b. (a -> b) -> a -> b
$ Blocks -> Blocks
blockQuote (Blocks
contents Blocks -> Blocks -> Blocks
forall a. Semigroup a => a -> a -> a
<> Blocks
attrib)
listitems :: StateT DBState m [Blocks]
listitems = (Element -> DB m Blocks) -> [Element] -> StateT DBState m [Blocks]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM Element -> DB m Blocks
forall (m :: * -> *). PandocMonad m => Element -> DB m Blocks
getBlocks ([Element] -> StateT DBState m [Blocks])
-> [Element] -> StateT DBState m [Blocks]
forall a b. (a -> b) -> a -> b
$ (Element -> Bool) -> Element -> [Element]
filterChildren (Text -> Element -> Bool
named Text
"listitem") Element
e
callouts :: StateT DBState m [Blocks]
callouts = (Element -> DB m Blocks) -> [Element] -> StateT DBState m [Blocks]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM Element -> DB m Blocks
forall (m :: * -> *). PandocMonad m => Element -> DB m Blocks
getBlocks ([Element] -> StateT DBState m [Blocks])
-> [Element] -> StateT DBState m [Blocks]
forall a b. (a -> b) -> a -> b
$ (Element -> Bool) -> Element -> [Element]
filterChildren (Text -> Element -> Bool
named Text
"callout") Element
e
deflistitems :: StateT DBState m [(Inlines, [Blocks])]
deflistitems = (Element -> StateT DBState m (Inlines, [Blocks]))
-> [Element] -> StateT DBState m [(Inlines, [Blocks])]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM Element -> StateT DBState m (Inlines, [Blocks])
forall (m :: * -> *).
PandocMonad m =>
Element -> StateT DBState m (Inlines, [Blocks])
parseVarListEntry ([Element] -> StateT DBState m [(Inlines, [Blocks])])
-> [Element] -> StateT DBState m [(Inlines, [Blocks])]
forall a b. (a -> b) -> a -> b
$ (Element -> Bool) -> Element -> [Element]
filterChildren
(Text -> Element -> Bool
named Text
"varlistentry") Element
e
steps :: StateT DBState m [Blocks]
steps = (Element -> DB m Blocks) -> [Element] -> StateT DBState m [Blocks]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM Element -> DB m Blocks
forall (m :: * -> *). PandocMonad m => Element -> DB m Blocks
getBlocks ([Element] -> StateT DBState m [Blocks])
-> [Element] -> StateT DBState m [Blocks]
forall a b. (a -> b) -> a -> b
$ (Element -> Bool) -> Element -> [Element]
filterChildren (Text -> Element -> Bool
named Text
"step") Element
e
parseVarListEntry :: Element -> StateT DBState m (Inlines, [Blocks])
parseVarListEntry Element
e' = do
let terms :: [Element]
terms = (Element -> Bool) -> Element -> [Element]
filterChildren (Text -> Element -> Bool
named Text
"term") Element
e'
let items :: [Element]
items = (Element -> Bool) -> Element -> [Element]
filterChildren (Text -> Element -> Bool
named Text
"listitem") Element
e'
[Inlines]
terms' <- (Element -> StateT DBState m Inlines)
-> [Element] -> StateT DBState m [Inlines]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM Element -> StateT DBState m Inlines
forall (m :: * -> *). PandocMonad m => Element -> DB m Inlines
getInlines [Element]
terms
[Blocks]
items' <- (Element -> StateT DBState m Blocks)
-> [Element] -> StateT DBState m [Blocks]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM Element -> StateT DBState m Blocks
forall (m :: * -> *). PandocMonad m => Element -> DB m Blocks
getBlocks [Element]
items
(Inlines, [Blocks]) -> StateT DBState m (Inlines, [Blocks])
forall (m :: * -> *) a. Monad m => a -> m a
return ([Inlines] -> Inlines
forall a. Monoid a => [a] -> a
mconcat ([Inlines] -> Inlines) -> [Inlines] -> Inlines
forall a b. (a -> b) -> a -> b
$ Inlines -> [Inlines] -> [Inlines]
forall a. a -> [a] -> [a]
intersperse (Text -> Inlines
str Text
"; ") [Inlines]
terms', [Blocks]
items')
parseGlossEntry :: Element -> StateT DBState m (Inlines, [Blocks])
parseGlossEntry Element
e' = do
let terms :: [Element]
terms = (Element -> Bool) -> Element -> [Element]
filterChildren (Text -> Element -> Bool
named Text
"glossterm") Element
e'
let items :: [Element]
items = (Element -> Bool) -> Element -> [Element]
filterChildren (Text -> Element -> Bool
named Text
"glossdef") Element
e'
[Inlines]
terms' <- (Element -> StateT DBState m Inlines)
-> [Element] -> StateT DBState m [Inlines]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM Element -> StateT DBState m Inlines
forall (m :: * -> *). PandocMonad m => Element -> DB m Inlines
getInlines [Element]
terms
[Blocks]
items' <- (Element -> StateT DBState m Blocks)
-> [Element] -> StateT DBState m [Blocks]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM Element -> StateT DBState m Blocks
forall (m :: * -> *). PandocMonad m => Element -> DB m Blocks
getBlocks [Element]
items
(Inlines, [Blocks]) -> StateT DBState m (Inlines, [Blocks])
forall (m :: * -> *) a. Monad m => a -> m a
return ([Inlines] -> Inlines
forall a. Monoid a => [a] -> a
mconcat ([Inlines] -> Inlines) -> [Inlines] -> Inlines
forall a b. (a -> b) -> a -> b
$ Inlines -> [Inlines] -> [Inlines]
forall a. a -> [a] -> [a]
intersperse (Text -> Inlines
str Text
"; ") [Inlines]
terms', [Blocks]
items')
parseTable :: DB m Blocks
parseTable = do
let isCaption :: Element -> Bool
isCaption Element
x = Text -> Element -> Bool
named Text
"title" Element
x Bool -> Bool -> Bool
|| Text -> Element -> Bool
named Text
"caption" Element
x
Inlines
capt <- case (Element -> Bool) -> Element -> Maybe Element
filterChild Element -> Bool
isCaption Element
e of
Just Element
t -> Element -> StateT DBState m Inlines
forall (m :: * -> *). PandocMonad m => Element -> DB m Inlines
getInlines Element
t
Maybe Element
Nothing -> Inlines -> StateT DBState m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return Inlines
forall a. Monoid a => a
mempty
let e' :: Element
e' = Element -> Maybe Element -> Element
forall a. a -> Maybe a -> a
fromMaybe Element
e (Maybe Element -> Element) -> Maybe Element -> Element
forall a b. (a -> b) -> a -> b
$ (Element -> Bool) -> Element -> Maybe Element
filterChild (Text -> Element -> Bool
named Text
"tgroup") Element
e
let isColspec :: Element -> Bool
isColspec Element
x = Text -> Element -> Bool
named Text
"colspec" Element
x Bool -> Bool -> Bool
|| Text -> Element -> Bool
named Text
"col" Element
x
let colspecs :: [Element]
colspecs = case (Element -> Bool) -> Element -> Maybe Element
filterChild (Text -> Element -> Bool
named Text
"colgroup") Element
e' of
Just Element
c -> (Element -> Bool) -> Element -> [Element]
filterChildren Element -> Bool
isColspec Element
c
Maybe Element
_ -> (Element -> Bool) -> Element -> [Element]
filterChildren Element -> Bool
isColspec Element
e'
let colnames :: [String]
colnames = case [Element]
colspecs of
[] -> []
[Element]
cs -> (Element -> Maybe String) -> [Element] -> [String]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe (QName -> Element -> Maybe String
findAttr (String -> QName
unqual String
"colname" )) [Element]
cs
let isRow :: Element -> Bool
isRow Element
x = Text -> Element -> Bool
named Text
"row" Element
x Bool -> Bool -> Bool
|| Text -> Element -> Bool
named Text
"tr" Element
x
[Cell]
headrows <- case (Element -> Bool) -> Element -> Maybe Element
filterChild (Text -> Element -> Bool
named Text
"thead") Element
e' of
Just Element
h -> case (Element -> Bool) -> Element -> Maybe Element
filterChild Element -> Bool
isRow Element
h of
Just Element
x -> [String] -> Element -> StateT DBState m [Cell]
forall (m :: * -> *).
PandocMonad m =>
[String] -> Element -> DB m [Cell]
parseRow [String]
colnames Element
x
Maybe Element
Nothing -> [Cell] -> StateT DBState m [Cell]
forall (m :: * -> *) a. Monad m => a -> m a
return []
Maybe Element
Nothing -> [Cell] -> StateT DBState m [Cell]
forall (m :: * -> *) a. Monad m => a -> m a
return []
[[Cell]]
bodyrows <- case (Element -> Bool) -> Element -> Maybe Element
filterChild (Text -> Element -> Bool
named Text
"tbody") Element
e' of
Just Element
b -> (Element -> StateT DBState m [Cell])
-> [Element] -> StateT DBState m [[Cell]]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM ([String] -> Element -> StateT DBState m [Cell]
forall (m :: * -> *).
PandocMonad m =>
[String] -> Element -> DB m [Cell]
parseRow [String]
colnames)
([Element] -> StateT DBState m [[Cell]])
-> [Element] -> StateT DBState m [[Cell]]
forall a b. (a -> b) -> a -> b
$ (Element -> Bool) -> Element -> [Element]
filterChildren Element -> Bool
isRow Element
b
Maybe Element
Nothing -> (Element -> StateT DBState m [Cell])
-> [Element] -> StateT DBState m [[Cell]]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM ([String] -> Element -> StateT DBState m [Cell]
forall (m :: * -> *).
PandocMonad m =>
[String] -> Element -> DB m [Cell]
parseRow [String]
colnames)
([Element] -> StateT DBState m [[Cell]])
-> [Element] -> StateT DBState m [[Cell]]
forall a b. (a -> b) -> a -> b
$ (Element -> Bool) -> Element -> [Element]
filterChildren Element -> Bool
isRow Element
e'
let toWidth :: Element -> Maybe b
toWidth Element
c = do
String
w <- QName -> Element -> Maybe String
findAttr (String -> QName
unqual String
"colwidth") Element
c
b
n <- Text -> Maybe b
forall (m :: * -> *) a. (MonadPlus m, Read a) => Text -> m a
safeRead (Text -> Maybe b) -> Text -> Maybe b
forall a b. (a -> b) -> a -> b
$ Text
"0" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> (Char -> Bool) -> Text -> Text
T.filter (\Char
x ->
(Char
x Char -> Char -> Bool
forall a. Ord a => a -> a -> Bool
>= Char
'0' Bool -> Bool -> Bool
&& Char
x Char -> Char -> Bool
forall a. Ord a => a -> a -> Bool
<= Char
'9')
Bool -> Bool -> Bool
|| Char
x Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'.') (String -> Text
T.pack String
w)
if b
n b -> b -> Bool
forall a. Ord a => a -> a -> Bool
> b
0 then b -> Maybe b
forall a. a -> Maybe a
Just b
n else Maybe b
forall a. Maybe a
Nothing
let numrows :: Int
numrows = case [[Cell]]
bodyrows of
[] -> Int
0
[[Cell]]
xs -> [Int] -> Int
forall (t :: * -> *) a. (Foldable t, Ord a) => t a -> a
maximum ([Int] -> Int) -> [Int] -> Int
forall a b. (a -> b) -> a -> b
$ ([Cell] -> Int) -> [[Cell]] -> [Int]
forall a b. (a -> b) -> [a] -> [b]
map [Cell] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [[Cell]]
xs
let aligns :: [Alignment]
aligns = case [Element]
colspecs of
[] -> Int -> Alignment -> [Alignment]
forall a. Int -> a -> [a]
replicate Int
numrows Alignment
AlignDefault
[Element]
cs -> (Element -> Alignment) -> [Element] -> [Alignment]
forall a b. (a -> b) -> [a] -> [b]
map Element -> Alignment
toAlignment [Element]
cs
let parseWidth :: Text -> m a
parseWidth Text
s = Text -> m a
forall (m :: * -> *) a. (MonadPlus m, Read a) => Text -> m a
safeRead ((Char -> Bool) -> Text -> Text
T.filter (\Char
x -> (Char
x Char -> Char -> Bool
forall a. Ord a => a -> a -> Bool
>= Char
'0' Bool -> Bool -> Bool
&& Char
x Char -> Char -> Bool
forall a. Ord a => a -> a -> Bool
<= Char
'9')
Bool -> Bool -> Bool
|| Char
x Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'.') Text
s)
let textWidth :: Double
textWidth = case (Element -> Bool) -> Element -> Maybe Element
filterChild (Text -> Element -> Bool
named Text
"?dbfo") Element
e of
Just Element
d -> case String -> Element -> Text
attrValue String
"table-width" Element
d of
Text
"" -> Double
1.0
Text
w -> Double -> Maybe Double -> Double
forall a. a -> Maybe a -> a
fromMaybe Double
100.0 (Text -> Maybe Double
forall (m :: * -> *) a. (MonadPlus m, Read a) => Text -> m a
parseWidth Text
w) Double -> Double -> Double
forall a. Fractional a => a -> a -> a
/ Double
100.0
Maybe Element
Nothing -> Double
1.0
let widths :: [ColWidth]
widths = case [Element]
colspecs of
[] -> Int -> ColWidth -> [ColWidth]
forall a. Int -> a -> [a]
replicate Int
numrows ColWidth
ColWidthDefault
[Element]
cs -> let ws :: [Maybe Double]
ws = (Element -> Maybe Double) -> [Element] -> [Maybe Double]
forall a b. (a -> b) -> [a] -> [b]
map Element -> Maybe Double
forall b. (Read b, Ord b, Num b) => Element -> Maybe b
toWidth [Element]
cs
in case [Maybe Double] -> Maybe [Double]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence [Maybe Double]
ws of
Just [Double]
ws' -> let colTot :: Double
colTot = [Double] -> Double
forall (t :: * -> *) a. (Foldable t, Num a) => t a -> a
sum [Double]
ws'
scale :: Double -> Double
scale
| Double
textWidth Double -> Double -> Bool
forall a. Eq a => a -> a -> Bool
== Double
1.0 = (Double -> Double -> Double
forall a. Fractional a => a -> a -> a
/ Double
colTot)
| Bool
otherwise = (Double -> Double -> Double
forall a. Num a => a -> a -> a
* (Double
textWidth Double -> Double -> Double
forall a. Fractional a => a -> a -> a
/ Double
colTot) )
in Double -> ColWidth
ColWidth (Double -> ColWidth) -> (Double -> Double) -> Double -> ColWidth
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Double -> Double
scale (Double -> ColWidth) -> [Double] -> [ColWidth]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Double]
ws'
Maybe [Double]
Nothing -> Int -> ColWidth -> [ColWidth]
forall a. Int -> a -> [a]
replicate Int
numrows ColWidth
ColWidthDefault
let toRow :: [Cell] -> Row
toRow = Attr -> [Cell] -> Row
Row Attr
nullAttr
toHeaderRow :: [Cell] -> [Row]
toHeaderRow [Cell]
l = [[Cell] -> Row
toRow [Cell]
l | Bool -> Bool
not ([Cell] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Cell]
l)]
Blocks -> DB m Blocks
forall (m :: * -> *) a. Monad m => a -> m a
return (Blocks -> DB m Blocks) -> Blocks -> DB m Blocks
forall a b. (a -> b) -> a -> b
$ Caption
-> [ColSpec] -> TableHead -> [TableBody] -> TableFoot -> Blocks
table (Blocks -> Caption
simpleCaption (Blocks -> Caption) -> Blocks -> Caption
forall a b. (a -> b) -> a -> b
$ Inlines -> Blocks
plain Inlines
capt)
([Alignment] -> [ColWidth] -> [ColSpec]
forall a b. [a] -> [b] -> [(a, b)]
zip [Alignment]
aligns [ColWidth]
widths)
(Attr -> [Row] -> TableHead
TableHead Attr
nullAttr ([Row] -> TableHead) -> [Row] -> TableHead
forall a b. (a -> b) -> a -> b
$ [Cell] -> [Row]
toHeaderRow [Cell]
headrows)
[Attr -> RowHeadColumns -> [Row] -> [Row] -> TableBody
TableBody Attr
nullAttr RowHeadColumns
0 [] ([Row] -> TableBody) -> [Row] -> TableBody
forall a b. (a -> b) -> a -> b
$ ([Cell] -> Row) -> [[Cell]] -> [Row]
forall a b. (a -> b) -> [a] -> [b]
map [Cell] -> Row
toRow [[Cell]]
bodyrows]
(Attr -> [Row] -> TableFoot
TableFoot Attr
nullAttr [])
sect :: Int -> StateT DBState m Blocks
sect Int
n = Attr -> Int -> StateT DBState m Blocks
forall (m :: * -> *).
PandocMonad m =>
Attr -> Int -> StateT DBState m Blocks
sectWith (String -> Element -> Text
attrValue String
"id" Element
e,[],[]) Int
n
sectWith :: Attr -> Int -> StateT DBState m Blocks
sectWith Attr
attr Int
n = do
Bool
isbook <- (DBState -> Bool) -> StateT DBState m Bool
forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets DBState -> Bool
dbBook
let n' :: Int
n' = if Bool
isbook Bool -> Bool -> Bool
|| Int
n Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0 then Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1 else Int
n
Inlines
headerText <- case (Element -> Bool) -> Element -> Maybe Element
filterChild (Text -> Element -> Bool
named Text
"title") Element
e Maybe Element -> Maybe Element -> Maybe Element
forall (m :: * -> *) a. MonadPlus m => m a -> m a -> m a
`mplus`
((Element -> Bool) -> Element -> Maybe Element
filterChild (Text -> Element -> Bool
named Text
"info") Element
e Maybe Element -> (Element -> Maybe Element) -> Maybe Element
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=
(Element -> Bool) -> Element -> Maybe Element
filterChild (Text -> Element -> Bool
named Text
"title")) of
Just Element
t -> Element -> StateT DBState m Inlines
forall (m :: * -> *). PandocMonad m => Element -> DB m Inlines
getInlines Element
t
Maybe Element
Nothing -> Inlines -> StateT DBState m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return Inlines
forall a. Monoid a => a
mempty
(DBState -> DBState) -> StateT DBState m ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify ((DBState -> DBState) -> StateT DBState m ())
-> (DBState -> DBState) -> StateT DBState m ()
forall a b. (a -> b) -> a -> b
$ \DBState
st -> DBState
st{ dbSectionLevel :: Int
dbSectionLevel = Int
n }
Blocks
b <- Element -> StateT DBState m Blocks
forall (m :: * -> *). PandocMonad m => Element -> DB m Blocks
getBlocks Element
e
(DBState -> DBState) -> StateT DBState m ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify ((DBState -> DBState) -> StateT DBState m ())
-> (DBState -> DBState) -> StateT DBState m ()
forall a b. (a -> b) -> a -> b
$ \DBState
st -> DBState
st{ dbSectionLevel :: Int
dbSectionLevel = Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1 }
Blocks -> StateT DBState m Blocks
forall (m :: * -> *) a. Monad m => a -> m a
return (Blocks -> StateT DBState m Blocks)
-> Blocks -> StateT DBState m Blocks
forall a b. (a -> b) -> a -> b
$ Attr -> Int -> Inlines -> Blocks
headerWith Attr
attr Int
n' Inlines
headerText Blocks -> Blocks -> Blocks
forall a. Semigroup a => a -> a -> a
<> Blocks
b
lineItems :: StateT DBState m [Inlines]
lineItems = (Element -> StateT DBState m Inlines)
-> [Element] -> StateT DBState m [Inlines]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM Element -> StateT DBState m Inlines
forall (m :: * -> *). PandocMonad m => Element -> DB m Inlines
getInlines ([Element] -> StateT DBState m [Inlines])
-> [Element] -> StateT DBState m [Inlines]
forall a b. (a -> b) -> a -> b
$ (Element -> Bool) -> Element -> [Element]
filterChildren (Text -> Element -> Bool
named Text
"line") Element
e
parseAdmonition :: Text -> StateT DBState m Blocks
parseAdmonition Text
label = do
Blocks
title <- case (Element -> Bool) -> Element -> Maybe Element
filterChild (Text -> Element -> Bool
named Text
"title") Element
e of
Just Element
t -> Attr -> Blocks -> Blocks
divWith (Text
"", [Text
"title"], []) (Blocks -> Blocks) -> (Inlines -> Blocks) -> Inlines -> Blocks
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Inlines -> Blocks
plain (Inlines -> Blocks)
-> StateT DBState m Inlines -> StateT DBState m Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Element -> StateT DBState m Inlines
forall (m :: * -> *). PandocMonad m => Element -> DB m Inlines
getInlines Element
t
Maybe Element
Nothing -> Blocks -> StateT DBState m Blocks
forall (m :: * -> *) a. Monad m => a -> m a
return Blocks
forall a. Monoid a => a
mempty
Blocks
b <- Element -> StateT DBState m Blocks
forall (m :: * -> *). PandocMonad m => Element -> DB m Blocks
getBlocks Element
e
Blocks -> StateT DBState m Blocks
forall (m :: * -> *) a. Monad m => a -> m a
return (Blocks -> StateT DBState m Blocks)
-> Blocks -> StateT DBState m Blocks
forall a b. (a -> b) -> a -> b
$ Attr -> Blocks -> Blocks
divWith (String -> Element -> Text
attrValue String
"id" Element
e,[Text
label],[]) (Blocks
title Blocks -> Blocks -> Blocks
forall a. Semigroup a => a -> a -> a
<> Blocks
b)
toAlignment :: Element -> Alignment
toAlignment :: Element -> Alignment
toAlignment Element
c = case QName -> Element -> Maybe String
findAttr (String -> QName
unqual String
"align") Element
c of
Just String
"left" -> Alignment
AlignLeft
Just String
"right" -> Alignment
AlignRight
Just String
"center" -> Alignment
AlignCenter
Maybe String
_ -> Alignment
AlignDefault
parseMixed :: PandocMonad m => (Inlines -> Blocks) -> [Content] -> DB m Blocks
parseMixed :: (Inlines -> Blocks) -> [Content] -> DB m Blocks
parseMixed Inlines -> Blocks
container [Content]
conts = do
let ([Content]
ils,[Content]
rest) = (Content -> Bool) -> [Content] -> ([Content], [Content])
forall a. (a -> Bool) -> [a] -> ([a], [a])
break Content -> Bool
isBlockElement [Content]
conts
Inlines
ils' <- Inlines -> Inlines
trimInlines (Inlines -> Inlines)
-> ([Inlines] -> Inlines) -> [Inlines] -> Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Inlines] -> Inlines
forall a. Monoid a => [a] -> a
mconcat ([Inlines] -> Inlines)
-> StateT DBState m [Inlines] -> StateT DBState m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Content -> StateT DBState m Inlines)
-> [Content] -> StateT DBState m [Inlines]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM Content -> StateT DBState m Inlines
forall (m :: * -> *). PandocMonad m => Content -> DB m Inlines
parseInline [Content]
ils
let p :: Blocks
p = if Inlines
ils' Inlines -> Inlines -> Bool
forall a. Eq a => a -> a -> Bool
== Inlines
forall a. Monoid a => a
mempty then Blocks
forall a. Monoid a => a
mempty else Inlines -> Blocks
container Inlines
ils'
case [Content]
rest of
[] -> Blocks -> DB m Blocks
forall (m :: * -> *) a. Monad m => a -> m a
return Blocks
p
(Content
r:[Content]
rs) -> do
Blocks
b <- Content -> DB m Blocks
forall (m :: * -> *). PandocMonad m => Content -> DB m Blocks
parseBlock Content
r
Blocks
x <- (Inlines -> Blocks) -> [Content] -> DB m Blocks
forall (m :: * -> *).
PandocMonad m =>
(Inlines -> Blocks) -> [Content] -> DB m Blocks
parseMixed Inlines -> Blocks
container [Content]
rs
Blocks -> DB m Blocks
forall (m :: * -> *) a. Monad m => a -> m a
return (Blocks -> DB m Blocks) -> Blocks -> DB m Blocks
forall a b. (a -> b) -> a -> b
$ Blocks
p Blocks -> Blocks -> Blocks
forall a. Semigroup a => a -> a -> a
<> Blocks
b Blocks -> Blocks -> Blocks
forall a. Semigroup a => a -> a -> a
<> Blocks
x
parseRow :: PandocMonad m => [String] -> Element -> DB m [Cell]
parseRow :: [String] -> Element -> DB m [Cell]
parseRow [String]
cn = do
let isEntry :: Element -> Bool
isEntry Element
x = Text -> Element -> Bool
named Text
"entry" Element
x Bool -> Bool -> Bool
|| Text -> Element -> Bool
named Text
"td" Element
x Bool -> Bool -> Bool
|| Text -> Element -> Bool
named Text
"th" Element
x
(Element -> StateT DBState m Cell) -> [Element] -> DB m [Cell]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM ([String] -> Element -> StateT DBState m Cell
forall (m :: * -> *).
PandocMonad m =>
[String] -> Element -> DB m Cell
parseEntry [String]
cn) ([Element] -> DB m [Cell])
-> (Element -> [Element]) -> Element -> DB m [Cell]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Element -> Bool) -> Element -> [Element]
filterChildren Element -> Bool
isEntry
parseEntry :: PandocMonad m => [String] -> Element -> DB m Cell
parseEntry :: [String] -> Element -> DB m Cell
parseEntry [String]
cn Element
el = do
let colDistance :: String -> String -> ColSpan
colDistance String
sa String
ea = do
let iStrt :: Maybe Int
iStrt = String -> [String] -> Maybe Int
forall a. Eq a => a -> [a] -> Maybe Int
elemIndex String
sa [String]
cn
let iEnd :: Maybe Int
iEnd = String -> [String] -> Maybe Int
forall a. Eq a => a -> [a] -> Maybe Int
elemIndex String
ea [String]
cn
case (Maybe Int
iStrt, Maybe Int
iEnd) of
(Just Int
start, Just Int
end) -> Int -> ColSpan
ColSpan (Int -> ColSpan) -> Int -> ColSpan
forall a b. (a -> b) -> a -> b
$ Int
end Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
start Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1
(Maybe Int, Maybe Int)
_ -> ColSpan
1
let toColSpan :: Element -> ColSpan
toColSpan Element
en = do
let mStrt :: Maybe String
mStrt = QName -> Element -> Maybe String
findAttr (String -> QName
unqual String
"namest") Element
en
let mEnd :: Maybe String
mEnd = QName -> Element -> Maybe String
findAttr (String -> QName
unqual String
"nameend") Element
en
case (Maybe String
mStrt, Maybe String
mEnd) of
(Just String
start, Just String
end) -> String -> String -> ColSpan
colDistance String
start String
end
(Maybe String, Maybe String)
_ -> ColSpan
1
let colSpan :: ColSpan
colSpan = Element -> ColSpan
toColSpan Element
el
let align :: Alignment
align = Element -> Alignment
toAlignment Element
el
((Blocks -> Cell) -> StateT DBState m Blocks -> DB m Cell
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Alignment -> RowSpan -> ColSpan -> Blocks -> Cell
cell Alignment
align RowSpan
1 ColSpan
colSpan) (StateT DBState m Blocks -> DB m Cell)
-> (Element -> StateT DBState m Blocks) -> Element -> DB m Cell
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Inlines -> Blocks) -> [Content] -> StateT DBState m Blocks
forall (m :: * -> *).
PandocMonad m =>
(Inlines -> Blocks) -> [Content] -> DB m Blocks
parseMixed Inlines -> Blocks
plain ([Content] -> StateT DBState m Blocks)
-> (Element -> [Content]) -> Element -> StateT DBState m Blocks
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Element -> [Content]
elContent) Element
el
getInlines :: PandocMonad m => Element -> DB m Inlines
getInlines :: Element -> DB m Inlines
getInlines Element
e' = Inlines -> Inlines
trimInlines (Inlines -> Inlines)
-> ([Inlines] -> Inlines) -> [Inlines] -> Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Inlines] -> Inlines
forall a. Monoid a => [a] -> a
mconcat ([Inlines] -> Inlines)
-> StateT DBState m [Inlines] -> DB m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
(Content -> DB m Inlines)
-> [Content] -> StateT DBState m [Inlines]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM Content -> DB m Inlines
forall (m :: * -> *). PandocMonad m => Content -> DB m Inlines
parseInline (Element -> [Content]
elContent Element
e')
strContentRecursive :: Element -> String
strContentRecursive :: Element -> String
strContentRecursive = Element -> String
strContent (Element -> String) -> (Element -> Element) -> Element -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
(\Element
e' -> Element
e'{ elContent :: [Content]
elContent = (Content -> Content) -> [Content] -> [Content]
forall a b. (a -> b) -> [a] -> [b]
map Content -> Content
elementToStr ([Content] -> [Content]) -> [Content] -> [Content]
forall a b. (a -> b) -> a -> b
$ Element -> [Content]
elContent Element
e' })
elementToStr :: Content -> Content
elementToStr :: Content -> Content
elementToStr (Elem Element
e') = CData -> Content
Text (CData -> Content) -> CData -> Content
forall a b. (a -> b) -> a -> b
$ CDataKind -> String -> Maybe Line -> CData
CData CDataKind
CDataText (Element -> String
strContentRecursive Element
e') Maybe Line
forall a. Maybe a
Nothing
elementToStr Content
x = Content
x
parseInline :: PandocMonad m => Content -> DB m Inlines
parseInline :: Content -> DB m Inlines
parseInline (Text (CData CDataKind
_ String
s Maybe Line
_)) = Inlines -> DB m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> DB m Inlines) -> Inlines -> DB m Inlines
forall a b. (a -> b) -> a -> b
$ Text -> Inlines
text (Text -> Inlines) -> Text -> Inlines
forall a b. (a -> b) -> a -> b
$ String -> Text
T.pack String
s
parseInline (CRef String
ref) =
Inlines -> DB m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> DB m Inlines) -> Inlines -> DB m Inlines
forall a b. (a -> b) -> a -> b
$ Text -> Inlines
text (Text -> Inlines) -> Text -> Inlines
forall a b. (a -> b) -> a -> b
$ Text -> (String -> Text) -> Maybe String -> Text
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (Text -> Text
T.toUpper (Text -> Text) -> Text -> Text
forall a b. (a -> b) -> a -> b
$ String -> Text
T.pack String
ref) String -> Text
T.pack (Maybe String -> Text) -> Maybe String -> Text
forall a b. (a -> b) -> a -> b
$ String -> Maybe String
lookupEntity String
ref
parseInline (Elem Element
e) =
case QName -> String
qName (Element -> QName
elName Element
e) of
String
"anchor" -> do
Inlines -> DB m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> DB m Inlines) -> Inlines -> DB m Inlines
forall a b. (a -> b) -> a -> b
$ Attr -> Inlines -> Inlines
spanWith (String -> Element -> Text
attrValue String
"id" Element
e, [], []) Inlines
forall a. Monoid a => a
mempty
String
"phrase" -> do
let ident :: Text
ident = String -> Element -> Text
attrValue String
"id" Element
e
let classes :: [Text]
classes = Text -> [Text]
T.words (Text -> [Text]) -> Text -> [Text]
forall a b. (a -> b) -> a -> b
$ String -> Element -> Text
attrValue String
"class" Element
e
if Text
ident Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
/= Text
"" Bool -> Bool -> Bool
|| [Text]
classes [Text] -> [Text] -> Bool
forall a. Eq a => a -> a -> Bool
/= []
then (Inlines -> Inlines) -> DB m Inlines
forall (m :: * -> *).
PandocMonad m =>
(Inlines -> Inlines) -> StateT DBState m Inlines
innerInlines (Attr -> Inlines -> Inlines
spanWith (Text
ident,[Text]
classes,[]))
else (Inlines -> Inlines) -> DB m Inlines
forall (m :: * -> *).
PandocMonad m =>
(Inlines -> Inlines) -> StateT DBState m Inlines
innerInlines Inlines -> Inlines
forall a. a -> a
id
String
"equation" -> Element -> (Text -> Inlines) -> DB m Inlines
forall (m :: * -> *).
Monad m =>
Element -> (Text -> Inlines) -> m Inlines
equation Element
e Text -> Inlines
displayMath
String
"informalequation" -> Element -> (Text -> Inlines) -> DB m Inlines
forall (m :: * -> *).
Monad m =>
Element -> (Text -> Inlines) -> m Inlines
equation Element
e Text -> Inlines
displayMath
String
"inlineequation" -> Element -> (Text -> Inlines) -> DB m Inlines
forall (m :: * -> *).
Monad m =>
Element -> (Text -> Inlines) -> m Inlines
equation Element
e Text -> Inlines
math
String
"subscript" -> (Inlines -> Inlines) -> DB m Inlines
forall (m :: * -> *).
PandocMonad m =>
(Inlines -> Inlines) -> StateT DBState m Inlines
innerInlines Inlines -> Inlines
subscript
String
"superscript" -> (Inlines -> Inlines) -> DB m Inlines
forall (m :: * -> *).
PandocMonad m =>
(Inlines -> Inlines) -> StateT DBState m Inlines
innerInlines Inlines -> Inlines
superscript
String
"inlinemediaobject" -> Element -> DB m Inlines
forall (m :: * -> *). PandocMonad m => Element -> DB m Inlines
getMediaobject Element
e
String
"quote" -> do
QuoteType
qt <- (DBState -> QuoteType) -> StateT DBState m QuoteType
forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets DBState -> QuoteType
dbQuoteType
let qt' :: QuoteType
qt' = if QuoteType
qt QuoteType -> QuoteType -> Bool
forall a. Eq a => a -> a -> Bool
== QuoteType
SingleQuote then QuoteType
DoubleQuote else QuoteType
SingleQuote
(DBState -> DBState) -> StateT DBState m ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify ((DBState -> DBState) -> StateT DBState m ())
-> (DBState -> DBState) -> StateT DBState m ()
forall a b. (a -> b) -> a -> b
$ \DBState
st -> DBState
st{ dbQuoteType :: QuoteType
dbQuoteType = QuoteType
qt' }
Inlines
contents <- (Inlines -> Inlines) -> DB m Inlines
forall (m :: * -> *).
PandocMonad m =>
(Inlines -> Inlines) -> StateT DBState m Inlines
innerInlines Inlines -> Inlines
forall a. a -> a
id
(DBState -> DBState) -> StateT DBState m ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify ((DBState -> DBState) -> StateT DBState m ())
-> (DBState -> DBState) -> StateT DBState m ()
forall a b. (a -> b) -> a -> b
$ \DBState
st -> DBState
st{ dbQuoteType :: QuoteType
dbQuoteType = QuoteType
qt }
Inlines -> DB m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> DB m Inlines) -> Inlines -> DB m Inlines
forall a b. (a -> b) -> a -> b
$ if QuoteType
qt QuoteType -> QuoteType -> Bool
forall a. Eq a => a -> a -> Bool
== QuoteType
SingleQuote
then Inlines -> Inlines
singleQuoted Inlines
contents
else Inlines -> Inlines
doubleQuoted Inlines
contents
String
"simplelist" -> DB m Inlines
simpleList
String
"segmentedlist" -> DB m Inlines
segmentedList
String
"classname" -> DB m Inlines
codeWithLang
String
"code" -> DB m Inlines
codeWithLang
String
"filename" -> DB m Inlines
codeWithLang
String
"envar" -> DB m Inlines
codeWithLang
String
"literal" -> DB m Inlines
codeWithLang
String
"computeroutput" -> DB m Inlines
codeWithLang
String
"prompt" -> DB m Inlines
codeWithLang
String
"parameter" -> DB m Inlines
codeWithLang
String
"option" -> DB m Inlines
codeWithLang
String
"optional" -> do Inlines
x <- Element -> DB m Inlines
forall (m :: * -> *). PandocMonad m => Element -> DB m Inlines
getInlines Element
e
Inlines -> DB m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> DB m Inlines) -> Inlines -> DB m Inlines
forall a b. (a -> b) -> a -> b
$ Text -> Inlines
str Text
"[" Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines
x Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Text -> Inlines
str Text
"]"
String
"replaceable" -> do Inlines
x <- Element -> DB m Inlines
forall (m :: * -> *). PandocMonad m => Element -> DB m Inlines
getInlines Element
e
Inlines -> DB m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> DB m Inlines) -> Inlines -> DB m Inlines
forall a b. (a -> b) -> a -> b
$ Text -> Inlines
str Text
"<" Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines
x Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Text -> Inlines
str Text
">"
String
"markup" -> DB m Inlines
codeWithLang
String
"wordasword" -> (Inlines -> Inlines) -> DB m Inlines
forall (m :: * -> *).
PandocMonad m =>
(Inlines -> Inlines) -> StateT DBState m Inlines
innerInlines Inlines -> Inlines
emph
String
"command" -> DB m Inlines
codeWithLang
String
"varname" -> DB m Inlines
codeWithLang
String
"function" -> DB m Inlines
codeWithLang
String
"type" -> DB m Inlines
codeWithLang
String
"symbol" -> DB m Inlines
codeWithLang
String
"constant" -> DB m Inlines
codeWithLang
String
"userinput" -> DB m Inlines
codeWithLang
String
"systemitem" -> DB m Inlines
codeWithLang
String
"varargs" -> Inlines -> DB m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> DB m Inlines) -> Inlines -> DB m Inlines
forall a b. (a -> b) -> a -> b
$ Text -> Inlines
code Text
"(...)"
String
"keycap" -> Inlines -> DB m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> Inlines
str (Text -> Inlines) -> Text -> Inlines
forall a b. (a -> b) -> a -> b
$ String -> Text
T.pack (String -> Text) -> String -> Text
forall a b. (a -> b) -> a -> b
$ Element -> String
strContent Element
e)
String
"keycombo" -> [Inlines] -> Inlines
keycombo ([Inlines] -> Inlines)
-> StateT DBState m [Inlines] -> DB m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
(Content -> DB m Inlines)
-> [Content] -> StateT DBState m [Inlines]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM Content -> DB m Inlines
forall (m :: * -> *). PandocMonad m => Content -> DB m Inlines
parseInline (Element -> [Content]
elContent Element
e)
String
"menuchoice" -> [Inlines] -> Inlines
menuchoice ([Inlines] -> Inlines)
-> StateT DBState m [Inlines] -> DB m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
(Content -> DB m Inlines)
-> [Content] -> StateT DBState m [Inlines]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM Content -> DB m Inlines
forall (m :: * -> *). PandocMonad m => Content -> DB m Inlines
parseInline (
(Content -> Bool) -> [Content] -> [Content]
forall a. (a -> Bool) -> [a] -> [a]
filter Content -> Bool
isGuiMenu ([Content] -> [Content]) -> [Content] -> [Content]
forall a b. (a -> b) -> a -> b
$ Element -> [Content]
elContent Element
e)
String
"xref" -> do
[Content]
content <- DBState -> [Content]
dbContent (DBState -> [Content])
-> StateT DBState m DBState -> StateT DBState m [Content]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> StateT DBState m DBState
forall s (m :: * -> *). MonadState s m => m s
get
let linkend :: Text
linkend = String -> Element -> Text
attrValue String
"linkend" Element
e
let title :: Text
title = case String -> Element -> Text
attrValue String
"endterm" Element
e of
Text
"" -> Text -> (Element -> Text) -> Maybe Element -> Text
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Text
"???" Element -> Text
xrefTitleByElem
(Text -> [Content] -> Maybe Element
findElementById Text
linkend [Content]
content)
Text
endterm -> Text -> (Element -> Text) -> Maybe Element -> Text
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Text
"???" (String -> Text
T.pack (String -> Text) -> (Element -> String) -> Element -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Element -> String
strContent)
(Text -> [Content] -> Maybe Element
findElementById Text
endterm [Content]
content)
Inlines -> DB m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> DB m Inlines) -> Inlines -> DB m Inlines
forall a b. (a -> b) -> a -> b
$ Text -> Text -> Inlines -> Inlines
link (Text
"#" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
linkend) Text
"" (Text -> Inlines
text Text
title)
String
"email" -> Inlines -> DB m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> DB m Inlines) -> Inlines -> DB m Inlines
forall a b. (a -> b) -> a -> b
$ Text -> Text -> Inlines -> Inlines
link (Text
"mailto:" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> String -> Text
T.pack (Element -> String
strContent Element
e)) Text
""
(Inlines -> Inlines) -> Inlines -> Inlines
forall a b. (a -> b) -> a -> b
$ Text -> Inlines
str (Text -> Inlines) -> Text -> Inlines
forall a b. (a -> b) -> a -> b
$ String -> Text
T.pack (String -> Text) -> String -> Text
forall a b. (a -> b) -> a -> b
$ Element -> String
strContent Element
e
String
"uri" -> Inlines -> DB m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> DB m Inlines) -> Inlines -> DB m Inlines
forall a b. (a -> b) -> a -> b
$ Text -> Text -> Inlines -> Inlines
link (String -> Text
T.pack (String -> Text) -> String -> Text
forall a b. (a -> b) -> a -> b
$ Element -> String
strContent Element
e) Text
"" (Inlines -> Inlines) -> Inlines -> Inlines
forall a b. (a -> b) -> a -> b
$ Text -> Inlines
str (Text -> Inlines) -> Text -> Inlines
forall a b. (a -> b) -> a -> b
$ String -> Text
T.pack (String -> Text) -> String -> Text
forall a b. (a -> b) -> a -> b
$ Element -> String
strContent Element
e
String
"ulink" -> (Inlines -> Inlines) -> DB m Inlines
forall (m :: * -> *).
PandocMonad m =>
(Inlines -> Inlines) -> StateT DBState m Inlines
innerInlines (Text -> Text -> Inlines -> Inlines
link (String -> Element -> Text
attrValue String
"url" Element
e) Text
"")
String
"link" -> do
Inlines
ils <- (Inlines -> Inlines) -> DB m Inlines
forall (m :: * -> *).
PandocMonad m =>
(Inlines -> Inlines) -> StateT DBState m Inlines
innerInlines Inlines -> Inlines
forall a. a -> a
id
let href :: Text
href = case QName -> Element -> Maybe String
findAttr (String -> Maybe String -> Maybe String -> QName
QName String
"href" (String -> Maybe String
forall a. a -> Maybe a
Just String
"http://www.w3.org/1999/xlink") Maybe String
forall a. Maybe a
Nothing) Element
e of
Just String
h -> String -> Text
T.pack String
h
Maybe String
_ -> Text
"#" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> String -> Element -> Text
attrValue String
"linkend" Element
e
let ils' :: Inlines
ils' = if Inlines
ils Inlines -> Inlines -> Bool
forall a. Eq a => a -> a -> Bool
== Inlines
forall a. Monoid a => a
mempty then Text -> Inlines
str Text
href else Inlines
ils
let attr :: (Text, [Text], [a])
attr = (String -> Element -> Text
attrValue String
"id" Element
e, Text -> [Text]
T.words (Text -> [Text]) -> Text -> [Text]
forall a b. (a -> b) -> a -> b
$ String -> Element -> Text
attrValue String
"role" Element
e, [])
Inlines -> DB m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> DB m Inlines) -> Inlines -> DB m Inlines
forall a b. (a -> b) -> a -> b
$ Attr -> Text -> Text -> Inlines -> Inlines
linkWith Attr
forall a. (Text, [Text], [a])
attr Text
href Text
"" Inlines
ils'
String
"foreignphrase" -> (Inlines -> Inlines) -> DB m Inlines
forall (m :: * -> *).
PandocMonad m =>
(Inlines -> Inlines) -> StateT DBState m Inlines
innerInlines Inlines -> Inlines
emph
String
"emphasis" -> case String -> Element -> Text
attrValue String
"role" Element
e of
Text
"bold" -> (Inlines -> Inlines) -> DB m Inlines
forall (m :: * -> *).
PandocMonad m =>
(Inlines -> Inlines) -> StateT DBState m Inlines
innerInlines Inlines -> Inlines
strong
Text
"strong" -> (Inlines -> Inlines) -> DB m Inlines
forall (m :: * -> *).
PandocMonad m =>
(Inlines -> Inlines) -> StateT DBState m Inlines
innerInlines Inlines -> Inlines
strong
Text
"strikethrough" -> (Inlines -> Inlines) -> DB m Inlines
forall (m :: * -> *).
PandocMonad m =>
(Inlines -> Inlines) -> StateT DBState m Inlines
innerInlines Inlines -> Inlines
strikeout
Text
_ -> (Inlines -> Inlines) -> DB m Inlines
forall (m :: * -> *).
PandocMonad m =>
(Inlines -> Inlines) -> StateT DBState m Inlines
innerInlines Inlines -> Inlines
emph
String
"footnote" -> Blocks -> Inlines
note (Blocks -> Inlines) -> ([Blocks] -> Blocks) -> [Blocks] -> Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Blocks] -> Blocks
forall a. Monoid a => [a] -> a
mconcat ([Blocks] -> Inlines) -> StateT DBState m [Blocks] -> DB m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
(Content -> StateT DBState m Blocks)
-> [Content] -> StateT DBState m [Blocks]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM Content -> StateT DBState m Blocks
forall (m :: * -> *). PandocMonad m => Content -> DB m Blocks
parseBlock (Element -> [Content]
elContent Element
e)
String
"title" -> Inlines -> DB m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return Inlines
forall a. Monoid a => a
mempty
String
"affiliation" -> DB m Inlines
skip
String
"br" -> Inlines -> DB m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return Inlines
linebreak
String
_ -> DB m Inlines
skip DB m Inlines -> DB m Inlines -> DB m Inlines
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> (Inlines -> Inlines) -> DB m Inlines
forall (m :: * -> *).
PandocMonad m =>
(Inlines -> Inlines) -> StateT DBState m Inlines
innerInlines Inlines -> Inlines
forall a. a -> a
id
where skip :: DB m Inlines
skip = do
m () -> StateT DBState m ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m () -> StateT DBState m ()) -> m () -> StateT DBState m ()
forall a b. (a -> b) -> a -> b
$ LogMessage -> m ()
forall (m :: * -> *). PandocMonad m => LogMessage -> m ()
report (LogMessage -> m ()) -> LogMessage -> m ()
forall a b. (a -> b) -> a -> b
$ Text -> LogMessage
IgnoredElement (Text -> LogMessage) -> Text -> LogMessage
forall a b. (a -> b) -> a -> b
$ String -> Text
T.pack (String -> Text) -> String -> Text
forall a b. (a -> b) -> a -> b
$ QName -> String
qName (Element -> QName
elName Element
e)
Inlines -> DB m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return Inlines
forall a. Monoid a => a
mempty
innerInlines :: (Inlines -> Inlines) -> StateT DBState m Inlines
innerInlines Inlines -> Inlines
f = (Inlines -> Inlines) -> Inlines -> Inlines
extractSpaces Inlines -> Inlines
f (Inlines -> Inlines)
-> ([Inlines] -> Inlines) -> [Inlines] -> Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Inlines] -> Inlines
forall a. Monoid a => [a] -> a
mconcat ([Inlines] -> Inlines)
-> StateT DBState m [Inlines] -> StateT DBState m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
(Content -> StateT DBState m Inlines)
-> [Content] -> StateT DBState m [Inlines]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM Content -> StateT DBState m Inlines
forall (m :: * -> *). PandocMonad m => Content -> DB m Inlines
parseInline (Element -> [Content]
elContent Element
e)
codeWithLang :: DB m Inlines
codeWithLang = do
let classes' :: [Text]
classes' = case String -> Element -> Text
attrValue String
"language" Element
e of
Text
"" -> []
Text
l -> [Text
l]
Inlines -> DB m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> DB m Inlines) -> Inlines -> DB m Inlines
forall a b. (a -> b) -> a -> b
$ Attr -> Text -> Inlines
codeWith (String -> Element -> Text
attrValue String
"id" Element
e,[Text]
classes',[]) (Text -> Inlines) -> Text -> Inlines
forall a b. (a -> b) -> a -> b
$ String -> Text
T.pack (String -> Text) -> String -> Text
forall a b. (a -> b) -> a -> b
$ Element -> String
strContentRecursive Element
e
simpleList :: DB m Inlines
simpleList = [Inlines] -> Inlines
forall a. Monoid a => [a] -> a
mconcat ([Inlines] -> Inlines)
-> ([Inlines] -> [Inlines]) -> [Inlines] -> Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Inlines -> [Inlines] -> [Inlines]
forall a. a -> [a] -> [a]
intersperse (Text -> Inlines
str Text
"," Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines
space) ([Inlines] -> Inlines)
-> StateT DBState m [Inlines] -> DB m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Element -> DB m Inlines)
-> [Element] -> StateT DBState m [Inlines]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM Element -> DB m Inlines
forall (m :: * -> *). PandocMonad m => Element -> DB m Inlines
getInlines
((Element -> Bool) -> Element -> [Element]
filterChildren (Text -> Element -> Bool
named Text
"member") Element
e)
segmentedList :: DB m Inlines
segmentedList = do
Inlines
tit <- DB m Inlines
-> (Element -> DB m Inlines) -> Maybe Element -> DB m Inlines
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (Inlines -> DB m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return Inlines
forall a. Monoid a => a
mempty) Element -> DB m Inlines
forall (m :: * -> *). PandocMonad m => Element -> DB m Inlines
getInlines (Maybe Element -> DB m Inlines) -> Maybe Element -> DB m Inlines
forall a b. (a -> b) -> a -> b
$ (Element -> Bool) -> Element -> Maybe Element
filterChild (Text -> Element -> Bool
named Text
"title") Element
e
[Inlines]
segtits <- (Element -> DB m Inlines)
-> [Element] -> StateT DBState m [Inlines]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM Element -> DB m Inlines
forall (m :: * -> *). PandocMonad m => Element -> DB m Inlines
getInlines ([Element] -> StateT DBState m [Inlines])
-> [Element] -> StateT DBState m [Inlines]
forall a b. (a -> b) -> a -> b
$ (Element -> Bool) -> Element -> [Element]
filterChildren (Text -> Element -> Bool
named Text
"segtitle") Element
e
[[Inlines]]
segitems <- (Element -> StateT DBState m [Inlines])
-> [Element] -> StateT DBState m [[Inlines]]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM ((Element -> DB m Inlines)
-> [Element] -> StateT DBState m [Inlines]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM Element -> DB m Inlines
forall (m :: * -> *). PandocMonad m => Element -> DB m Inlines
getInlines ([Element] -> StateT DBState m [Inlines])
-> (Element -> [Element]) -> Element -> StateT DBState m [Inlines]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Element -> Bool) -> Element -> [Element]
filterChildren (Text -> Element -> Bool
named Text
"seg"))
([Element] -> StateT DBState m [[Inlines]])
-> [Element] -> StateT DBState m [[Inlines]]
forall a b. (a -> b) -> a -> b
$ (Element -> Bool) -> Element -> [Element]
filterChildren (Text -> Element -> Bool
named Text
"seglistitem") Element
e
let toSeg :: [Inlines] -> Inlines
toSeg = [Inlines] -> Inlines
forall a. Monoid a => [a] -> a
mconcat ([Inlines] -> Inlines)
-> ([Inlines] -> [Inlines]) -> [Inlines] -> Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Inlines -> Inlines -> Inlines)
-> [Inlines] -> [Inlines] -> [Inlines]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith (\Inlines
x Inlines
y -> Inlines -> Inlines
strong (Inlines
x Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Text -> Inlines
str Text
":") Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines
space Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<>
Inlines
y Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines
linebreak) [Inlines]
segtits
let segs :: Inlines
segs = [Inlines] -> Inlines
forall a. Monoid a => [a] -> a
mconcat ([Inlines] -> Inlines) -> [Inlines] -> Inlines
forall a b. (a -> b) -> a -> b
$ ([Inlines] -> Inlines) -> [[Inlines]] -> [Inlines]
forall a b. (a -> b) -> [a] -> [b]
map [Inlines] -> Inlines
toSeg [[Inlines]]
segitems
let tit' :: Inlines
tit' = if Inlines
tit Inlines -> Inlines -> Bool
forall a. Eq a => a -> a -> Bool
== Inlines
forall a. Monoid a => a
mempty
then Inlines
forall a. Monoid a => a
mempty
else Inlines -> Inlines
strong Inlines
tit Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines
linebreak
Inlines -> DB m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> DB m Inlines) -> Inlines -> DB m Inlines
forall a b. (a -> b) -> a -> b
$ Inlines
linebreak Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines
tit' Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines
segs
keycombo :: [Inlines] -> Inlines
keycombo = Attr -> Inlines -> Inlines
spanWith (Text
"",[Text
"keycombo"],[]) (Inlines -> Inlines)
-> ([Inlines] -> Inlines) -> [Inlines] -> Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
[Inlines] -> Inlines
forall a. Monoid a => [a] -> a
mconcat ([Inlines] -> Inlines)
-> ([Inlines] -> [Inlines]) -> [Inlines] -> Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Inlines -> [Inlines] -> [Inlines]
forall a. a -> [a] -> [a]
intersperse (Text -> Inlines
str Text
"+")
menuchoice :: [Inlines] -> Inlines
menuchoice = Attr -> Inlines -> Inlines
spanWith (Text
"",[Text
"menuchoice"],[]) (Inlines -> Inlines)
-> ([Inlines] -> Inlines) -> [Inlines] -> Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
[Inlines] -> Inlines
forall a. Monoid a => [a] -> a
mconcat ([Inlines] -> Inlines)
-> ([Inlines] -> [Inlines]) -> [Inlines] -> Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Inlines -> [Inlines] -> [Inlines]
forall a. a -> [a] -> [a]
intersperse (Text -> Inlines
text Text
" > ")
isGuiMenu :: Content -> Bool
isGuiMenu (Elem Element
x) = Text -> Element -> Bool
named Text
"guimenu" Element
x Bool -> Bool -> Bool
|| Text -> Element -> Bool
named Text
"guisubmenu" Element
x Bool -> Bool -> Bool
||
Text -> Element -> Bool
named Text
"guimenuitem" Element
x
isGuiMenu Content
_ = Bool
False
findElementById :: Text -> [Content] -> Maybe Element
findElementById Text
idString [Content]
content
= [Maybe Element] -> Maybe Element
forall (t :: * -> *) (f :: * -> *) a.
(Foldable t, Alternative f) =>
t (f a) -> f a
asum [(Element -> Bool) -> Element -> Maybe Element
filterElement (\Element
x -> String -> Element -> Text
attrValue String
"id" Element
x Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== Text
idString) Element
el | Elem Element
el <- [Content]
content]
xrefTitleByElem :: Element -> Text
xrefTitleByElem Element
el
| Bool -> Bool
not (Text -> Bool
T.null Text
xrefLabel) = Text
xrefLabel
| Bool
otherwise = case QName -> String
qName (Element -> QName
elName Element
el) of
String
"chapter" -> String -> Element -> Text
descendantContent String
"title" Element
el
String
"section" -> String -> Element -> Text
descendantContent String
"title" Element
el
String
"sect1" -> String -> Element -> Text
descendantContent String
"title" Element
el
String
"sect2" -> String -> Element -> Text
descendantContent String
"title" Element
el
String
"sect3" -> String -> Element -> Text
descendantContent String
"title" Element
el
String
"sect4" -> String -> Element -> Text
descendantContent String
"title" Element
el
String
"sect5" -> String -> Element -> Text
descendantContent String
"title" Element
el
String
"cmdsynopsis" -> String -> Element -> Text
descendantContent String
"command" Element
el
String
"funcsynopsis" -> String -> Element -> Text
descendantContent String
"function" Element
el
String
_ -> String -> Text
T.pack (String -> Text) -> String -> Text
forall a b. (a -> b) -> a -> b
$ QName -> String
qName (Element -> QName
elName Element
el) String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
"_title"
where
xrefLabel :: Text
xrefLabel = String -> Element -> Text
attrValue String
"xreflabel" Element
el
descendantContent :: String -> Element -> Text
descendantContent String
name = Text -> (Element -> Text) -> Maybe Element -> Text
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Text
"???" (String -> Text
T.pack (String -> Text) -> (Element -> String) -> Element -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Element -> String
strContent)
(Maybe Element -> Text)
-> (Element -> Maybe Element) -> Element -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (QName -> Bool) -> Element -> Maybe Element
filterElementName (\QName
n -> QName -> String
qName QName
n String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== String
name)
equation
:: Monad m
=> Element
-> (Text -> Inlines)
-> m Inlines
equation :: Element -> (Text -> Inlines) -> m Inlines
equation Element
e Text -> Inlines
constructor =
Inlines -> m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> m Inlines) -> Inlines -> m Inlines
forall a b. (a -> b) -> a -> b
$ [Inlines] -> Inlines
forall a. Monoid a => [a] -> a
mconcat ([Inlines] -> Inlines) -> [Inlines] -> Inlines
forall a b. (a -> b) -> a -> b
$ (Text -> Inlines) -> [Text] -> [Inlines]
forall a b. (a -> b) -> [a] -> [b]
map Text -> Inlines
constructor ([Text] -> [Inlines]) -> [Text] -> [Inlines]
forall a b. (a -> b) -> a -> b
$ [Text]
mathMLEquations [Text] -> [Text] -> [Text]
forall a. Semigroup a => a -> a -> a
<> [Text]
latexEquations
where
mathMLEquations :: [Text]
mathMLEquations :: [Text]
mathMLEquations = ([Exp] -> Text) -> [[Exp]] -> [Text]
forall a b. (a -> b) -> [a] -> [b]
map [Exp] -> Text
writeTeX ([[Exp]] -> [Text]) -> [[Exp]] -> [Text]
forall a b. (a -> b) -> a -> b
$ [Either Text [Exp]] -> [[Exp]]
forall a b. [Either a b] -> [b]
rights ([Either Text [Exp]] -> [[Exp]]) -> [Either Text [Exp]] -> [[Exp]]
forall a b. (a -> b) -> a -> b
$ (Element -> Bool)
-> (Element -> Either Text [Exp]) -> [Either Text [Exp]]
forall b. (Element -> Bool) -> (Element -> b) -> [b]
readMath
(\Element
x -> QName -> String
qName (Element -> QName
elName Element
x) String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== String
"math" Bool -> Bool -> Bool
&& QName -> Maybe String
qPrefix (Element -> QName
elName Element
x) Maybe String -> Maybe String -> Bool
forall a. Eq a => a -> a -> Bool
== String -> Maybe String
forall a. a -> Maybe a
Just String
"mml")
(Text -> Either Text [Exp]
readMathML (Text -> Either Text [Exp])
-> (Element -> Text) -> Element -> Either Text [Exp]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
T.pack (String -> Text) -> (Element -> String) -> Element -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Element -> String
showElement)
latexEquations :: [Text]
latexEquations :: [Text]
latexEquations = (Element -> Bool) -> (Element -> Text) -> [Text]
forall b. (Element -> Bool) -> (Element -> b) -> [b]
readMath (\Element
x -> QName -> String
qName (Element -> QName
elName Element
x) String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== String
"mathphrase")
([Text] -> Text
T.concat ([Text] -> Text) -> (Element -> [Text]) -> Element -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Content -> Text) -> [Content] -> [Text]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Content -> Text
showVerbatimCData ([Content] -> [Text])
-> (Element -> [Content]) -> Element -> [Text]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Element -> [Content]
elContent)
readMath :: (Element -> Bool) -> (Element -> b) -> [b]
readMath :: (Element -> Bool) -> (Element -> b) -> [b]
readMath Element -> Bool
childPredicate Element -> b
fromElement =
(Element -> b) -> [Element] -> [b]
forall a b. (a -> b) -> [a] -> [b]
map (Element -> b
fromElement (Element -> b) -> (Element -> Element) -> Element -> b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall a. Data a => a -> a) -> forall a. Data a => a -> a
everywhere ((QName -> QName) -> a -> a
forall a b. (Typeable a, Typeable b) => (b -> b) -> a -> a
mkT QName -> QName
removePrefix))
([Element] -> [b]) -> [Element] -> [b]
forall a b. (a -> b) -> a -> b
$ (Element -> Bool) -> Element -> [Element]
filterChildren Element -> Bool
childPredicate Element
e
showVerbatimCData :: Content -> Text
showVerbatimCData :: Content -> Text
showVerbatimCData (Text (CData CDataKind
_ String
d Maybe Line
_)) = String -> Text
T.pack String
d
showVerbatimCData Content
c = String -> Text
T.pack (String -> Text) -> String -> Text
forall a b. (a -> b) -> a -> b
$ Content -> String
showContent Content
c
removePrefix :: QName -> QName
removePrefix :: QName -> QName
removePrefix QName
elname = QName
elname { qPrefix :: Maybe String
qPrefix = Maybe String
forall a. Maybe a
Nothing }