-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Represent cmark-parsed Markdown as a tree of sections -- -- Represent cmark-parsed Markdown as a tree of sections @package cmark-sections @version 0.1.0.3 -- | This library lets you parse Markdown into a hierarchical structure -- (delimited by headings). For instance, let's say your document looks -- like this: -- --
-- This is the preface. -- -- First chapter -- ======================================== -- -- This chapter doesn't have sections. -- -- Second chapter -- ======================================== -- -- First section -- -------------------- -- -- Here's some text. -- -- Second section -- -------------------- -- -- And more text. ---- -- It can be represented as a tree: -- --
-- preface: "This is the preface." -- sections: -- * heading: "First chapter" -- content: "This chapter doesn't have sections." -- sections: [] -- -- * heading: "Second chapter" -- sections: -- * heading: "First section" -- content: "Here's some text." -- sections: [] -- -- * heading: "Second section" -- content: "And more text." -- sections: [] ---- -- That's what this library does. Moreover, it lets you access the -- Markdown source of every node of the tree. -- -- In most cases the only thing you need to do is something like this: -- --
-- nodesToDocument . commonmarkToAnnotatedNodes [optSafe, optNormalize] ---- -- You can preprocess parsed Markdown after doing -- commonmarkToAnnotatedNodes as long as you don't add or remove -- any top-level nodes. module CMark.Sections -- | commonmarkToAnnotatedNodes parses Markdown with the given -- options and extracts nodes from the initial DOCUMENT node. commonmarkToAnnotatedNodes :: [CMarkOption] -> Text -> Annotated [Node] -- | Turn a list of Markdown nodes into a tree. nodesToDocument :: Annotated [Node] -> Document () () -- | A data type for annotating things with their source. In this library -- we only use Annotated [Node], which stands for “some Markdown -- nodes + source”. data Annotated a Ann :: Text -> a -> Annotated a [annSource] :: Annotated a -> Text [annValue] :: Annotated a -> a -- | A section in the Markdown tree. Does not contain subsections (the tree -- is built using Forest from Data.Tree). data Section a b Section :: Int -> Annotated [Node] -> a -> Annotated [Node] -> b -> Section a b -- | Level (from 1 to 6). [level] :: Section a b -> Int [heading] :: Section a b -> Annotated [Node] [headingAnn] :: Section a b -> a -- | Text between the heading and the first subsection. Can be empty. [content] :: Section a b -> Annotated [Node] [contentAnn] :: Section a b -> b -- | The whole parsed Markdown tree. The first parameter is the type of -- annotations for headings (i.e. sections), the second – chunks of text -- (which are all associated with sections except for the preface). data Document a b Document :: Annotated [Node] -> b -> Forest (Section a b) -> Document a b -- | Text before the first section. Can be empty. [preface] :: Document a b -> Annotated [Node] [prefaceAnn] :: Document a b -> b [sections] :: Document a b -> Forest (Section a b) flattenDocument :: Document a b -> Annotated [Node] flattenSection :: Section a b -> Annotated [Node] flattenTree :: Tree (Section a b) -> Annotated [Node] flattenForest :: Forest (Section a b) -> Annotated [Node] instance (GHC.Show.Show a, GHC.Show.Show b) => GHC.Show.Show (CMark.Sections.Document a b) instance (GHC.Classes.Eq a, GHC.Classes.Eq b) => GHC.Classes.Eq (CMark.Sections.Document a b) instance (GHC.Show.Show b, GHC.Show.Show a) => GHC.Show.Show (CMark.Sections.Section a b) instance (GHC.Classes.Eq b, GHC.Classes.Eq a) => GHC.Classes.Eq (CMark.Sections.Section a b) instance Data.Traversable.Traversable CMark.Sections.Annotated instance Data.Foldable.Foldable CMark.Sections.Annotated instance GHC.Base.Functor CMark.Sections.Annotated instance GHC.Show.Show a => GHC.Show.Show (CMark.Sections.Annotated a) instance GHC.Classes.Eq a => GHC.Classes.Eq (CMark.Sections.Annotated a) instance GHC.Base.Monoid a => GHC.Base.Monoid (CMark.Sections.Annotated a)