" -- | Link conversion loc2target :: Location -> Target loc2target (Web url) = (url,"") loc2target (File file) = (file,"") -- | Conversion of simple inline elements. inlines :: DocInline -> [Inline] inlines (Text str) = [Str str] inlines BlankSpace = [Space] inlines (Grouping grp) = concat . intersperse [Space] $ map inlines grp inlines (Bold inl) = [Strong (inlines inl)] inlines (Emphasis inl) = [Emph (inlines inl)] inlines (DocLink inl loc) = [Link (inlines inl) (loc2target loc)] inlines (DocImage inl loc) = [Image (inlines inl) (loc2target loc)] {- | Conversion of complex elements. The only reason it's in the IO monad is for GraphImage, as it requires IO to create the image. If any one of the conversions fail (i.e. returns 'Nothing'), the entire process fails. In future, may extend this to creating multiple files for top-level sections, in which case the IO monad will be required for that as well. -} elements :: PandocProcess -> DocElement -> IO (Maybe [Block]) elements p (Section lbl elems) = do let n = secLevel p p' = p { secLevel = n + 1} sec = Header n (inlines lbl) elems' <- multiElems p' elems return (fmap (sec:) elems') elements _ (Paragraph inls) = return $ Just [Para (concatMap inlines inls)] elements p (Enumeration elems) = do elems' <- multiElems' p elems let attrs = (1,DefaultStyle,DefaultDelim) list = fmap (OrderedList attrs) elems' return (fmap return list) elements p (Itemized elems) = do elems' <- multiElems' p elems return (fmap (return . BulletList) elems') elements _ (Definitions defs) = return . Just . return . DefinitionList $ map (inlines *** ((:[]) . (:[]) . Plain . inlines)) defs elements p (GraphImage dg) = elements p =<< createGraph (visParams p) dg -- | Concatenate the result of multiple calls to 'elements'. multiElems :: PandocProcess -> [DocElement] -> IO (Maybe [Block]) multiElems p elems = do elems' <- mapM (elements p) elems if any isNothing elems' then return Nothing else return (Just $ concatMap fromJust elems') -- | As for 'multiElems', but don't @concat@ the resulting 'Block's. multiElems' :: PandocProcess -> [DocElement] -> IO (Maybe [[Block]]) multiElems' p elems = do elems' <- mapM (elements p) elems if any isNothing elems' then return Nothing else return (Just $ map fromJust elems')" ++ str ++ "