git.iko.soy/typeable/pandoc
on master help sign in
Fenced divs: ensure that paragraph at end doesn't become Plain.

Added test case.

commit513b16a71b30a04cc91c056a22e2761f7ea554d2 authorJohn MacFarlane <jgm@berkeley.edu> dateTue 24 Oct 2017, 09:53 (9 years ago) parent312db3b
3 files changed+31−11
MANUAL.txt+8−6 src/Text/Pandoc/Readers/Markdown.hs+9−4 test/command/168.md+14−1
MANUAL.txt+8−6
@@ -3080,10 +3080,12 @@ starts with a fence containing at least three consecutive
30803080colons plus some attributes. The attributes may optionally
30813081be followed by another string of consecutive colons.
30823082The attribute syntax is exactly as in fenced code blocks (see
3083−[Extension-fenced_code_attributes], above). The Div ends with
3084−another line containing a string of at least three consecutive
3085−colons. The fenced Div should be separated by blank lines from
3086−preceding and following blocks.
3083+[Extension-fenced_code_attributes], above). As with fenced
3084+code blocks, one can use either attributes in curly braces
3085+or a single unbraced word, which will be treated as a class
3086+name. The Div ends with another line containing a string of at
3087+least three consecutive colons. The fenced Div should be
3088+separated by blank lines from preceding and following blocks.
30873089
30883090Example:
30893091
@@ -3096,13 +3098,13 @@ Example:
30963098Fenced divs can be nested. Opening fences are distinguished
30973099because they *must* have attributes:
30983100
3099− ::: Warning
3101+ ::: Warning ::::::
31003102 This is a warning.
31013103
31023104 ::: Danger
31033105 This is a warning within a warning.
31043106 :::
3105− :::
3107+ ::::::::::::::::::
31063108
31073109#### Extension: `raw_tex` ####
31083110
src/Text/Pandoc/Readers/Markdown.hs+9−4
@@ -1027,6 +1027,11 @@ para = try $ do
10271027 Just "div" -> () <$
10281028 lookAhead (htmlTag (~== TagClose "div"))
10291029 _ -> mzero
1030+ <|> do guardEnabled Ext_fenced_divs
1031+ divLevel <- stateFencedDivLevel <$> getState
1032+ if divLevel > 0
1033+ then lookAhead divFenceEnd
1034+ else mzero
10301035 return $ do
10311036 result' <- result
10321037 case B.toList result' of
@@ -1689,7 +1694,7 @@ endline = try $ do
16891694 notFollowedBy (() <$ (lookAhead (char '`') >> codeBlockFenced))
16901695 guardDisabled Ext_fenced_divs <|>
16911696 do divLevel <- stateFencedDivLevel <$> getState
1692− guard (divLevel < 1) <|> notFollowedBy fenceEnd
1697+ guard (divLevel < 1) <|> notFollowedBy divFenceEnd
16931698 notFollowedByHtmlCloser
16941699 (eof >> return mempty)
16951700 <|> (guardEnabled Ext_hard_line_breaks >> return (return B.linebreak))
@@ -1946,12 +1951,12 @@ divFenced = try $ do
19461951 skipMany (char ':')
19471952 blankline
19481953 updateState $ \st -> st{ stateFencedDivLevel = stateFencedDivLevel st + 1 }
1949− bs <- mconcat <$> manyTill block fenceEnd
1954+ bs <- mconcat <$> manyTill block divFenceEnd
19501955 updateState $ \st -> st{ stateFencedDivLevel = stateFencedDivLevel st - 1 }
19511956 return $ B.divWith attribs <$> bs
19521957
1953−fenceEnd :: PandocMonad m => MarkdownParser m ()
1954−fenceEnd = try $ do
1958+divFenceEnd :: PandocMonad m => MarkdownParser m ()
1959+divFenceEnd = try $ do
19551960 nonindentSpaces
19561961 string ":::"
19571962 skipMany (char ':')
test/command/168.md+14−1
@@ -17,7 +17,7 @@ nested div
1717 [[Plain [Str "list"]]
1818 ,[Plain [Str "another"]]]
1919 ,Div ("myid",["class"],[("key","val")])
20− [Plain [Str "nested",Space,Str "div"]]]]
20+ [Para [Str "nested",Space,Str "div"]]]]
2121```
2222
2323```
@@ -28,3 +28,16 @@ bar
2828^D
2929[Para [Str "foo",SoftBreak,Str ":::",SoftBreak,Str "bar"]]
3030```
31+
32+```
33+% pandoc -t native
34+::::: Warning
35+Here is a paragraph.
36+
37+And another.
38+:::::
39+^D
40+[Div ("",["Warning"],[])
41+ [Para [Str "Here",Space,Str "is",Space,Str "a",Space,Str "paragraph."]
42+ ,Para [Str "And",Space,Str "another."]]]
43+```