@@ -1,5 +1,6 @@
11{-# LANGUAGE NoImplicitPrelude #-}
2−{-# LANGUAGE FlexibleContexts #-}
2+{-# LANGUAGE FlexibleContexts #-}
3+{-# LANGUAGE TupleSections #-}
34{-
45 Copyright (C) 2017-2018 Alexander Krotov <ilabdsf@gmail.com>
56
@@ -174,7 +175,7 @@ parseHtmlContent tag = try $ do
174175 pos <- getPosition
175176 (TagOpen _ attr, _) <- htmlTag (~== TagOpen tag [])
176177 manyTill spaceChar eol
177− content <- parseBlocksTill (try $ ((count (sourceColumn pos - 1) spaceChar) >> endtag))
178+ content <- parseBlocksTill $ try $ count (sourceColumn pos - 1) spaceChar >> endtag
178179 manyTill spaceChar eol -- closing tag must be followed by optional whitespace and newline
179180 return (htmlAttrToPandoc attr, content)
180181 where
@@ -274,9 +275,7 @@ parseBlocksTill end =
274275 paraStart)
275276 where
276277 parseEnd = mempty <$ end
277− blockStart = do first <- blockElements
278− rest <- continuation
279− return $ first B.<> rest
278+ blockStart = (B.<>) <$> blockElements <*> continuation
280279 listStart = do
281280 updateState (\st -> st { museInPara = False })
282281 (first, e) <- anyListUntil ((Left <$> end) <|> (Right <$> continuation))
@@ -299,10 +298,8 @@ listItemContentsUntil col pre end =
299298 try listStart <|>
300299 try paraStart
301300 where
302− parsePre = do e <- pre
303− return (mempty, e)
304− parseEnd = do e <- end
305− return (mempty, e)
301+ parsePre = (mempty,) <$> pre
302+ parseEnd = (mempty,) <$> end
306303 paraStart = do
307304 (first, e) <- paraUntil ((Left <$> pre) <|> (Right <$> continuation) <|> (Left <$> end))
308305 case e of
@@ -468,9 +465,7 @@ paraUntil end = do
468465noteMarker :: PandocMonad m => MuseParser m String
469466noteMarker = try $ do
470467 char '['
471− first <- oneOf "123456789"
472− rest <- manyTill digit (char ']')
473− return $ first:rest
468+ (:) <$> oneOf "123456789" <*> manyTill digit (char ']')
474469
475470-- Amusewiki version of note
476471-- Parsing is similar to list item, except that note marker is used instead of list marker
@@ -713,11 +708,7 @@ elementsToTable = foldM museAppendElement emptyTable
713708 where emptyTable = MuseTable mempty mempty mempty mempty
714709
715710table :: PandocMonad m => MuseParser m (F Blocks)
716−table = try $ do
717− rows <- tableElements
718− let tbl = elementsToTable rows
719− let pandocTbl = museToPandocTable <$> tbl :: F Blocks
720− return pandocTbl
711+table = try $ fmap museToPandocTable <$> (elementsToTable <$> tableElements)
721712
722713tableParseElement :: PandocMonad m => MuseParser m MuseTableElement
723714tableParseElement = tableParseHeader
@@ -831,16 +822,14 @@ enclosedInlines start end = try $
831822 trimInlinesF . mconcat <$> (enclosed (atStart start) end inline <* notFollowedBy (satisfy isLetter))
832823
833824inlineTag :: PandocMonad m
834− => (Inlines -> Inlines)
835− -> String
825+ => String
836826 -> MuseParser m (F Inlines)
837−inlineTag f tag = try $ do
827+inlineTag tag = try $ do
838828 htmlTag (~== TagOpen tag [])
839− res <- manyTill inline (void $ htmlTag (~== TagClose tag))
840− return $ f <$> mconcat res
829+ mconcat <$> manyTill inline (void $ htmlTag (~== TagClose tag))
841830
842831strongTag :: PandocMonad m => MuseParser m (F Inlines)
843−strongTag = inlineTag B.strong "strong"
832+strongTag = fmap B.strong <$> inlineTag "strong"
844833
845834strong :: PandocMonad m => MuseParser m (F Inlines)
846835strong = fmap B.strong <$> emphasisBetween (string "**")
@@ -854,16 +843,16 @@ underlined = do
854843 fmap underlineSpan <$> emphasisBetween (char '_')
855844
856845emphTag :: PandocMonad m => MuseParser m (F Inlines)
857−emphTag = inlineTag B.emph "em"
846+emphTag = fmap B.emph <$> inlineTag "em"
858847
859848superscriptTag :: PandocMonad m => MuseParser m (F Inlines)
860−superscriptTag = inlineTag B.superscript "sup"
849+superscriptTag = fmap B.superscript <$> inlineTag "sup"
861850
862851subscriptTag :: PandocMonad m => MuseParser m (F Inlines)
863−subscriptTag = inlineTag B.subscript "sub"
852+subscriptTag = fmap B.subscript <$> inlineTag "sub"
864853
865854strikeoutTag :: PandocMonad m => MuseParser m (F Inlines)
866−strikeoutTag = inlineTag B.strikeout "del"
855+strikeoutTag = fmap B.strikeout <$> inlineTag "del"
867856
868857verbatimTag :: PandocMonad m => MuseParser m (F Inlines)
869858verbatimTag = return . B.text . snd <$> htmlElement "verbatim"
@@ -891,9 +880,7 @@ code = try $ do
891880 return $ return $ B.code contents
892881
893882codeTag :: PandocMonad m => MuseParser m (F Inlines)
894−codeTag = do
895− (attrs, content) <- htmlElement "code"
896− return $ return $ B.codeWith attrs content
883+codeTag = return . uncurry B.codeWith <$> htmlElement "code"
897884
898885inlineLiteralTag :: PandocMonad m => MuseParser m (F Inlines)
899886inlineLiteralTag =
@@ -904,10 +891,7 @@ inlineLiteralTag =
904891 rawInline (attrs, content) = B.rawInline (format attrs) content
905892
906893str :: PandocMonad m => MuseParser m (F Inlines)
907−str = do
908− result <- many1 alphaNum
909− updateLastStrPos
910− return $ return $ B.str result
894+str = return . B.str <$> many1 alphaNum <* updateLastStrPos
911895
912896symbol :: PandocMonad m => MuseParser m (F Inlines)
913897symbol = return . B.str <$> count 1 nonspaceChar
@@ -929,9 +913,7 @@ link = try $ do
929913 isImageUrl = (`elem` imageExtensions) . takeExtension
930914
931915linkContent :: PandocMonad m => MuseParser m (F Inlines)
932−linkContent = do
933− char '['
934− trimInlinesF . mconcat <$> manyTill inline (string "]")
916+linkContent = char '[' >> trimInlinesF . mconcat <$> manyTill inline (string "]")
935917
936918linkText :: PandocMonad m => MuseParser m (String, String, Maybe (F Inlines))
937919linkText = do