commonmark-0.2.6.1: Pure Haskell commonmark parser.

Safe Haskell | None
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 :: forall (m :: Type -> Type) il bl. (Monad m, IsBlock il bl) => [BlockSpec m il bl]
- data BlockStartResult
  - = BlockStartMatch
  - | BlockStartNoMatchBefore !SourcePos
- data BlockSpec (m :: Type -> Type) 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 :: Type -> Type) il bl = BlockData {
  - blockSpec :: BlockSpec m il bl
  - blockLines :: [[Tok]]
  - blockStartPos :: [SourcePos]
  - blockData :: !Dynamic
  - blockBlanks :: [Int]
  - blockAttributes :: !Attributes
  }
- defBlockData :: forall (m :: Type -> Type) il bl. BlockSpec m il bl -> BlockData m il bl
- type BlockNode (m :: Type -> Type) il bl = Tree (BlockData m il bl)
- data BPState (m :: Type -> Type) 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 :: Type -> Type) il bl = ParsecT [Tok] (BPState m il bl) m
- data LinkInfo = LinkInfo {
  - linkDestination :: !Text
  - linkTitle :: !Text
  - linkAttributes :: !Attributes
  - linkPos :: !(Maybe SourcePos)
  }
- defaultFinalizer :: forall (m :: Type -> Type) il bl. Monad m => BlockNode m il bl -> BlockNode m il bl -> BlockParser m il bl (BlockNode m il bl)
- runInlineParser :: forall (m :: Type -> Type) il bl. Monad m => [Tok] -> BlockParser m il bl il
- addNodeToStack :: forall (m :: Type -> Type) bl il. Monad m => BlockNode m bl il -> BlockParser m bl il ()
- collapseNodeStack :: forall (m :: Type -> Type) il bl. [BlockNode m il bl] -> BlockParser m il bl (BlockNode m il bl)
- getBlockText :: forall (m :: Type -> Type) il bl. BlockNode m il bl -> [Tok]
- removeIndent :: [Tok] -> [Tok]
- bspec :: forall (m :: Type -> Type) il bl. BlockNode m il bl -> BlockSpec m il bl
- endOfBlock :: forall (m :: Type -> Type) il bl. Monad m => BlockParser m il bl ()
- interruptsParagraph :: forall (m :: Type -> Type) bl il. Monad m => BlockParser m bl il Bool
- linkReferenceDef :: forall (m :: Type -> Type) s. Monad m => ParsecT [Tok] s m Attributes -> ParsecT [Tok] s m ((SourceRange, Text), LinkInfo)
- renderChildren :: forall (m :: Type -> Type) il bl. (Monad m, IsBlock il bl) => BlockNode m il bl -> BlockParser m il bl [bl]
- reverseSubforests :: Tree a -> Tree a
- getParentListType :: forall (m :: Type -> Type) il bl. Monad m => BlockParser m il bl (Maybe ListType)
- docSpec :: forall (m :: Type -> Type) il bl. (Monad m, IsBlock il bl, Monoid bl) => BlockSpec m il bl
- indentedCodeSpec :: forall (m :: Type -> Type) il bl. (Monad m, IsBlock il bl) => BlockSpec m il bl
- fencedCodeSpec :: forall (m :: Type -> Type) il bl. (Monad m, IsBlock il bl) => BlockSpec m il bl
- blockQuoteSpec :: forall (m :: Type -> Type) il bl. (Monad m, IsBlock il bl) => BlockSpec m il bl
- atxHeadingSpec :: forall (m :: Type -> Type) il bl. (Monad m, IsBlock il bl) => BlockSpec m il bl
- setextHeadingSpec :: forall (m :: Type -> Type) il bl. (Monad m, IsBlock il bl) => BlockSpec m il bl
- thematicBreakSpec :: forall (m :: Type -> Type) il bl. (Monad m, IsBlock il bl) => BlockSpec m il bl
- listItemSpec :: forall (m :: Type -> Type) il bl. (Monad m, IsBlock il bl) => BlockParser m il bl ListType -> BlockSpec m il bl
- bulletListMarker :: forall (m :: Type -> Type) il bl. Monad m => BlockParser m il bl ListType
- orderedListMarker :: forall (m :: Type -> Type) il bl. Monad m => BlockParser m il bl ListType
- rawHtmlSpec :: forall (m :: Type -> Type) il bl. (Monad m, IsBlock il bl) => BlockSpec m il bl
- attributeSpec :: forall (m :: Type -> Type) il bl. (Monad m, IsBlock il bl) => BlockSpec m il bl
- paraSpec :: forall (m :: Type -> Type) il bl. (Monad m, IsBlock il bl) => BlockSpec m il bl
- plainSpec :: forall (m :: Type -> Type) il bl. (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 :: forall (m :: Type -> Type) il bl. (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 :: Type -> Type) 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 :: Type -> Type) 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 :: forall (m :: Type -> Type) il bl. BlockSpec m il bl -> BlockData m il bl #

