git.iko.soy/typeable/pandoc
on master help sign in
Muse reader: allow examples to be indented with tabs
commit6fc812485e26f169bfe560b5f78c572378cbc53a authorAlexander Krotov <ilabdsf@gmail.com> dateWed 17 Oct 2018, 15:42 (8 years ago) parent1071732
2 files changed+13−8
src/Text/Pandoc/Readers/Muse.hs+5−8 test/Tests/Readers/Muse.hs+8
src/Text/Pandoc/Readers/Muse.hs+5−8
@@ -45,7 +45,7 @@ import Control.Monad.Reader
4545import Control.Monad.Except (throwError)
4646import Data.Bifunctor
4747import Data.Default
48−import Data.List (intercalate)
48+import Data.List (intercalate, transpose)
4949import Data.List.Split (splitOn)
5050import qualified Data.Map as M
5151import qualified Data.Set as Set
@@ -135,9 +135,6 @@ parseMuse = do
135135
136136-- * Utility functions
137137
138−commonPrefix :: String -> String -> String
139−commonPrefix xs ys = map fst $ takeWhile (uncurry (==)) $ zip xs ys
140−
141138-- | Trim up to one newline from the beginning of the string.
142139lchop :: String -> String
143140lchop ('\n':xs) = xs
@@ -151,10 +148,10 @@ unindent :: String -> String
151148unindent = rchop . intercalate "\n" . dropSpacePrefix . splitOn "\n" . lchop
152149
153150dropSpacePrefix :: [String] -> [String]
154−dropSpacePrefix lns =
155− map (drop maxIndent) lns
156− where flns = filter (not . all (== ' ')) lns
157− maxIndent = if null flns then maximum (map length lns) else length $ takeWhile (== ' ') $ foldl1 commonPrefix flns
151+dropSpacePrefix lns = drop maxIndent <$> lns
152+ where isSpaceChar c = c == ' ' || c == '\t'
153+ maxIndent = length $ takeWhile (isSpaceChar . head) $ takeWhile same $ transpose lns
154+ same = and . (zipWith (==) <*> drop 1)
158155
159156atStart :: PandocMonad m => MuseParser m ()
160157atStart = do
test/Tests/Readers/Muse.hs+8
@@ -465,6 +465,14 @@ tests =
465465 , " }}}"
466466 ] =?>
467467 bulletList [ codeBlock "Example line" ]
468+ , "Tabs" =:
469+ T.unlines [ "{{{"
470+ , "\t foo"
471+ , "\t\t"
472+ , "\t bar"
473+ , "}}}"
474+ ] =?>
475+ codeBlock " foo\n\t\n bar"
468476 -- Amusewiki requires braces to be on separate line,
469477 -- this is an extension.
470478 , "One line" =: