Allow fenced code blocks to be indented 1-3 spaces.

This brings our handling of them into alignment with
CommonMark's.

Closes #??.
This commit is contained in:
John MacFarlane 2017-11-09 11:34:50 -08:00
parent f72d763655
commit 1592d38821
2 changed files with 26 additions and 2 deletions

View file

@ -623,8 +623,9 @@ indentedLine = indentSpaces >> anyLineNewline
blockDelimiter :: PandocMonad m blockDelimiter :: PandocMonad m
=> (Char -> Bool) => (Char -> Bool)
-> Maybe Int -> Maybe Int
-> ParserT [Char] st m Int -> ParserT [Char] ParserState m Int
blockDelimiter f len = try $ do blockDelimiter f len = try $ do
skipNonindentSpaces
c <- lookAhead (satisfy f) c <- lookAhead (satisfy f)
case len of case len of
Just l -> count l (char c) >> many (char c) >> return l Just l -> count l (char c) >> many (char c) >> return l
@ -689,6 +690,8 @@ rawAttribute = do
codeBlockFenced :: PandocMonad m => MarkdownParser m (F Blocks) codeBlockFenced :: PandocMonad m => MarkdownParser m (F Blocks)
codeBlockFenced = try $ do codeBlockFenced = try $ do
indentchars <- nonindentSpaces
let indentLevel = length indentchars
c <- try (guardEnabled Ext_fenced_code_blocks >> lookAhead (char '~')) c <- try (guardEnabled Ext_fenced_code_blocks >> lookAhead (char '~'))
<|> (guardEnabled Ext_backtick_code_blocks >> lookAhead (char '`')) <|> (guardEnabled Ext_backtick_code_blocks >> lookAhead (char '`'))
size <- blockDelimiter (== c) Nothing size <- blockDelimiter (== c) Nothing
@ -701,7 +704,8 @@ codeBlockFenced = try $ do
<|> ((\x -> ("",[toLanguageId x],[])) <$> many1 nonspaceChar))) <|> ((\x -> ("",[toLanguageId x],[])) <$> many1 nonspaceChar)))
blankline blankline
contents <- intercalate "\n" <$> contents <- intercalate "\n" <$>
manyTill anyLine (blockDelimiter (== c) (Just size)) manyTill (gobbleAtMostSpaces indentLevel >> anyLine)
(blockDelimiter (== c) (Just size))
blanklines blanklines
return $ return $ return $ return $
case rawattr of case rawattr of

View file

@ -0,0 +1,20 @@
`````
% pandoc -t native
```haskell
let x = y
in y
```
^D
[CodeBlock ("",["haskell"],[]) "let x = y\nin y"]
`````
`````
% pandoc -t native
~~~ {.haskell}
let x = y
in y +
y +
y
~~~
^D
[CodeBlock ("",["haskell"],[]) " let x = y\nin y +\ny +\ny"]
`````