git.iko.soy/typeable/pandoc
on master help sign in
Fenced divs: ensure that paragraph at end doesn't become Plain.
513b16aJohn MacFarlane
MANUAL.txt+8−6
@@ -3080,10 +3080,12 @@ starts with a fence containing at least three consecutive
3080colons plus some attributes. The attributes may optionally
3080colons plus some attributes. The attributes may optionally
3081be followed by another string of consecutive colons.
3081be followed by another string of consecutive colons.
3082The attribute syntax is exactly as in fenced code blocks (see
3082The attribute syntax is exactly as in fenced code blocks (see
3083−[Extension-fenced_code_attributes], above). The Div ends with
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
3084−another line containing a string of at least three consecutive
3086+name. The Div ends with another line containing a string of at
3085−colons. The fenced Div should be separated by blank lines from
3087+least three consecutive colons. The fenced Div should be
3086−preceding and following blocks.
3088+separated by blank lines from preceding and following blocks.
3087
3089
3088Example:
3090Example:
3089
3091
@@ -3096,13 +3098,13 @@ Example:
3096Fenced divs can be nested. Opening fences are distinguished
3098Fenced divs can be nested. Opening fences are distinguished
3097because they *must* have attributes:
3099because they *must* have attributes:
3098
3100
3099− ::: Warning
3101+ ::: Warning ::::::
3100 This is a warning.
3102 This is a warning.
3101
3103
3102 ::: Danger
3104 ::: Danger
3103 This is a warning within a warning.
3105 This is a warning within a warning.
3104 :::
3106 :::
3105− :::
3107+ ::::::::::::::::::
3106
3108
3107#### Extension: `raw_tex` ####
3109#### Extension: `raw_tex` ####
3108
3110
src/Text/Pandoc/Readers/Markdown.hs+9−4
@@ -1027,6 +1027,11 @@ para = try $ do
1027 Just "div" -> () <$
1027 Just "div" -> () <$
1028 lookAhead (htmlTag (~== TagClose "div"))
1028 lookAhead (htmlTag (~== TagClose "div"))
1029 _ -> mzero
1029 _ -> mzero
1030+ <|> do guardEnabled Ext_fenced_divs
1031+ divLevel <- stateFencedDivLevel <$> getState
1032+ if divLevel > 0
1033+ then lookAhead divFenceEnd
1034+ else mzero
1030 return $ do
1035 return $ do
1031 result' <- result
1036 result' <- result
1032 case B.toList result' of
1037 case B.toList result' of
@@ -1689,7 +1694,7 @@ endline = try $ do
1689 notFollowedBy (() <$ (lookAhead (char '`') >> codeBlockFenced))
1694 notFollowedBy (() <$ (lookAhead (char '`') >> codeBlockFenced))
1690 guardDisabled Ext_fenced_divs <|>
1695 guardDisabled Ext_fenced_divs <|>
1691 do divLevel <- stateFencedDivLevel <$> getState
1696 do divLevel <- stateFencedDivLevel <$> getState
1692− guard (divLevel < 1) <|> notFollowedBy fenceEnd
1697+ guard (divLevel < 1) <|> notFollowedBy divFenceEnd
1693 notFollowedByHtmlCloser
1698 notFollowedByHtmlCloser
1694 (eof >> return mempty)
1699 (eof >> return mempty)
1695 <|> (guardEnabled Ext_hard_line_breaks >> return (return B.linebreak))
1700 <|> (guardEnabled Ext_hard_line_breaks >> return (return B.linebreak))
@@ -1946,12 +1951,12 @@ divFenced = try $ do
1946 skipMany (char ':')
1951 skipMany (char ':')
1947 blankline
1952 blankline
1948 updateState $ \st -> st{ stateFencedDivLevel = stateFencedDivLevel st + 1 }
1953 updateState $ \st -> st{ stateFencedDivLevel = stateFencedDivLevel st + 1 }
1949− bs <- mconcat <$> manyTill block fenceEnd
1954+ bs <- mconcat <$> manyTill block divFenceEnd
1950 updateState $ \st -> st{ stateFencedDivLevel = stateFencedDivLevel st - 1 }
1955 updateState $ \st -> st{ stateFencedDivLevel = stateFencedDivLevel st - 1 }
1951 return $ B.divWith attribs <$> bs
1956 return $ B.divWith attribs <$> bs
1952
1957
1953−fenceEnd :: PandocMonad m => MarkdownParser m ()
1958+divFenceEnd :: PandocMonad m => MarkdownParser m ()
1954−fenceEnd = try $ do
1959+divFenceEnd = try $ do
1955 nonindentSpaces
1960 nonindentSpaces
1956 string ":::"
1961 string ":::"
1957 skipMany (char ':')
1962 skipMany (char ':')
test/command/168.md+14−1
@@ -17,7 +17,7 @@ nested div
17 [[Plain [Str "list"]]
17 [[Plain [Str "list"]]
18 ,[Plain [Str "another"]]]
18 ,[Plain [Str "another"]]]
19 ,Div ("myid",["class"],[("key","val")])
19 ,Div ("myid",["class"],[("key","val")])
20− [Plain [Str "nested",Space,Str "div"]]]]
20+ [Para [Str "nested",Space,Str "div"]]]]
21```
21```
22
22
23```
23```
@@ -28,3 +28,16 @@ bar
28^D
28^D
29[Para [Str "foo",SoftBreak,Str ":::",SoftBreak,Str "bar"]]
29[Para [Str "foo",SoftBreak,Str ":::",SoftBreak,Str "bar"]]
30```
30```
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+```