-- 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.3.0 -- | 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 . commonmarkToNodesWithSource [optSafe, optNormalize] ---- -- You can preprocess parsed Markdown after doing -- commonmarkToNodesWithSource as long as you don't add or remove -- any top-level nodes. module CMark.Sections -- | commonmarkToNodesWithSource parses Markdown with the given -- options and extracts nodes from the initial DOCUMENT node. commonmarkToNodesWithSource :: [CMarkOption] -> Text -> WithSource [Node] -- | Turn a list of Markdown nodes into a tree. nodesToDocument :: WithSource [Node] -> Document () () -- | A data type for annotating things with their source. In this library -- we only use WithSource [Node], which stands for “some -- Markdown nodes + source”. data WithSource a WithSource :: Text -> a -> WithSource a -- | Extract source from WithSource (it's stored there in a field). getSource :: WithSource a -> Text -- | Extract data from WithSource. stripSource :: WithSource a -> a -- | A section in the Markdown tree. -- -- Sections do not contain subsections; i.e. Section isn't -- recursive and the tree structure is provided by Data.Tree. -- -- In a Section a b, the heading is coupled with a value of type -- a, and content – with a value of type b. This is -- occasionally useful. data Section a b Section :: Int -> WithSource [Node] -> a -> WithSource [Node] -> b -> Section a b -- | Level (from 1 to 6). [level] :: Section a b -> Int -- | Heading [heading] :: Section a b -> WithSource [Node] -- | Annotation for the heading [headingAnn] :: Section a b -> a -- | Text between the heading and the first subsection. Can be empty. [content] :: Section a b -> WithSource [Node] -- | Annotation for the content [contentAnn] :: Section a b -> b -- | The whole parsed Markdown tree. In a Document a b, headings -- are annotated with a and content blocks – with b. data Document a b Document :: WithSource [Node] -> b -> Forest (Section a b) -> Document a b -- | Text before the first section. Can be empty. [preface] :: Document a b -> WithSource [Node] -- | Annotation for the preface [prefaceAnn] :: Document a b -> b -- | A tree with the sections comprising the rest of the document [sections] :: Document a b -> Forest (Section a b) -- | Turn the whole parsed-and-broken-down Document into a list of -- nodes. flattenDocument :: Document a b -> WithSource [Node] -- | Turn a section into a list of nodes. flattenSection :: Section a b -> WithSource [Node] -- | Turn a Data.Tree Tree into a list of nodes. flattenTree :: Tree (Section a b) -> WithSource [Node] -- | Turn a Data.Tree Forest into a list of nodes. flattenForest :: Forest (Section a b) -> WithSource [Node] instance (Data.Data.Data b, Data.Data.Data a) => Data.Data.Data (CMark.Sections.Document a b) instance GHC.Generics.Generic (CMark.Sections.Document a b) 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 (Data.Data.Data b, Data.Data.Data a) => Data.Data.Data (CMark.Sections.Section a b) instance GHC.Generics.Generic (CMark.Sections.Section 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.Data.Data a => Data.Data.Data (CMark.Sections.WithSource a) instance GHC.Generics.Generic (CMark.Sections.WithSource a) instance Data.Traversable.Traversable CMark.Sections.WithSource instance Data.Foldable.Foldable CMark.Sections.WithSource instance GHC.Base.Functor CMark.Sections.WithSource instance GHC.Show.Show a => GHC.Show.Show (CMark.Sections.WithSource a) instance GHC.Classes.Eq a => GHC.Classes.Eq (CMark.Sections.WithSource a) instance GHC.Base.Monoid a => GHC.Base.Monoid (CMark.Sections.WithSource a)