Safe Haskell | None |
---|---|
Language | Haskell2010 |
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.
- commonmarkToAnnotatedNodes :: [CMarkOption] -> Text -> Annotated [Node]
- nodesToDocument :: Annotated [Node] -> Document () ()
- data Annotated a = Ann {}
- data Section a b = Section {
- level :: Int
- heading :: Annotated [Node]
- headingAnn :: a
- content :: Annotated [Node]
- contentAnn :: b
- data Document a b = Document {}
- 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]
Parse Markdown to trees
commonmarkToAnnotatedNodes :: [CMarkOption] -> Text -> Annotated [Node] Source #
commonmarkToAnnotatedNodes
parses Markdown with the given options and extracts nodes from the initial DOCUMENT
node.
nodesToDocument :: Annotated [Node] -> Document () () Source #
Turn a list of Markdown nodes into a tree.
A data type for annotating things with their source. In this library we only use Annotated [Node]
, which stands for “some Markdown nodes + source”.
A section in the Markdown tree. Does not contain subsections (the tree is built using Forest
from Data.Tree).
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).