markdown-unlit 0.3.1 → 0.4.0
raw patch · 3 files changed
+29/−6 lines, 3 files
Files
- markdown-unlit.cabal +1/−1
- src/Text/Markdown/Unlit.hs +13/−5
- test/Text/Markdown/UnlitSpec.hs +15/−0
markdown-unlit.cabal view
@@ -3,7 +3,7 @@ -- see: https://github.com/sol/hpack name: markdown-unlit-version: 0.3.1+version: 0.4.0 synopsis: Literate Haskell support for Markdown category: Development homepage: https://github.com/sol/markdown-unlit#readme
src/Text/Markdown/Unlit.hs view
@@ -21,6 +21,12 @@ import System.Exit import System.Environment +fenceChars :: [Char]+fenceChars = ['`', '~']++fences :: [String]+fences = map (replicate 3) fenceChars+ -- | Program entry point. run :: [String] -> IO () run args =@@ -115,13 +121,15 @@ (cb, rest) -> (CodeBlock (parseClasses fence) (map (drop indent . snd) cb) n, drop 1 rest) isFence :: Line -> Bool- isFence = isPrefixOf "~~~" . dropWhile isSpace . snd+ isFence = p . dropWhile isSpace . snd+ where+ p :: String -> Bool+ p line = any (`isPrefixOf` line) fences parseClasses :: String -> [String]-parseClasses xs = case dropWhile isSpace . dropWhile (== '~') . dropWhile isSpace $ xs of- '{':ys -> words . replace '.' ' ' . takeWhile (/= '}') $ ys- _ -> []-+parseClasses xs = words . replace '.' ' ' $ case dropWhile isSpace . dropWhile (`elem` fenceChars) . dropWhile isSpace $ xs of+ '{':ys -> takeWhile (/= '}') ys+ ys -> ys replace :: Char -> Char -> String -> String replace x sub = map f
test/Text/Markdown/UnlitSpec.hs view
@@ -186,6 +186,14 @@ "some other text" `shouldBe` [["some", "code"]] + it "accepts backticks as fence" $ do+ parse . build $ do+ "``` {.haskell .ignore}"+ "some"+ "code"+ "```"+ `shouldBe` [CodeBlock ["haskell", "ignore"] ["some", "code"] 2]+ it "parses an indented code block" $ do map codeBlockContent . parse . build $ do "1. some text"@@ -237,3 +245,10 @@ it "treats dots as whitespace" $ do parseClasses "~~~ {foo.bar. ..}" `shouldBe` ["foo", "bar"]++ context "without {...}" $ do+ it "accepts single class" $ do+ parseClasses "```haskell" `shouldBe` ["haskell"]++ it "accepts multiple classes" $ do+ parseClasses "```.haskell .ignore" `shouldBe` ["haskell", "ignore"]