git.iko.soy/typeable/pandoc
on master help sign in
Org reader: Fix parsing of footnotes

Footnotes can consist of multiple blocks and end only at a header or at the beginning of another footnote. This fixes the previous behavior, which restricted notes to a single paragraph.

commit8e91d362a392d1ee90a497f39cfcf90fee8d8da0 authorAlbert Krewinkel <tarleb@moltkeplatz.de> dateSat 19 Apr 2014, 13:15 (13 years ago) parenta694160
2 files changed+48−2
src/Text/Pandoc/Readers/Org.hs+6−2 tests/Tests/Readers/Org.hs+42
src/Text/Pandoc/Readers/Org.hs+6−2
@@ -639,10 +639,14 @@ latexEnvName = try $ do
639639--
640640noteBlock :: OrgParser (F Blocks)
641641noteBlock = try $ do
642− ref <- noteMarker
643− content <- skipSpaces *> paraOrPlain
642+ ref <- noteMarker <* skipSpaces
643+ content <- mconcat <$> blocksTillHeaderOrNote
644644 addToNotesTable (ref, content)
645645 return mempty
646+ where
647+ blocksTillHeaderOrNote =
648+ many1Till block (eof <|> () <$ lookAhead noteMarker
649+ <|> () <$ lookAhead headerStart)
646650
647651-- Paragraphs or Plain text
648652paraOrPlain :: OrgParser (F Blocks)
tests/Tests/Readers/Org.hs+42
@@ -383,6 +383,48 @@ tests =
383383 ] =?>
384384 para (image "the-red-queen.jpg" "fig:redqueen"
385385 "Used as a metapher in evolutionary biology.")
386+
387+ , "Footnote" =:
388+ unlines [ "A footnote[1]"
389+ , ""
390+ , "[1] First paragraph"
391+ , ""
392+ , "second paragraph"
393+ ] =?>
394+ para (mconcat
395+ [ "A", space, "footnote"
396+ , note $ mconcat [ para ("First" <> space <> "paragraph")
397+ , para ("second" <> space <> "paragraph")
398+ ]
399+ ])
400+
401+ , "Two footnotes" =:
402+ unlines [ "Footnotes[fn:1][fn:2]"
403+ , ""
404+ , "[fn:1] First note."
405+ , ""
406+ , "[fn:2] Second note."
407+ ] =?>
408+ para (mconcat
409+ [ "Footnotes"
410+ , note $ para ("First" <> space <> "note.")
411+ , note $ para ("Second" <> space <> "note.")
412+ ])
413+
414+ , "Footnote followed by header" =:
415+ unlines [ "Another note[fn:yay]"
416+ , ""
417+ , "[fn:yay] This is great!"
418+ , ""
419+ , "** Headline"
420+ ] =?>
421+ mconcat
422+ [ para (mconcat
423+ [ "Another", space, "note"
424+ , note $ para ("This" <> space <> "is" <> space <> "great!")
425+ ])
426+ , header 2 "Headline"
427+ ]
386428 ]
387429
388430 , testGroup "Lists" $