Skip to content

Commit

Permalink
Markdown definition lists: don't require indent for first line.
Browse files Browse the repository at this point in the history
Previously the body of the definition (after the `:` or `~` marker)
needed to be in column 4.  This commit relaxes that requirement,
to better match the behavior of PHP Markdown Extra.  So, now
this is a valid definition list:

    foo
    : bar

This patch also helps resolve a potentially ambiguity with table
captions:

    foo

      : bar

      -----
      table
      -----

Is "bar" a definition, or the caption for the table?  We'll count
it as a caption for the table.

Closes #2087.
  • Loading branch information
jgm committed Apr 18, 2015
1 parent 10e28ef commit d3544dc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/Text/Pandoc/Readers/Markdown.hs
Original file line number Diff line number Diff line change
Expand Up @@ -880,7 +880,7 @@ defListMarker = do
tabStop <- getOption readerTabStop
let remaining = tabStop - (length sps + 1)
if remaining > 0
then count remaining (char ' ') <|> string "\t"
then try (count remaining (char ' ')) <|> string "\t" <|> many1 spaceChar
else mzero
return ()

Expand Down Expand Up @@ -916,7 +916,9 @@ defRawBlock compact = try $ do

definitionList :: MarkdownParser Blocks
definitionList = try $ do
lookAhead (anyLine >> optional blankline >> defListMarker)
lookAhead (anyLine >> optional (blankline >> notFollowedBy table) >>
-- don't capture table caption as def list!
defListMarker)
compactDefinitionList <|> normalDefinitionList

compactDefinitionList :: MarkdownParser Blocks
Expand Down
3 changes: 3 additions & 0 deletions tests/Tests/Readers/Markdown.hs
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,9 @@ tests = [ testGroup "inline code"
definitionList [ (text "foo1", [para (text "bar") <>
para (text "baz")])
]
, "first line not indented" =:
"foo\n: bar\n" =?>
definitionList [ (text "foo", [plain (text "bar")]) ]
]
, testGroup "+compact_definition_lists"
[ test markdownCDL "basic compact list" $
Expand Down

0 comments on commit d3544dc

Please sign in to comment.