@@ -28,7 +28,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2828Parsers for org-mode headlines and document subtrees
2929-}
3030module Text.Pandoc.Readers.Org.DocumentTree
31− ( headline
31+ ( documentTree
3232 , headlineToBlocks
3333 ) where
3434
@@ -43,11 +43,42 @@ import Text.Pandoc.Readers.Org.BlockStarts
4343import Text.Pandoc.Readers.Org.Parsing
4444import Text.Pandoc.Readers.Org.ParserState
4545
46+import qualified Data.Map as Map
4647import qualified Text.Pandoc.Builder as B
4748
4849--
4950-- Org headers
5051--
52+
53+-- | Parse input as org document tree.
54+documentTree :: PandocMonad m
55+ => OrgParser m (F Blocks)
56+ -> OrgParser m (F Inlines)
57+ -> OrgParser m (F Headline)
58+documentTree blocks inline = do
59+ initialBlocks <- blocks
60+ headlines <- sequence <$> manyTill (headline blocks inline 1) eof
61+ title <- fmap (getTitle . unMeta) . orgStateMeta <$> getState
62+ return $ do
63+ headlines' <- headlines
64+ initialBlocks' <- initialBlocks
65+ title' <- title
66+ return Headline
67+ { headlineLevel = 0
68+ , headlineTodoMarker = Nothing
69+ , headlineText = B.fromList title'
70+ , headlineTags = mempty
71+ , headlineProperties = mempty
72+ , headlineContents = initialBlocks'
73+ , headlineChildren = headlines'
74+ }
75+ where
76+ getTitle :: Map.Map String MetaValue -> [Inline]
77+ getTitle metamap =
78+ case Map.lookup "title" metamap of
79+ Just (MetaInlines inlns) -> inlns
80+ _ -> []
81+
5182newtype Tag = Tag { fromTag :: String }
5283 deriving (Show, Eq)
5384