Skip to content

Commit

Permalink
Markdown reader: better handling of paragraph in div.
Browse files Browse the repository at this point in the history
Previously text that ended a div would be parsed as Plain
unless there was a blank line before the closing div tag.

Test case:

    <div class="first">
    This is a paragraph.

    This is another paragraph.
    </div>

Closes #1591.
  • Loading branch information
jgm committed Aug 31, 2014
1 parent 6cf9ab7 commit 598d3ee
Show file tree
Hide file tree
Showing 14 changed files with 32 additions and 13 deletions.
7 changes: 7 additions & 0 deletions src/Text/Pandoc/Readers/Markdown.hs
Expand Up @@ -927,6 +927,12 @@ para = try $ do
<|> (guardDisabled Ext_blank_before_header >> () <$ lookAhead header)
<|> (guardEnabled Ext_lists_without_preceding_blankline >>
() <$ lookAhead listStart)
<|> do guardEnabled Ext_native_divs
inHtmlBlock <- stateInHtmlBlock <$> getState
case inHtmlBlock of
Just "div" -> () <$
lookAhead (htmlTag (~== TagClose "div"))
_ -> mzero
return $ do
result' <- result
case B.toList result' of
Expand Down Expand Up @@ -1611,6 +1617,7 @@ endline = try $ do
guardEnabled Ext_blank_before_header <|> notFollowedBy (char '#') -- atx header
guardDisabled Ext_backtick_code_blocks <|>
notFollowedBy (() <$ (lookAhead (char '`') >> codeBlockFenced))
notFollowedByHtmlCloser
(eof >> return mempty)
<|> (guardEnabled Ext_hard_line_breaks >> return (return B.linebreak))
<|> (guardEnabled Ext_ignore_line_breaks >> return mempty)
Expand Down
4 changes: 2 additions & 2 deletions tests/Tests/Readers/Markdown.hs
Expand Up @@ -266,10 +266,10 @@ tests = [ testGroup "inline code"
, testGroup "lists"
[ "issue #1154" =:
" - <div>\n first div breaks\n </div>\n\n <button>if this button exists</button>\n\n <div>\n with this div too.\n </div>\n"
=?> bulletList [divWith nullAttr (plain $ text "first div breaks") <>
=?> bulletList [divWith nullAttr (para $ text "first div breaks") <>
rawBlock "html" "<button>" <>
plain (text "if this button exists") <>
rawBlock "html" "</button>" <>
divWith nullAttr (plain $ text "with this div too.")]
divWith nullAttr (para $ text "with this div too.")]
]
]
4 changes: 2 additions & 2 deletions tests/testsuite.native
Expand Up @@ -230,7 +230,7 @@ Pandoc (Meta {unMeta = fromList [("author",MetaList [MetaInlines [Str "John",Spa
,Para [Str "Simple",Space,Str "block",Space,Str "on",Space,Str "one",Space,Str "line:"]
,Div ("",[],[]) [Plain [Str "foo"]]
,Para [Str "And",Space,Str "nested",Space,Str "without",Space,Str "indentation:"]
,Div ("",[],[]) [Div ("",[],[]) [Div ("",[],[]) [Plain [Str "foo"]]],Div ("",[],[]) [Plain [Str "bar"]]]
,Div ("",[],[]) [Div ("",[],[]) [Div ("",[],[]) [Para [Str "foo"]]],Div ("",[],[]) [Plain [Str "bar"]]]
,Para [Str "Interpreted",Space,Str "markdown",Space,Str "in",Space,Str "a",Space,Str "table:"]
,RawBlock (Format "html") "<table>"
,RawBlock (Format "html") "<tr>"
Expand All @@ -244,7 +244,7 @@ Pandoc (Meta {unMeta = fromList [("author",MetaList [MetaInlines [Str "John",Spa
,RawBlock (Format "html") "</table>"
,RawBlock (Format "html") "<script type=\"text/javascript\">document.write('This *should not* be interpreted as markdown');</script>"
,Para [Str "Here\8217s",Space,Str "a",Space,Str "simple",Space,Str "block:"]
,Div ("",[],[]) [Plain [Str "foo"]]
,Div ("",[],[]) [Para [Str "foo"]]
,Para [Str "This",Space,Str "should",Space,Str "be",Space,Str "a",Space,Str "code",Space,Str "block,",Space,Str "though:"]
,CodeBlock ("",[],[]) "<div>\n foo\n</div>"
,Para [Str "As",Space,Str "should",Space,Str "this:"]
Expand Down
2 changes: 2 additions & 0 deletions tests/writer.asciidoc
Expand Up @@ -378,6 +378,7 @@ foo
And nested without indentation:
foo
bar
Interpreted markdown in a table:
Expand All @@ -386,6 +387,7 @@ And this is *strong*
Here’s a simple block:
foo
This should be a code block, though:
-------
Expand Down
2 changes: 2 additions & 0 deletions tests/writer.context
Expand Up @@ -548,6 +548,7 @@ foo
And nested without indentation:

foo

bar
Interpreted markdown in a table:

Expand All @@ -556,6 +557,7 @@ And this is {\bf strong}
Here's a simple block:

foo

This should be a code block, though:

\starttyping
Expand Down
2 changes: 2 additions & 0 deletions tests/writer.dokuwiki
Expand Up @@ -298,6 +298,7 @@ And nested without indentation:
foo



bar


Expand All @@ -324,6 +325,7 @@ Here’s a simple block:

foo


This should be a code block, though:

<code><div>
Expand Down
2 changes: 1 addition & 1 deletion tests/writer.fb2

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions tests/writer.html
Expand Up @@ -328,7 +328,7 @@ <h1 id="html-blocks">HTML Blocks</h1>
<div>
<div>
<div>
foo
<p>foo</p>
</div>
</div>
<div>
Expand All @@ -349,7 +349,7 @@ <h1 id="html-blocks">HTML Blocks</h1>
<script type="text/javascript">document.write('This *should not* be interpreted as markdown');</script>
<p>Here’s a simple block:</p>
<div>
foo
<p>foo</p>
</div>
<p>This should be a code block, though:</p>
<pre><code>&lt;div&gt;
Expand Down
4 changes: 2 additions & 2 deletions tests/writer.icml
Expand Up @@ -1374,7 +1374,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{</Content>
<Content>And nested without indentation:</Content>
</CharacterStyleRange><Br />
</ParagraphStyleRange>
<ParagraphStyleRange AppliedParagraphStyle="">
<ParagraphStyleRange AppliedParagraphStyle="ParagraphStyle/Paragraph">
<CharacterStyleRange AppliedCharacterStyle="$ID/NormalCharacterStyle">
<Content>foo</Content>
</CharacterStyleRange><Br />
Expand Down Expand Up @@ -1455,7 +1455,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{</Content>
<Content>Here’s a simple block:</Content>
</CharacterStyleRange><Br />
</ParagraphStyleRange>
<ParagraphStyleRange AppliedParagraphStyle="">
<ParagraphStyleRange AppliedParagraphStyle="ParagraphStyle/Paragraph">
<CharacterStyleRange AppliedCharacterStyle="$ID/NormalCharacterStyle">
<Content>foo</Content>
</CharacterStyleRange><Br />
Expand Down
2 changes: 2 additions & 0 deletions tests/writer.man
Expand Up @@ -450,6 +450,7 @@ Simple block on one line:
foo
.PP
And nested without indentation:
.PP
foo
bar
.PP
Expand All @@ -458,6 +459,7 @@ This is \f[I]emphasized\f[]
And this is \f[B]strong\f[]
.PP
Here's a simple block:
.PP
foo
.PP
This should be a code block, though:
Expand Down
2 changes: 2 additions & 0 deletions tests/writer.mediawiki
Expand Up @@ -325,6 +325,7 @@ And nested without indentation:

foo


</div>

</div>
Expand Down Expand Up @@ -354,6 +355,7 @@ Here’s a simple block:

foo


</div>
This should be a code block, though:

Expand Down
4 changes: 2 additions & 2 deletions tests/writer.native
Expand Up @@ -230,7 +230,7 @@ Pandoc (Meta {unMeta = fromList [("author",MetaList [MetaInlines [Str "John",Spa
,Para [Str "Simple",Space,Str "block",Space,Str "on",Space,Str "one",Space,Str "line:"]
,Div ("",[],[]) [Plain [Str "foo"]]
,Para [Str "And",Space,Str "nested",Space,Str "without",Space,Str "indentation:"]
,Div ("",[],[]) [Div ("",[],[]) [Div ("",[],[]) [Plain [Str "foo"]]],Div ("",[],[]) [Plain [Str "bar"]]]
,Div ("",[],[]) [Div ("",[],[]) [Div ("",[],[]) [Para [Str "foo"]]],Div ("",[],[]) [Plain [Str "bar"]]]
,Para [Str "Interpreted",Space,Str "markdown",Space,Str "in",Space,Str "a",Space,Str "table:"]
,RawBlock (Format "html") "<table>"
,RawBlock (Format "html") "<tr>"
Expand All @@ -244,7 +244,7 @@ Pandoc (Meta {unMeta = fromList [("author",MetaList [MetaInlines [Str "John",Spa
,RawBlock (Format "html") "</table>"
,RawBlock (Format "html") "<script type=\"text/javascript\">document.write('This *should not* be interpreted as markdown');</script>"
,Para [Str "Here\8217s",Space,Str "a",Space,Str "simple",Space,Str "block:"]
,Div ("",[],[]) [Plain [Str "foo"]]
,Div ("",[],[]) [Para [Str "foo"]]
,Para [Str "This",Space,Str "should",Space,Str "be",Space,Str "a",Space,Str "code",Space,Str "block,",Space,Str "though:"]
,CodeBlock ("",[],[]) "<div>\n foo\n</div>"
,Para [Str "As",Space,Str "should",Space,Str "this:"]
Expand Down
4 changes: 2 additions & 2 deletions tests/writer.rtf
Expand Up @@ -208,13 +208,13 @@ These should not be escaped: \\$ \\\\ \\> \\[ \\\{\par}
{\pard \ql \f0 \sa180 \li0 \fi0 Simple block on one line:\par}
{\pard \ql \f0 \sa0 \li0 \fi0 foo\par}
{\pard \ql \f0 \sa180 \li0 \fi0 And nested without indentation:\par}
{\pard \ql \f0 \sa0 \li0 \fi0 foo\par}
{\pard \ql \f0 \sa180 \li0 \fi0 foo\par}
{\pard \ql \f0 \sa0 \li0 \fi0 bar\par}
{\pard \ql \f0 \sa180 \li0 \fi0 Interpreted markdown in a table:\par}
{\pard \ql \f0 \sa0 \li0 \fi0 This is {\i emphasized}\par}
{\pard \ql \f0 \sa0 \li0 \fi0 And this is {\b strong}\par}
{\pard \ql \f0 \sa180 \li0 \fi0 Here\u8217's a simple block:\par}
{\pard \ql \f0 \sa0 \li0 \fi0 foo\par}
{\pard \ql \f0 \sa180 \li0 \fi0 foo\par}
{\pard \ql \f0 \sa180 \li0 \fi0 This should be a code block, though:\par}
{\pard \ql \f0 \sa180 \li0 \fi0 \f1 <div>\line
foo\line
Expand Down
2 changes: 2 additions & 0 deletions tests/writer.textile
Expand Up @@ -367,6 +367,7 @@ And nested without indentation:

foo


</div>


Expand Down Expand Up @@ -400,6 +401,7 @@ Here's a simple block:

foo


</div>

This should be a code block, though:
Expand Down

0 comments on commit 598d3ee

Please sign in to comment.