Org reader: end footnotes after two blank lines

Footnotes can not only be terminated by the start of a new footnote or a
header, but also by two consecutive blank lines.
This commit is contained in:
Albert Krewinkel 2017-10-08 14:17:26 +02:00
parent 89f1362660
commit f176ad6f21
No known key found for this signature in database
GPG key ID: 388DC0B21F631124
2 changed files with 80 additions and 64 deletions

View file

@ -724,13 +724,14 @@ latexEnd envName = try $
noteBlock :: PandocMonad m => OrgParser m (F Blocks)
noteBlock = try $ do
ref <- noteMarker <* skipSpaces <* updateLastPreCharPos
content <- mconcat <$> blocksTillHeaderOrNote
content <- mconcat <$> many1Till block endOfFootnote
addToNotesTable (ref, content)
return mempty
where
blocksTillHeaderOrNote =
many1Till block (eof <|> () <$ lookAhead noteMarker
<|> () <$ lookAhead headerStart)
endOfFootnote = eof
<|> () <$ lookAhead noteMarker
<|> () <$ lookAhead headerStart
<|> () <$ lookAhead (try $ blankline *> blankline)
-- Paragraphs or Plain text
paraOrPlain :: PandocMonad m => OrgParser m (F Blocks)

View file

@ -1086,67 +1086,82 @@ tests =
para (image "guess.jpg" "fig:" "")
]
, "Footnote" =:
T.unlines [ "A footnote[1]"
, ""
, "[1] First paragraph"
, ""
, "second paragraph"
] =?>
para (mconcat
[ "A", space, "footnote"
, note $ mconcat [ para ("First" <> space <> "paragraph")
, para ("second" <> space <> "paragraph")
]
])
, "Two footnotes" =:
T.unlines [ "Footnotes[fn:1][fn:2]"
, ""
, "[fn:1] First note."
, ""
, "[fn:2] Second note."
] =?>
para (mconcat
[ "Footnotes"
, note $ para ("First" <> space <> "note.")
, note $ para ("Second" <> space <> "note.")
])
, "Emphasized text before footnote" =:
T.unlines [ "/text/[fn:1]"
, ""
, "[fn:1] unicorn"
] =?>
para (mconcat
[ emph "text"
, note . para $ "unicorn"
])
, "Footnote that starts with emphasized text" =:
T.unlines [ "text[fn:1]"
, ""
, "[fn:1] /emphasized/"
] =?>
para (mconcat
[ "text"
, note . para $ emph "emphasized"
])
, "Footnote followed by header" =:
T.unlines [ "Another note[fn:yay]"
, ""
, "[fn:yay] This is great!"
, ""
, "** Headline"
] =?>
mconcat
[ para (mconcat
[ "Another", space, "note"
, note $ para ("This" <> space <> "is" <> space <> "great!")
, testGroup "Footnotes"
[ "Footnote" =:
T.unlines [ "A footnote[1]"
, ""
, "[1] First paragraph"
, ""
, "second paragraph"
] =?>
para (mconcat
[ "A", space, "footnote"
, note $ mconcat [ para ("First" <> space <> "paragraph")
, para ("second" <> space <> "paragraph")
]
])
, headerWith ("headline", [], []) 2 "Headline"
]
, "Two footnotes" =:
T.unlines [ "Footnotes[fn:1][fn:2]"
, ""
, "[fn:1] First note."
, ""
, "[fn:2] Second note."
] =?>
para (mconcat
[ "Footnotes"
, note $ para ("First" <> space <> "note.")
, note $ para ("Second" <> space <> "note.")
])
, "Emphasized text before footnote" =:
T.unlines [ "/text/[fn:1]"
, ""
, "[fn:1] unicorn"
] =?>
para (mconcat
[ emph "text"
, note . para $ "unicorn"
])
, "Footnote that starts with emphasized text" =:
T.unlines [ "text[fn:1]"
, ""
, "[fn:1] /emphasized/"
] =?>
para (mconcat
[ "text"
, note . para $ emph "emphasized"
])
, "Footnote followed by header" =:
T.unlines [ "Another note[fn:yay]"
, ""
, "[fn:yay] This is great!"
, ""
, "** Headline"
] =?>
mconcat
[ para (mconcat
[ "Another", space, "note"
, note $ para ("This" <> space <> "is" <> space <> "great!")
])
, headerWith ("headline", [], []) 2 "Headline"
]
, "Footnote followed by two blank lines" =:
T.unlines [ "footnote[fn:blanklines]"
, ""
, "[fn:blanklines] followed by blank lines"
, ""
, ""
, "next"
] =?>
mconcat
[ para ("footnote" <> note (para "followed by blank lines"))
, para "next"
]
]
]
, testGroup "Lists" $