Muse reader: add secondary note support

This commit is contained in:
Alexander Krotov
2019-02-18 15:21:32 +03:00
parent 2c7c8a6f40
commit c4814ea965
2 changed files with 28 additions and 5 deletions
+11 -5
View File
@@ -481,11 +481,17 @@ paraUntil end = do
guard $ not inPara
first (fmap B.para) <$> paraContentsUntil end
noteMarker :: PandocMonad m => MuseParser m String
noteMarker = try $ (:)
<$ char '['
noteMarker' :: PandocMonad m
=> Char
-> Char
-> MuseParser m String
noteMarker' l r = try $ (\x y -> l:x:y ++ [r])
<$ char l
<*> oneOf "123456789"
<*> manyTill digit (char ']')
<*> manyTill digit (char r)
noteMarker :: PandocMonad m => MuseParser m String
noteMarker = noteMarker' '[' ']' <|> noteMarker' '{' '}'
addNote :: PandocMonad m
=> String
@@ -797,7 +803,7 @@ footnote = try $ do
return $ do
notes <- asksF museNotes
case M.lookup ref notes of
Nothing -> return $ B.str $ "[" ++ ref ++ "]"
Nothing -> return $ B.str $ ref
Just (_pos, contents) -> do
st <- askF
let contents' = runF contents st { museNotes = M.delete ref (museNotes st) }
+17
View File
@@ -784,6 +784,23 @@ tests =
para (text "Here is a footnote" <>
note (para "Footnote contents") <>
str ".")
, "Simple secondary footnote" =:
T.unlines [ "Here is a secondary note{1}."
, ""
, "{1} Secondary note contents"
] =?>
para (text "Here is a secondary note" <>
note (para "Secondary note contents") <>
str ".")
, "Missing footnote" =: "Foo[1]" =?> para "Foo[1]"
, "Missing secondary note" =: "Foo{1}" =?> para "Foo{1}"
, "Wrong note type" =:
T.unlines [ "Here is a secondary note{1}"
, ""
, "Footnote contents[1]"
] =?>
para "Here is a secondary note{1}" <>
para "Footnote contents[1]"
, "Recursive footnote" =:
T.unlines [ "Start recursion here[1]"
, ""