Text.MMark.Extension
Contents
Description
This module provides building blocks for extension creation.
We suggest using a qualified import, like this:
import Text.MMark.Extension (Bni, Block (..), Inline (..)) import qualified Text.MMark.Extension as Ext
Details about extensions
There are four kinds of extension-producing functions. They correspond internally to four functions that are applied to the parsed document in turn:
blockTransis applied first, as it's quite general and can change block-level structure of document as well as inline-level structure.
inlineTransis applied to every inline in the document obtained in the previous step.
inlineRenderis applied to every inline; this function produces HTML rendition of the inlines and we also preserve the original inline so
blockRendercan look at it (sometimes it is useful).
blockRenderis applied to every block to obtain HTML rendition of the whole document.
When one combines different extensions, extensions of the same kind get fused together into a single function. This allows for faster processing in the end.
Synopsis
- data Extension
- type Bni = Block (NonEmpty Inline)
- data Block a
- blockTrans :: (Bni -> Bni) -> Extension
- blockRender :: ((Block (Ois, Html ()) -> Html ()) -> Block (Ois, Html ()) -> Html ()) -> Extension
- data Ois
- getOis :: Ois -> NonEmpty Inline
- data Inline
- inlineTrans :: (Inline -> Inline) -> Extension
- inlineRender :: ((Inline -> Html ()) -> Inline -> Html ()) -> Extension
- scanner :: a -> (a -> Bni -> a) -> Fold Bni a
- asPlainText :: NonEmpty Inline -> Text
- headerId :: NonEmpty Inline -> Text
- headerFragment :: Text -> URI
Extension construction
Block-level manipulation
type Bni = Block (NonEmpty Inline) Source #
We can think of a markdown document as a collection of
blocks—structural elements like paragraphs, block quotations, lists,
headings, thematic breaks, and code blocks. Some blocks (like block
quotes and list items) contain other blocks; others (like headings and
paragraphs) contain inline content, see
Inline.
We can divide blocks into two types: container blocks, which can contain other blocks, and leaf blocks, which cannot.
Constructors
Instances
blockTrans :: (Bni -> Bni) -> Extension Source #
blockRender :: ((Block (Ois, Html ()) -> Html ()) -> Block (Ois, Html ()) -> Html ()) -> Extension Source #
Create an extension that replaces or augments rendering of
Blocks of
markdown document. The argument of
blockRender will be given the
rendering function constructed so far
as well as an actual block to render—
Block (
Ois,
Html ()) ->
Html ()
. The user can then decide whether to replace/reuse that function to
get the final rendering of the type
Block (
Ois,
Html
())
.
Html ()
The argument of
blockRender can also be thought of as a function that
transforms the rendering function constructed so far:
(Block (Ois, Html ()) -> Html ()) -> (Block (Ois, Html ()) -> Html ())
See also:
Ois and
getOis.
A wrapper for “originial inlines”. Source inlines are wrapped in this
during rendering of inline components and then it's available to block
render, but only for inspection. Altering of
Ois is not possible
because the user cannot construct a value of the
Ois type, she can only
inspect it with
getOis.
Inline-level manipulation
inlineTrans :: (Inline -> Inline) -> Extension Source #
inlineRender :: ((Inline -> Html ()) -> Inline -> Html ()) -> Extension Source #
Create an extension that replaces or augments rendering of
Inlines of
markdown document. This works like
blockRender.
Scanner construction
Utils
asPlainText :: NonEmpty Inline -> Text Source #
headerId :: NonEmpty Inline -> Text Source #
Generate value of id attribute for a given header. This is used during rendering and also can be used to get id of a header for linking to it in extensions.
See also:
headerFragment.