aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2015-07-23 14:46:38 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2015-07-23 14:46:38 -0700
commit5db478733034433e7875853a126b43a7f5f6de84 (patch)
tree12e2fe9e5f6a3778d0c81fc855905701915bba05
parent66a72b8eec08d7bffb431cc86795ec7cd63399fe (diff)
parent53cb926232e23af32866255d4ecad518f8f972f5 (diff)
downloadpandoc-5db478733034433e7875853a126b43a7f5f6de84.tar.gz
Merge pull request #2323 from hftf/implicit-header-refs
Fix implicit header refs for headers with extra spaces
-rw-r--r--src/Text/Pandoc/Readers/Markdown.hs2
-rw-r--r--tests/Tests/Readers/Markdown.hs30
2 files changed, 32 insertions, 0 deletions
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
diff --git a/tests/Tests/Readers/Markdown.hs b/tests/Tests/Readers/Markdown.hs
index a5425ffb3..d5ad07a18 100644
--- a/tests/Tests/Readers/Markdown.hs
+++ b/tests/Tests/Readers/Markdown.hs
@@ -224,6 +224,36 @@ 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" =:
+ "# 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"