From 42c139d302a682339faaab011ffa8ebca2d93a2a Mon Sep 17 00:00:00 2001 From: Ophir Lifshitz Date: Thu, 23 Jul 2015 02:29:37 -0400 Subject: Markdown Reader: Skip spaces in headers --- src/Text/Pandoc/Readers/Markdown.hs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Text/Pandoc/Readers/Markdown.hs b/src/Text/Pandoc/Readers/Markdown.hs index b8f5dab60..ab33023bb 100644 --- a/src/Text/Pandoc/Readers/Markdown.hs +++ b/src/Text/Pandoc/Readers/Markdown.hs @@ -521,6 +521,7 @@ atxClosing :: MarkdownParser Attr atxClosing = try $ do attr' <- option nullAttr (guardEnabled Ext_mmd_header_identifiers >> mmdHeaderIdentifier) + skipSpaces skipMany (char '#') skipSpaces attr <- option attr' @@ -547,6 +548,7 @@ setextHeader = try $ do -- This lookahead prevents us from wasting time parsing Inlines -- unless necessary -- it gives a significant performance boost. lookAhead $ anyLine >> many1 (oneOf setextHChars) >> blankline + skipSpaces (text, raw) <- withRaw $ trimInlinesF . mconcat <$> many1 (notFollowedBy setextHeaderEnd >> inline) attr <- setextHeaderEnd -- cgit v1.2.3 From 0c7d0757d6d69403fdcf5bc0fba2e6c0dfbf8b6e Mon Sep 17 00:00:00 2001 From: Ophir Lifshitz Date: Thu, 23 Jul 2015 02:31:03 -0400 Subject: Markdown Reader: Add implicit header ref tests for headers with spaces --- tests/Tests/Readers/Markdown.hs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/Tests/Readers/Markdown.hs b/tests/Tests/Readers/Markdown.hs index a5425ffb3..78891ab54 100644 --- a/tests/Tests/Readers/Markdown.hs +++ b/tests/Tests/Readers/Markdown.hs @@ -225,6 +225,26 @@ tests = [ testGroup "inline code" "# [hi]\n" =?> headerWith ("hi",[],[]) 1 "[hi]" ] + , testGroup "Implicit header references" + [ "ATX header without trailing #s" =: + "# Header\n[header]\n\n[header ]\n\n[ header]" =?> + headerWith ("header",[],[]) 1 "Header" + <> para (link "#header" "" (text "header")) + <> para (text "[header" <> space <> text "]") + <> para (text "[" <> space <> text "header]") + , "ATX header with trailing #s" =: + "# Foo bar #\n[foo bar]\n\n[foo bar ]\n\n[ foo bar]" =?> + headerWith ("foo-bar",[],[]) 1 "Foo bar" + <> para (link "#foo-bar" "" (text "foo bar")) + <> para (text "[foo bar" <> space <> text "]") + <> para (text "[" <> space <> text "foo bar]") + , "setext header" =: + " Header \n=\n\n[header]\n\n[header ]\n\n[ header]" =?> + headerWith ("header",[],[]) 1 "Header" + <> para (link "#header" "" (text "header")) + <> para (text "[header" <> space <> text "]") + <> para (text "[" <> space <> text "header]") + ] , testGroup "smart punctuation" [ test markdownSmart "quote before ellipses" ("'...hi'" -- cgit v1.2.3 From 53cb926232e23af32866255d4ecad518f8f972f5 Mon Sep 17 00:00:00 2001 From: Ophir Lifshitz Date: Thu, 23 Jul 2015 02:31:24 -0400 Subject: Markdown Reader: Add basic tests for each header style --- tests/Tests/Readers/Markdown.hs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/Tests/Readers/Markdown.hs b/tests/Tests/Readers/Markdown.hs index 78891ab54..d5ad07a18 100644 --- a/tests/Tests/Readers/Markdown.hs +++ b/tests/Tests/Readers/Markdown.hs @@ -224,6 +224,16 @@ tests = [ testGroup "inline code" , "bracketed text (#2062)" =: "# [hi]\n" =?> headerWith ("hi",[],[]) 1 "[hi]" + , "ATX header without trailing #s" =: + "# Foo bar\n\n" =?> + headerWith ("foo-bar",[],[]) 1 "Foo bar" + , "ATX header without trailing #s" =: + "# Foo bar with # #" =?> + headerWith ("foo-bar-with",[],[]) 1 "Foo bar with #" + , "setext header" =: + "Foo bar\n=\n\n Foo bar 2 \n=" =?> + headerWith ("foo-bar",[],[]) 1 "Foo bar" + <> headerWith ("foo-bar-2",[],[]) 1 "Foo bar 2" ] , testGroup "Implicit header references" [ "ATX header without trailing #s" =: -- cgit v1.2.3