diff options
author | Alexander Krotov <ilabdsf@gmail.com> | 2017-11-14 22:34:47 +0300 |
---|---|---|
committer | Alexander Krotov <ilabdsf@gmail.com> | 2017-11-18 23:43:02 +0300 |
commit | 6018a2324d4eddc3844aa4c00b17294e85003750 (patch) | |
tree | 2a96e2a990d72ba635aeeaff34a2918be2c1f606 /src/Text/Pandoc | |
parent | 26e59b331fc6ce2509a3b53f4454c0fadfbc58ee (diff) | |
download | pandoc-6018a2324d4eddc3844aa4c00b17294e85003750.tar.gz |
Muse reader: Add Text::Amuse footnote extensions
Footnote end is indicated by indentation,
so footnotes can be placed anywhere in the text,
not just at the end of it.
Diffstat (limited to 'src/Text/Pandoc')
-rw-r--r-- | src/Text/Pandoc/Readers/Muse.hs | 35 |
1 files changed, 29 insertions, 6 deletions
diff --git a/src/Text/Pandoc/Readers/Muse.hs b/src/Text/Pandoc/Readers/Muse.hs index 13b517d09..8c785e002 100644 --- a/src/Text/Pandoc/Readers/Muse.hs +++ b/src/Text/Pandoc/Readers/Muse.hs @@ -189,7 +189,8 @@ blockElements = choice [ comment , definitionList , table , commentTag - , noteBlock + , amuseNoteBlock + , emacsNoteBlock ] comment :: PandocMonad m => MuseParser m (F Blocks) @@ -308,8 +309,26 @@ noteMarker = try $ do char '[' many1Till digit $ char ']' -noteBlock :: PandocMonad m => MuseParser m (F Blocks) -noteBlock = try $ do +-- Amusewiki version of note +-- Parsing is similar to list item, except that note marker is used instead of list marker +amuseNoteBlock :: PandocMonad m => MuseParser m (F Blocks) +amuseNoteBlock = try $ do + guardEnabled Ext_amuse + pos <- getPosition + ref <- noteMarker <* skipSpaces + content <- listItemContents $ 2 + length ref + oldnotes <- stateNotes' <$> getState + case M.lookup ref oldnotes of + Just _ -> logMessage $ DuplicateNoteReference ref pos + Nothing -> return () + updateState $ \s -> s{ stateNotes' = M.insert ref (pos, content) oldnotes } + return mempty + +-- Emacs version of note +-- Notes are allowed only at the end of text, no indentation is required. +emacsNoteBlock :: PandocMonad m => MuseParser m (F Blocks) +emacsNoteBlock = try $ do + guardDisabled Ext_amuse pos <- getPosition ref <- noteMarker <* skipSpaces content <- mconcat <$> blocksTillNote @@ -376,9 +395,8 @@ listStart marker = try $ do postWhitespace <- length <$> many1 spaceChar return $ preWhitespace + markerLength + postWhitespace -listItem :: PandocMonad m => MuseParser m Int -> MuseParser m (F Blocks) -listItem start = try $ do - markerLength <- start +listItemContents :: PandocMonad m => Int -> MuseParser m (F Blocks) +listItemContents markerLength = do firstLine <- anyLineNewline restLines <- many $ listLine markerLength blank <- option "" ("\n" <$ blankline) @@ -386,6 +404,11 @@ listItem start = try $ do rest <- many $ listContinuation markerLength parseFromString (withListContext parseBlocks) $ concat (first:rest) ++ "\n" +listItem :: PandocMonad m => MuseParser m Int -> MuseParser m (F Blocks) +listItem start = try $ do + markerLength <- start + listItemContents markerLength + bulletListItems :: PandocMonad m => MuseParser m (F [Blocks]) bulletListItems = sequence <$> many1 (listItem bulletListStart) |