aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2017-10-24 09:53:29 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2017-10-24 09:53:29 -0700
commit513b16a71b30a04cc91c056a22e2761f7ea554d2 (patch)
tree6eed586aee6ab229e035b69e71eb575372cfaa5a
parent312db3b851a0f3f52f535bc8762b566c2dd560b3 (diff)
downloadpandoc-513b16a71b30a04cc91c056a22e2761f7ea554d2.tar.gz
Fenced divs: ensure that paragraph at end doesn't become Plain.
Added test case.
-rw-r--r--MANUAL.txt14
-rw-r--r--src/Text/Pandoc/Readers/Markdown.hs13
-rw-r--r--test/command/168.md15
3 files changed, 31 insertions, 11 deletions
diff --git a/MANUAL.txt b/MANUAL.txt
index b52e900c3..42b836f0a 100644
--- a/MANUAL.txt
+++ b/MANUAL.txt
@@ -3080,10 +3080,12 @@ starts with a fence containing at least three consecutive
colons plus some attributes. The attributes may optionally
be followed by another string of consecutive colons.
The attribute syntax is exactly as in fenced code blocks (see
-[Extension-fenced_code_attributes], above). The Div ends with
-another line containing a string of at least three consecutive
-colons. The fenced Div should be separated by blank lines from
-preceding and following blocks.
+[Extension-fenced_code_attributes], above). As with fenced
+code blocks, one can use either attributes in curly braces
+or a single unbraced word, which will be treated as a class
+name. The Div ends with another line containing a string of at
+least three consecutive colons. The fenced Div should be
+separated by blank lines from preceding and following blocks.
Example:
@@ -3096,13 +3098,13 @@ Example:
Fenced divs can be nested. Opening fences are distinguished
because they *must* have attributes:
- ::: Warning
+ ::: Warning ::::::
This is a warning.
::: Danger
This is a warning within a warning.
:::
- :::
+ ::::::::::::::::::
#### Extension: `raw_tex` ####
diff --git a/src/Text/Pandoc/Readers/Markdown.hs b/src/Text/Pandoc/Readers/Markdown.hs
index 221c834e8..a27e05fed 100644
--- a/src/Text/Pandoc/Readers/Markdown.hs
+++ b/src/Text/Pandoc/Readers/Markdown.hs
@@ -1027,6 +1027,11 @@ para = try $ do
Just "div" -> () <$
lookAhead (htmlTag (~== TagClose "div"))
_ -> mzero
+ <|> do guardEnabled Ext_fenced_divs
+ divLevel <- stateFencedDivLevel <$> getState
+ if divLevel > 0
+ then lookAhead divFenceEnd
+ else mzero
return $ do
result' <- result
case B.toList result' of
@@ -1689,7 +1694,7 @@ endline = try $ do
notFollowedBy (() <$ (lookAhead (char '`') >> codeBlockFenced))
guardDisabled Ext_fenced_divs <|>
do divLevel <- stateFencedDivLevel <$> getState
- guard (divLevel < 1) <|> notFollowedBy fenceEnd
+ guard (divLevel < 1) <|> notFollowedBy divFenceEnd
notFollowedByHtmlCloser
(eof >> return mempty)
<|> (guardEnabled Ext_hard_line_breaks >> return (return B.linebreak))
@@ -1946,12 +1951,12 @@ divFenced = try $ do
skipMany (char ':')
blankline
updateState $ \st -> st{ stateFencedDivLevel = stateFencedDivLevel st + 1 }
- bs <- mconcat <$> manyTill block fenceEnd
+ bs <- mconcat <$> manyTill block divFenceEnd
updateState $ \st -> st{ stateFencedDivLevel = stateFencedDivLevel st - 1 }
return $ B.divWith attribs <$> bs
-fenceEnd :: PandocMonad m => MarkdownParser m ()
-fenceEnd = try $ do
+divFenceEnd :: PandocMonad m => MarkdownParser m ()
+divFenceEnd = try $ do
nonindentSpaces
string ":::"
skipMany (char ':')
diff --git a/test/command/168.md b/test/command/168.md
index 0d6183a78..43c3b865a 100644
--- a/test/command/168.md
+++ b/test/command/168.md
@@ -17,7 +17,7 @@ nested div
[[Plain [Str "list"]]
,[Plain [Str "another"]]]
,Div ("myid",["class"],[("key","val")])
- [Plain [Str "nested",Space,Str "div"]]]]
+ [Para [Str "nested",Space,Str "div"]]]]
```
```
@@ -28,3 +28,16 @@ bar
^D
[Para [Str "foo",SoftBreak,Str ":::",SoftBreak,Str "bar"]]
```
+
+```
+% pandoc -t native
+::::: Warning
+Here is a paragraph.
+
+And another.
+:::::
+^D
+[Div ("",["Warning"],[])
+ [Para [Str "Here",Space,Str "is",Space,Str "a",Space,Str "paragraph."]
+ ,Para [Str "And",Space,Str "another."]]]
+```