type BlockNode (m :: Type -> Type) il bl = Tree (BlockData m il bl) #

data BPState (m :: Type -> Type) 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 :: Type -> Type) 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 :: forall (m :: Type -> Type) il bl. Monad m => BlockNode m il bl -> BlockNode m il bl -> BlockParser m il bl (BlockNode m il bl) #

runInlineParser :: forall (m :: Type -> Type) il bl. Monad m => [Tok] -> BlockParser m il bl il #

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

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

getBlockText :: forall (m :: Type -> Type) il bl. BlockNode m il bl -> [Tok] #

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

bspec :: forall (m :: Type -> Type) il bl. BlockNode m il bl -> BlockSpec m il bl #

endOfBlock :: forall (m :: Type -> Type) il bl. Monad m => BlockParser m il bl () #

interruptsParagraph :: forall (m :: Type -> Type) bl il. Monad m => BlockParser m bl il Bool #

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

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

reverseSubforests :: Tree a -> Tree a #

getParentListType :: forall (m :: Type -> Type) il bl. 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 :: forall (m :: Type -> Type) il bl. (Monad m, IsBlock il bl, Monoid bl) => BlockSpec m il bl #

indentedCodeSpec :: forall (m :: Type -> Type) il bl. (Monad m, IsBlock il bl) => BlockSpec m il bl #

fencedCodeSpec :: forall (m :: Type -> Type) il bl. (Monad m, IsBlock il bl) => BlockSpec m il bl #

blockQuoteSpec :: forall (m :: Type -> Type) il bl. (Monad m, IsBlock il bl) => BlockSpec m il bl #

atxHeadingSpec :: forall (m :: Type -> Type) il bl. (Monad m, IsBlock il bl) => BlockSpec m il bl #

setextHeadingSpec :: forall (m :: Type -> Type) il bl. (Monad m, IsBlock il bl) => BlockSpec m il bl #

thematicBreakSpec :: forall (m :: Type -> Type) il bl. (Monad m, IsBlock il bl) => BlockSpec m il bl #

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

bulletListMarker :: forall (m :: Type -> Type) il bl. Monad m => BlockParser m il bl ListType #

orderedListMarker :: forall (m :: Type -> Type) il bl. Monad m => BlockParser m il bl ListType #

rawHtmlSpec :: forall (m :: Type -> Type) il bl. (Monad m, IsBlock il bl) => BlockSpec m il bl #

attributeSpec :: forall (m :: Type -> Type) il bl. (Monad m, IsBlock il bl) => BlockSpec m il bl #

paraSpec :: forall (m :: Type -> Type) il bl. (Monad m, IsBlock il bl) => BlockSpec m il bl #

plainSpec :: forall (m :: Type -> Type) il bl. (Monad m, IsBlock il bl) => BlockSpec m il bl #