commonmark-0.2.4: Pure Haskell commonmark parser.

Safe Haskell | Safe-Inferred
Language | Haskell2010

Commonmark.Blocks

Contents

- BlockSpecs

Synopsis

- mkBlockParser :: (Monad m, IsBlock il bl) => [BlockSpec m il bl] -> [BlockParser m il bl bl] -> (ReferenceMap -> [Tok] -> m (Either ParseError il)) -> [BlockParser m il bl Attributes] -> [Tok] -> m (Either ParseError bl)
- defaultBlockSpecs :: (Monad m, IsBlock il bl) => [BlockSpec m il bl]
- data BlockStartResult
  - = BlockStartMatch
  - | BlockStartNoMatchBefore !SourcePos
- data BlockSpec m il bl = BlockSpec {
  - blockType :: !Text
  - blockStart :: BlockParser m il bl BlockStartResult
  - blockCanContain :: BlockSpec m il bl -> Bool
  - blockContainsLines :: !Bool
  - blockParagraph :: !Bool
  - blockContinue :: BlockNode m il bl -> BlockParser m il bl (SourcePos, BlockNode m il bl)
  - blockConstructor :: BlockNode m il bl -> BlockParser m il bl bl
  - blockFinalize :: BlockNode m il bl -> BlockNode m il bl -> BlockParser m il bl (BlockNode m il bl)
  }
- data BlockData m il bl = BlockData {
  - blockSpec :: BlockSpec m il bl
  - blockLines :: [[Tok]]
  - blockStartPos :: [SourcePos]
  - blockData :: !Dynamic
  - blockBlanks :: [Int]
  - blockAttributes :: !Attributes
  }
- defBlockData :: BlockSpec m il bl -> BlockData m il bl
- type BlockNode m il bl = Tree (BlockData m il bl)
- data BPState m il bl = BPState {
  - referenceMap :: !ReferenceMap
  - inlineParser :: ReferenceMap -> [Tok] -> m (Either ParseError il)
  - nodeStack :: [BlockNode m il bl]
  - blockMatched :: !Bool
  - maybeLazy :: !Bool
  - maybeBlank :: !Bool
  - counters :: Map Text Dynamic
  - failurePositions :: Map Text SourcePos
  - attributeParsers :: [ParsecT [Tok] (BPState m il bl) m Attributes]
  - nextAttributes :: !Attributes
  }
- type BlockParser m il bl = ParsecT [Tok] (BPState m il bl) m
- data LinkInfo = LinkInfo {
  - linkDestination :: !Text
  - linkTitle :: !Text
  - linkAttributes :: !Attributes
  - linkPos :: !(Maybe SourcePos)
  }
- defaultFinalizer :: Monad m => BlockNode m il bl -> BlockNode m il bl -> BlockParser m il bl (BlockNode m il bl)
- runInlineParser :: Monad m => [Tok] -> BlockParser m il bl il
- addNodeToStack :: Monad m => BlockNode m bl il -> BlockParser m bl il ()
- collapseNodeStack :: [BlockNode m il bl] -> BlockParser m il bl (BlockNode m il bl)
- getBlockText :: BlockNode m il bl -> [Tok]
- removeIndent :: [Tok] -> [Tok]
- bspec :: BlockNode m il bl -> BlockSpec m il bl
- endOfBlock :: Monad m => BlockParser m il bl ()
- interruptsParagraph :: Monad m => BlockParser m bl il Bool
- linkReferenceDef :: Monad m => ParsecT [Tok] s m Attributes -> ParsecT [Tok] s m ((SourceRange, Text), LinkInfo)
- renderChildren :: (Monad m, IsBlock il bl) => BlockNode m il bl -> BlockParser m il bl [bl]
- reverseSubforests :: Tree a -> Tree a
- getParentListType :: Monad m => BlockParser m il bl (Maybe ListType)
- docSpec :: (Monad m, IsBlock il bl, Monoid bl) => BlockSpec m il bl
- indentedCodeSpec :: (Monad m, IsBlock il bl) => BlockSpec m il bl
- fencedCodeSpec :: (Monad m, IsBlock il bl) => BlockSpec m il bl
- blockQuoteSpec :: (Monad m, IsBlock il bl) => BlockSpec m il bl
- atxHeadingSpec :: (Monad m, IsBlock il bl) => BlockSpec m il bl
- setextHeadingSpec :: (Monad m, IsBlock il bl) => BlockSpec m il bl
- thematicBreakSpec :: (Monad m, IsBlock il bl) => BlockSpec m il bl
- listItemSpec :: (Monad m, IsBlock il bl) => BlockParser m il bl ListType -> BlockSpec m il bl
- bulletListMarker :: Monad m => BlockParser m il bl ListType
- orderedListMarker :: Monad m => BlockParser m il bl ListType
- rawHtmlSpec :: (Monad m, IsBlock il bl) => BlockSpec m il bl
- attributeSpec :: (Monad m, IsBlock il bl) => BlockSpec m il bl
- paraSpec :: (Monad m, IsBlock il bl) => BlockSpec m il bl
- plainSpec :: (Monad m, IsBlock il bl) => BlockSpec m il bl

