commonmark-0.2.3: 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 Source #

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] Source #

data BlockStartResult Source #

Constructors

BlockStartMatch |
BlockStartNoMatchBefore !SourcePos |

#### Instances

Instances details

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

data BlockSpec m il bl Source #

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) Source # |
Instance details Defined in Commonmark.Blocks Methods showsPrec :: Int -> BlockSpec m il bl -> ShowS Source # show :: BlockSpec m il bl -> String Source # showList :: [BlockSpec m il bl] -> ShowS Source #

data BlockData m il bl Source #

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) Source # |
Instance details Defined in Commonmark.Blocks Methods showsPrec :: Int -> BlockData m il bl -> ShowS Source # show :: BlockData m il bl -> String Source # showList :: [BlockData m il bl] -> ShowS Source #

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

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

data BPState m il bl Source #

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 Source #

data LinkInfo Source #

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 Source # |
Instance details Defined in Commonmark.ReferenceMap Methods showsPrec :: Int -> LinkInfo -> ShowS Source # show :: LinkInfo -> String Source # showList :: [LinkInfo] -> ShowS Source #

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

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

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

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

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

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

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

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

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

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

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

reverseSubforests :: Tree a -> Tree a Source #

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

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 Source #

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

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

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

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

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

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

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

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

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

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

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

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

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