Skip to content

Commit

Permalink
Added a LineBlock block element.
Browse files Browse the repository at this point in the history
See second point in jgm/pandoc#1852 and discussion in jgm/pandoc#1545.

Substantial changes in pandoc are still needed.
  • Loading branch information
tarleb committed Aug 15, 2016
1 parent fd6eba4 commit 859f6d6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Text/Pandoc/Builder.hs
Expand Up @@ -147,6 +147,7 @@ module Text.Pandoc.Builder ( module Text.Pandoc.Definition
-- * Block list builders
, para
, plain
, lineBlock
, codeBlockWith
, codeBlock
, rawBlock
Expand Down Expand Up @@ -430,6 +431,9 @@ plain ils = if isNull ils
then mempty
else singleton . Plain . toList $ ils

lineBlock :: [Inlines] -> Blocks
lineBlock = singleton . LineBlock . map toList

-- | A code block with attributes.
codeBlockWith :: Attr -> String -> Blocks
codeBlockWith attrs = singleton . CodeBlock attrs
Expand Down
1 change: 1 addition & 0 deletions Text/Pandoc/Definition.hs
Expand Up @@ -211,6 +211,7 @@ instance Ord Format where
data Block
= Plain [Inline] -- ^ Plain text, not a paragraph
| Para [Inline] -- ^ Paragraph
| LineBlock [[Inline]] -- ^ Multiple non-breaking lines
| CodeBlock Attr String -- ^ Code block (literal) with attributes
| RawBlock Format String -- ^ Raw block
| BlockQuote [Block] -- ^ Block quote (list of blocks)
Expand Down
6 changes: 6 additions & 0 deletions Text/Pandoc/Walk.hs
Expand Up @@ -186,6 +186,7 @@ instance Walkable Inline Inline where
instance Walkable Inline Block where
walk f (Para xs) = Para $ walk f xs
walk f (Plain xs) = Plain $ walk f xs
walk f (LineBlock xs) = LineBlock $ walk f xs
walk f (CodeBlock attr s) = CodeBlock attr s
walk f (RawBlock t s) = RawBlock t s
walk f (BlockQuote bs) = BlockQuote $ walk f bs
Expand All @@ -200,6 +201,7 @@ instance Walkable Inline Block where

walkM f (Para xs) = Para <$> walkM f xs
walkM f (Plain xs) = Plain <$> walkM f xs
walkM f (LineBlock xs) = LineBlock <$> walkM f xs
walkM f (CodeBlock attr s) = return $ CodeBlock attr s
walkM f (RawBlock t s) = return $ RawBlock t s
walkM f (BlockQuote bs) = BlockQuote <$> walkM f bs
Expand All @@ -218,6 +220,7 @@ instance Walkable Inline Block where

query f (Para xs) = query f xs
query f (Plain xs) = query f xs
query f (LineBlock xs) = query f xs
query f (CodeBlock attr s) = mempty
query f (RawBlock t s) = mempty
query f (BlockQuote bs) = query f bs
Expand All @@ -233,6 +236,7 @@ instance Walkable Inline Block where
instance Walkable Block Block where
walk f (Para xs) = f $ Para $ walk f xs
walk f (Plain xs) = f $ Plain $ walk f xs
walk f (LineBlock xs) = f $ LineBlock $ walk f xs
walk f (CodeBlock attr s) = f $ CodeBlock attr s
walk f (RawBlock t s) = f $ RawBlock t s
walk f (BlockQuote bs) = f $ BlockQuote $ walk f bs
Expand All @@ -248,6 +252,7 @@ instance Walkable Block Block where

walkM f (Para xs) = Para <$> walkM f xs >>= f
walkM f (Plain xs) = Plain <$> walkM f xs >>= f
walkM f (LineBlock xs) = LineBlock <$> walkM f xs >>= f
walkM f (CodeBlock attr s) = f $ CodeBlock attr s
walkM f (RawBlock t s) = f $ RawBlock t s
walkM f (BlockQuote bs) = BlockQuote <$> walkM f bs >>= f
Expand All @@ -265,6 +270,7 @@ instance Walkable Block Block where

query f (Para xs) = f (Para xs) <> query f xs
query f (Plain xs) = f (Plain xs) <> query f xs
query f (LineBlock xs) = f (LineBlock xs) <> query f xs
query f (CodeBlock attr s) = f $ CodeBlock attr s
query f (RawBlock t s) = f $ RawBlock t s
query f (BlockQuote bs) = f (BlockQuote bs) <> query f bs
Expand Down

0 comments on commit 859f6d6

Please sign in to comment.