# Documentation

mkBlockParser #

Arguments

:: (Monad m, IsBlock il bl) |
=> [BlockSpec m il bl] | Defines block syntax
-> [BlockParser m il bl bl] | Parsers to run at end
-> (ReferenceMap -> [Tok] -> m (Either ParseError il)) | Inline parser
-> [BlockParser m il bl Attributes] | attribute parsers
-> [Tok] | Tokenized commonmark input
-> m (Either ParseError bl) | Result or error

defaultBlockSpecs :: (Monad m, IsBlock il bl) => [BlockSpec m il bl] #

data BlockStartResult #

Constructors

BlockStartMatch |
BlockStartNoMatchBefore !SourcePos |

#### Instances

Instances details

Show BlockStartResult # |
Instance details Defined in Commonmark.Blocks Methods showsPrec :: Int -> BlockStartResult -> ShowS show :: BlockStartResult -> String showList :: [BlockStartResult] -> ShowS
Eq BlockStartResult # |
Instance details Defined in Commonmark.Blocks Methods (==) :: BlockStartResult -> BlockStartResult -> Bool (/=) :: BlockStartResult -> BlockStartResult -> Bool

data BlockSpec m il bl #

Defines a block-level element type.

Constructors

BlockSpec |

Fields

- blockType :: !Text

  Descriptive name of block type

