@@ -46,10 +46,11 @@ module Text.Pandoc.Writers.Muse (writeMuse) where
4646import Prelude
4747import Control.Monad.Reader
4848import Control.Monad.State.Strict
49−import Data.Char (isSpace, isAlphaNum, isDigit, isAsciiUpper, isAsciiLower)
49+import Data.Char (isAlphaNum, isAsciiLower, isAsciiUpper, isDigit, isSpace)
5050import Data.Default
51+import Data.List (intersperse, isInfixOf, transpose)
52+import qualified Data.Set as Set
5153import Data.Text (Text)
52−import Data.List (intersperse, transpose, isInfixOf)
5354import System.FilePath (takeExtension)
5455import Text.Pandoc.Class (PandocMonad)
5556import Text.Pandoc.Definition
@@ -60,28 +61,27 @@ import Text.Pandoc.Shared
6061import Text.Pandoc.Templates (renderTemplate')
6162import Text.Pandoc.Writers.Math
6263import Text.Pandoc.Writers.Shared
63−import qualified Data.Set as Set
6464
6565type Notes = [[Block]]
6666
6767type Muse m = ReaderT WriterEnv (StateT WriterState m)
6868
6969data WriterEnv =
70− WriterEnv { envOptions :: WriterOptions
71− , envTopLevel :: Bool
72− , envInsideBlock :: Bool
73− , envInlineStart :: Bool -- ^ True if there is only whitespace since last newline
70+ WriterEnv { envOptions :: WriterOptions
71+ , envTopLevel :: Bool
72+ , envInsideBlock :: Bool
73+ , envInlineStart :: Bool -- ^ True if there is only whitespace since last newline
7474 , envInsideLinkDescription :: Bool -- ^ Escape ] if True
75− , envAfterSpace :: Bool -- ^ There is whitespace (not just newline) before
76− , envOneLine :: Bool -- ^ True if newlines are not allowed
77− , envInsideAsterisks :: Bool -- ^ True if outer element is emphasis with asterisks
78− , envNearAsterisks :: Bool -- ^ Rendering inline near asterisks
75+ , envAfterSpace :: Bool -- ^ There is whitespace (not just newline) before
76+ , envOneLine :: Bool -- ^ True if newlines are not allowed
77+ , envInsideAsterisks :: Bool -- ^ True if outer element is emphasis with asterisks
78+ , envNearAsterisks :: Bool -- ^ Rendering inline near asterisks
7979 }
8080
8181data WriterState =
82− WriterState { stNotes :: Notes
83− , stIds :: Set.Set String
84− , stUseTags :: Bool -- ^ Use tags for emphasis, for example because previous character is a letter
82+ WriterState { stNotes :: Notes
83+ , stIds :: Set.Set String
84+ , stUseTags :: Bool -- ^ Use tags for emphasis, for example because previous character is a letter
8585 }
8686
8787instance Default WriterState
@@ -158,7 +158,7 @@ flatBlockListToMuse bs@(OrderedList (_, style1, _) _ : OrderedList (_, style2, _
158158 style1' = normalizeStyle style1
159159 style2' = normalizeStyle style2
160160 normalizeStyle DefaultStyle = Decimal
161− normalizeStyle s = s
161+ normalizeStyle s = s
162162flatBlockListToMuse bs@(DefinitionList _ : DefinitionList _ : _) = catWithBlankLines bs 2
163163flatBlockListToMuse bs@(_ : _) = catWithBlankLines bs 0
164164flatBlockListToMuse [] = return mempty
@@ -292,9 +292,9 @@ noteToMuse :: PandocMonad m
292292noteToMuse num note =
293293 hang (length marker) (text marker) <$>
294294 local (\env -> env { envInsideBlock = True
295− , envInlineStart = True
296− , envAfterSpace = True
297− }) (blockListToMuse note)
295+ , envInlineStart = True
296+ , envAfterSpace = True
297+ }) (blockListToMuse note)
298298 where
299299 marker = "[" ++ show num ++ "] "
300300
@@ -308,34 +308,34 @@ escapeString s =
308308-- | Replace newlines with spaces
309309replaceNewlines :: String -> String
310310replaceNewlines ('\n':xs) = ' ':replaceNewlines xs
311−replaceNewlines (x:xs) = x:replaceNewlines xs
312−replaceNewlines [] = []
311+replaceNewlines (x:xs) = x:replaceNewlines xs
312+replaceNewlines [] = []
313313
314314startsWithMarker :: (Char -> Bool) -> String -> Bool
315315startsWithMarker f (' ':xs) = startsWithMarker f xs
316316startsWithMarker f (x:xs) =
317317 f x && (startsWithMarker f xs || startsWithDot xs)
318318 where
319− startsWithDot ['.'] = True
319+ startsWithDot ['.'] = True
320320 startsWithDot ('.':c:_) = isSpace c
321− startsWithDot _ = False
321+ startsWithDot _ = False
322322startsWithMarker _ [] = False
323323
324324-- | Escape special characters for Muse if needed.
325325containsFootnotes :: String -> Bool
326326containsFootnotes = p
327327 where p ('[':xs) = q xs || p xs
328− p (_:xs) = p xs
329− p "" = False
328+ p (_:xs) = p xs
329+ p "" = False
330330 q (x:xs)
331331 | x `elem` ("123456789"::String) = r xs || p xs
332332 | otherwise = p xs
333333 q [] = False
334334 r ('0':xs) = r xs || p xs
335− r xs = s xs || q xs || p xs
335+ r xs = s xs || q xs || p xs
336336 s (']':_) = True
337− s (_:xs) = p xs
338− s [] = False
337+ s (_:xs) = p xs
338+ s [] = False
339339
340340-- | Return True if string should be escaped with <verbatim> tags
341341shouldEscapeString :: PandocMonad m
@@ -375,14 +375,14 @@ preprocessInlineList [] = return []
375375
376376replaceSmallCaps :: Inline -> Inline
377377replaceSmallCaps (SmallCaps lst) = Emph lst
378−replaceSmallCaps x = x
378+replaceSmallCaps x = x
379379
380380removeKeyValues :: Inline -> Inline
381381removeKeyValues (Code (i, cls, _) xs) = Code (i, cls, []) xs
382382-- Do not remove attributes from Link
383383-- Do not remove attributes, such as "width", from Image
384384removeKeyValues (Span (i, cls, _) xs) = Span (i, cls, []) xs
385−removeKeyValues x = x
385+removeKeyValues x = x
386386
387387normalizeInlineList :: [Inline] -> [Inline]
388388normalizeInlineList (Str "" : xs)
@@ -412,35 +412,35 @@ normalizeInlineList (x:xs) = x : normalizeInlineList xs
412412normalizeInlineList [] = []
413413
414414fixNotes :: [Inline] -> [Inline]
415−fixNotes [] = []
416−fixNotes (Space : n@Note{} : rest) = Str " " : n : fixNotes rest
415+fixNotes [] = []
416+fixNotes (Space : n@Note{} : rest) = Str " " : n : fixNotes rest
417417fixNotes (SoftBreak : n@Note{} : rest) = Str " " : n : fixNotes rest
418−fixNotes (x:xs) = x : fixNotes xs
418+fixNotes (x:xs) = x : fixNotes xs
419419
420420startsWithSpace :: [Inline] -> Bool
421−startsWithSpace (Space:_) = True
421+startsWithSpace (Space:_) = True
422422startsWithSpace (SoftBreak:_) = True
423−startsWithSpace (Str s:_) = stringStartsWithSpace s
424−startsWithSpace _ = False
423+startsWithSpace (Str s:_) = stringStartsWithSpace s
424+startsWithSpace _ = False
425425
426426endsWithSpace :: [Inline] -> Bool
427−endsWithSpace [Space] = True
427+endsWithSpace [Space] = True
428428endsWithSpace [SoftBreak] = True
429−endsWithSpace [Str s] = stringStartsWithSpace $ reverse s
430−endsWithSpace (_:xs) = endsWithSpace xs
431−endsWithSpace [] = False
429+endsWithSpace [Str s] = stringStartsWithSpace $ reverse s
430+endsWithSpace (_:xs) = endsWithSpace xs
431+endsWithSpace [] = False
432432
433433urlEscapeBrackets :: String -> String
434434urlEscapeBrackets (']':xs) = '%':'5':'D':urlEscapeBrackets xs
435−urlEscapeBrackets (x:xs) = x:urlEscapeBrackets xs
436−urlEscapeBrackets [] = []
435+urlEscapeBrackets (x:xs) = x:urlEscapeBrackets xs
436+urlEscapeBrackets [] = []
437437
438438isHorizontalRule :: String -> Bool
439439isHorizontalRule s = length s >= 4 && all (== '-') s
440440
441441stringStartsWithSpace :: String -> Bool
442442stringStartsWithSpace (x:_) = isSpace x
443−stringStartsWithSpace "" = False
443+stringStartsWithSpace "" = False
444444
445445fixOrEscape :: Bool -> Inline -> Bool
446446fixOrEscape sp (Str "-") = sp