@@ -44,7 +44,6 @@ import Control.Monad
4444import Control.Monad.Reader
4545import Control.Monad.Except (throwError)
4646import Data.Bifunctor
47−import Data.Char (isAlphaNum)
4847import Data.Default
4948import Data.List (intercalate)
5049import Data.List.Split (splitOn)
@@ -69,7 +68,7 @@ readMuse :: PandocMonad m
6968 -> m Pandoc
7069readMuse opts s = do
7170 let input = crFilter s
72− res <- runReaderT (runParserT parseMuse def{ museOptions = opts } "source" input) def
71+ res <- flip runReaderT def $ runParserT parseMuse def{ museOptions = opts } "source" input
7372 case res of
7473 Left e -> throwError $ PandocParsecError (unpack input) e
7574 Right d -> return d
@@ -132,9 +131,7 @@ parseMuse = do
132131 many directive
133132 blocks <- (:) <$> parseBlocks <*> many parseSection
134133 st <- getState
135− let doc = runF (Pandoc <$> museMeta st <*> fmap B.toList (mconcat blocks)) st
136− reportLogMessages
137− return doc
134+ runF (Pandoc <$> museMeta st <*> fmap B.toList (mconcat blocks)) st <$ reportLogMessages
138135
139136-- * Utility functions
140137
@@ -203,7 +200,7 @@ htmlAttrToPandoc attrs = (ident, classes, keyvals)
203200 where
204201 ident = fromMaybe "" $ lookup "id" attrs
205202 classes = maybe [] words $ lookup "class" attrs
206− keyvals = [(k,v) | (k,v) <- attrs, k /= "id" && k /= "class"]
203+ keyvals = [(k,v) | (k,v) <- attrs, k /= "id", k /= "class"]
207204
208205parseHtmlContent :: PandocMonad m
209206 => String -- ^ Tag name
@@ -279,28 +276,22 @@ parseSection =
279276parseBlocksTill :: PandocMonad m
280277 => MuseParser m a
281278 -> MuseParser m (F Blocks)
282−parseBlocksTill end =
283− try (parseEnd <|>
284− blockStart <|>
285− listStart <|>
286− paraStart)
279+parseBlocksTill end = continuation
287280 where
288281 parseEnd = mempty <$ end
289282 blockStart = (B.<>) <$> blockElements <*> allowPara continuation
290283 listStart = uncurry (B.<>) <$> allowPara (anyListUntil (parseEnd <|> continuation))
291284 paraStart = uncurry (B.<>) <$> paraUntil (parseEnd <|> continuation)
292− continuation = parseBlocksTill end
285+ continuation = try $ parseEnd <|> blockStart <|> listStart <|> paraStart
293286
294287listItemContentsUntil :: PandocMonad m
295288 => Int
296289 -> MuseParser m a
297290 -> MuseParser m a
298291 -> MuseParser m (F Blocks, a)
299−listItemContentsUntil col pre end =
300− try blockStart <|>
301− try listStart <|>
302− try paraStart
292+listItemContentsUntil col pre end = p
303293 where
294+ p = try blockStart <|> try listStart <|> try paraStart
304295 parsePre = (mempty,) <$> pre
305296 parseEnd = (mempty,) <$> end
306297 paraStart = do
@@ -314,7 +305,7 @@ listItemContentsUntil col pre end =
314305 continuation = try $ do blank <- optionMaybe blankline
315306 skipMany blankline
316307 indentWith col
317− local (\s -> s { museInPara = museInPara s && isNothing blank }) $ listItemContentsUntil col pre end
308+ local (\s -> s { museInPara = museInPara s && isNothing blank }) p
318309
319310parseBlock :: PandocMonad m => MuseParser m (F Blocks)
320311parseBlock = do
@@ -435,9 +426,9 @@ divTag = do
435426-- | Parse @\<biblio>@ tag, the result is the same as @\<div class="biblio">@.
436427-- @\<biblio>@ tag is supported only in Text::Amuse mode.
437428biblioTag :: PandocMonad m => MuseParser m (F Blocks)
438−biblioTag = do
439− guardEnabled Ext_amuse
440− fmap (B.divWith ("", ["biblio"], [])) . snd <$> parseHtmlContent "biblio"
429+biblioTag = fmap (B.divWith ("", ["biblio"], [])) . snd
430+ <$ guardEnabled Ext_amuse
431+ <*> parseHtmlContent "biblio"
441432
442433-- | Parse @\<play>@ tag, the result is the same as @\<div class="play">@.
443434-- @\<play>@ tag is supported only in Text::Amuse mode.
@@ -489,6 +480,17 @@ noteMarker = try $ (:)
489480 <*> oneOf "123456789"
490481 <*> manyTill digit (char ']')
491482
483+addNote :: PandocMonad m
484+ => String
485+ -> SourcePos
486+ -> F Blocks
487+ -> MuseParser m ()
488+addNote ref pos content = do
489+ oldnotes <- museNotes <$> getState
490+ when (M.member ref oldnotes)
491+ (logMessage $ DuplicateNoteReference ref pos)
492+ updateState $ \s -> s{ museNotes = M.insert ref (pos, content) oldnotes }
493+
492494-- Amusewiki version of note
493495-- Parsing is similar to list item, except that note marker is used instead of list marker
494496amuseNoteBlockUntil :: PandocMonad m
@@ -499,10 +501,7 @@ amuseNoteBlockUntil end = try $ do
499501 ref <- noteMarker <* spaceChar
500502 pos <- getPosition
501503 (content, e) <- allowPara $ listItemContentsUntil (sourceColumn pos - 1) (fail "x") end
502− oldnotes <- museNotes <$> getState
503− when (M.member ref oldnotes)
504− (logMessage $ DuplicateNoteReference ref pos)
505− updateState $ \s -> s{ museNotes = M.insert ref (pos, content) oldnotes }
504+ addNote ref pos content
506505 return (mempty, e)
507506
508507-- Emacs version of note
@@ -510,13 +509,10 @@ amuseNoteBlockUntil end = try $ do
510509emacsNoteBlock :: PandocMonad m => MuseParser m (F Blocks)
511510emacsNoteBlock = try $ do
512511 guardDisabled Ext_amuse
513− pos <- getPosition
514512 ref <- noteMarker <* skipSpaces
515− content <- mconcat <$> blocksTillNote
516− oldnotes <- museNotes <$> getState
517− when (M.member ref oldnotes)
518− (logMessage $ DuplicateNoteReference ref pos)
519− updateState $ \s -> s{ museNotes = M.insert ref (pos, content) oldnotes }
513+ pos <- getPosition
514+ content <- fmap mconcat blocksTillNote
515+ addNote ref pos content
520516 return mempty
521517 where
522518 blocksTillNote =
@@ -688,7 +684,7 @@ tableParseRow :: PandocMonad m
688684tableParseRow n = try $ sequence <$> tableCells
689685 where tableCells = (:) <$> tableCell sep <*> (tableCells <|> fmap pure (tableCell eol))
690686 tableCell p = try $ fmap B.plain . trimInlinesF . mconcat <$> manyTill inline' p
691− sep = try $ many1 spaceChar *> count n (char '|') *> (void (lookAhead $ many1 spaceChar) <|> void (lookAhead eol))
687+ sep = try $ many1 spaceChar *> count n (char '|') *> lookAhead (void (many1 spaceChar) <|> void eol)
692688
693689-- | Parse a table header row.
694690tableParseHeader :: PandocMonad m => MuseParser m (F MuseTableElement)
@@ -852,7 +848,7 @@ code = try $ fmap pure $ B.code . uncurry (++)
852848 <$ atStart (char '=')
853849 <* notFollowedBy (spaceChar <|> newline)
854850 <*> manyUntil (noneOf "\n\r" <|> (newline <* notFollowedBy newline)) (try $ fmap pure $ noneOf " \t\n\r=" <* char '=')
855− <* notFollowedBy (satisfy isAlphaNum)
851+ <* notFollowedBy alphaNum
856852
857853-- | Parse @\<code>@ tag.
858854codeTag :: PandocMonad m => MuseParser m (F Inlines)
@@ -877,7 +873,7 @@ str :: PandocMonad m => MuseParser m (F Inlines)
877873str = return . B.str <$> many1 alphaNum <* updateLastStrPos
878874
879875symbol :: PandocMonad m => MuseParser m (F Inlines)
880−symbol = return . B.str <$> count 1 nonspaceChar
876+symbol = pure . B.str . pure <$> nonspaceChar
881877
882878-- | Parse a link or image.
883879linkOrImage :: PandocMonad m => MuseParser m (F Inlines)