- blockStart :: BlockParser m il bl BlockStartResult

  Parses beginning of block. The parser should verify any preconditions, parse the opening of the block, and add the new block to the block stack using `addNodeToStack`, returning `BlockStartMatch` on success. If the match fails, the parser can either fail or return `BlockStartNoMatchBefore` and a `SourcePos` before which the parser is known not to succeed (this will be stored in `failurePositions` for the line, to ensure that future matches won't be attempted until after that position).

- blockCanContain :: BlockSpec m il bl -> Bool

  Returns True if this kind of block can contain the specified block type.

- blockContainsLines :: !Bool

  True if this kind of block can contain text lines.

- blockParagraph :: !Bool

  True if this kind of block is paragraph.

- blockContinue :: BlockNode m il bl -> BlockParser m il bl (SourcePos, BlockNode m il bl)

  Parser that checks to see if the current block (the `BlockNode`) can be kept open. If it fails, the block will be closed, unless we have a lazy paragraph continuation within the block.

- blockConstructor :: BlockNode m il bl -> BlockParser m il bl bl

  Renders the node into its target format, possibly after rendering inline content.

- blockFinalize :: BlockNode m il bl -> BlockNode m il bl -> BlockParser m il bl (BlockNode m il bl)

  Runs when the block is closed, but prior to rendering. The first parameter is the child, the second the parent.

#### Instances

Instances details

Show (BlockSpec m il bl) # |
Instance details Defined in Commonmark.Blocks Methods showsPrec :: Int -> BlockSpec m il bl -> ShowS show :: BlockSpec m il bl -> String showList :: [BlockSpec m il bl] -> ShowS

data BlockData m il bl #

Constructors

BlockData |

Fields

- blockSpec :: BlockSpec m il bl
- blockLines :: [[Tok]]
- blockStartPos :: [SourcePos]
- blockData :: !Dynamic
- blockBlanks :: [Int]
- blockAttributes :: !Attributes

#### Instances

Instances details

Show (BlockData m il bl) # |
Instance details Defined in Commonmark.Blocks Methods showsPrec :: Int -> BlockData m il bl -> ShowS show :: BlockData m il bl -> String showList :: [BlockData m il bl] -> ShowS

defBlockData :: BlockSpec m il bl -> BlockData m il bl #

type BlockNode m il bl = Tree (BlockData m il bl) #

data BPState m il bl #

Constructors

BPState |

Fields

- referenceMap :: !ReferenceMap
- inlineParser :: ReferenceMap -> [Tok] -> m (Either ParseError il)
- nodeStack :: [BlockNode m il bl]
- blockMatched :: !Bool
- maybeLazy :: !Bool
- maybeBlank :: !Bool
- counters :: Map Text Dynamic
- failurePositions :: Map Text SourcePos
- attributeParsers :: [ParsecT [Tok] (BPState m il bl) m Attributes]
- nextAttributes :: !Attributes

type BlockParser m il bl = ParsecT [Tok] (BPState m il bl) m #

data LinkInfo #

Constructors

LinkInfo |

Fields

- linkDestination :: !Text
- linkTitle :: !Text
- linkAttributes :: !Attributes
- linkPos :: !(Maybe SourcePos)

  Position of the reference link definition for references links.

#### Instances

Instances details

Show LinkInfo # |
Instance details Defined in Commonmark.ReferenceMap Methods showsPrec :: Int -> LinkInfo -> ShowS show :: LinkInfo -> String showList :: [LinkInfo] -> ShowS

defaultFinalizer :: Monad m => BlockNode m il bl -> BlockNode m il bl -> BlockParser m il bl (BlockNode m il bl) #

runInlineParser :: Monad m => [Tok] -> BlockParser m il bl il #

addNodeToStack :: Monad m => BlockNode m bl il -> BlockParser m bl il () #

collapseNodeStack :: [BlockNode m il bl] -> BlockParser m il bl (BlockNode m il bl) #

getBlockText :: BlockNode m il bl -> [Tok] #

removeIndent :: [Tok] -> [Tok] #

bspec :: BlockNode m il bl -> BlockSpec m il bl #

endOfBlock :: Monad m => BlockParser m il bl () #

interruptsParagraph :: Monad m => BlockParser m bl il Bool #

linkReferenceDef :: Monad m => ParsecT [Tok] s m Attributes -> ParsecT [Tok] s m ((SourceRange, Text), LinkInfo) #

renderChildren :: (Monad m, IsBlock il bl) => BlockNode m il bl -> BlockParser m il bl [bl] #

reverseSubforests :: Tree a -> Tree a #

getParentListType :: Monad m => BlockParser m il bl (Maybe ListType) #

Get type of the enclosing List block. If the parent isn't a List block, return Nothing.

# BlockSpecs

docSpec :: (Monad m, IsBlock il bl, Monoid bl) => BlockSpec m il bl #

indentedCodeSpec :: (Monad m, IsBlock il bl) => BlockSpec m il bl #

fencedCodeSpec :: (Monad m, IsBlock il bl) => BlockSpec m il bl #

blockQuoteSpec :: (Monad m, IsBlock il bl) => BlockSpec m il bl #

atxHeadingSpec :: (Monad m, IsBlock il bl) => BlockSpec m il bl #

setextHeadingSpec :: (Monad m, IsBlock il bl) => BlockSpec m il bl #

thematicBreakSpec :: (Monad m, IsBlock il bl) => BlockSpec m il bl #

listItemSpec :: (Monad m, IsBlock il bl) => BlockParser m il bl ListType -> BlockSpec m il bl #

bulletListMarker :: Monad m => BlockParser m il bl ListType #

orderedListMarker :: Monad m => BlockParser m il bl ListType #

rawHtmlSpec :: (Monad m, IsBlock il bl) => BlockSpec m il bl #

attributeSpec :: (Monad m, IsBlock il bl) => BlockSpec m il bl #

paraSpec :: (Monad m, IsBlock il bl) => BlockSpec m il bl #

plainSpec :: (Monad m, IsBlock il bl) => BlockSpec m il bl #