@@ -4,23 +4,23 @@ module Text.Markdown.SlamDown.Parser
44 , validateSlamDown
55 ) where
66
7- import Prelude
7+ import Prelude hiding ( min )
88
9- import Data.Foldable (any , all )
109import Data.Either (Either )
10+ import Data.Foldable (any , all )
11+ import Data.List ((:))
1112import Data.List as L
1213import Data.Maybe as M
1314import Data.Monoid (mempty )
1415import Data.String as S
1516import Data.Traversable (traverse )
16- import Data.Validation as V
17+ import Data.Validation.Semigroup as V
18+
19+ import Partial.Unsafe (unsafePartial )
1720
18- import Text.Markdown.SlamDown.Syntax as SD
1921import Text.Markdown.SlamDown.Parser.Inline as Inline
2022import Text.Markdown.SlamDown.Parser.References as Ref
21-
22- infixr 6 L.Cons as :
23-
23+ import Text.Markdown.SlamDown.Syntax as SD
2424
2525data Container a
2626 = CText String
@@ -56,7 +56,7 @@ allChars p = all p <<< S.split ""
5656
5757removeNonIndentingSpaces ∷ String → String
5858removeNonIndentingSpaces s
59- | S .count (isSpace <<< S .fromChar ) s < 4 = S .dropWhile (isSpace <<< S .fromChar ) s
59+ | S .count (isSpace <<< S .singleton ) s < 4 = S .dropWhile (isSpace <<< S .singleton ) s
6060 | otherwise = s
6161
6262isRuleChar ∷ String → Boolean
@@ -74,15 +74,15 @@ isRule s =
7474isATXHeader ∷ String → Boolean
7575isATXHeader s =
7676 let
77- level = S .count (\c → S .fromChar c == " #" ) s
77+ level = S .count (\c → S .singleton c == " #" ) s
7878 rest = S .drop level s
7979 in
8080 level >= 1 && level <= 6 && S .take 1 rest == " "
8181
8282splitATXHeader ∷ String → { level ∷ Int , contents ∷ String }
8383splitATXHeader s =
8484 let
85- level = S .count (\c → S .fromChar c == " #" ) s
85+ level = S .count (\c → S .singleton c == " #" ) s
8686 contents = S .drop (level + 1 ) s
8787 in
8888 { level: level
@@ -117,7 +117,7 @@ splitBlockquote ss =
117117 blockquoteContents s = S .drop (if S .take 2 s == " > " then 2 else 1 ) s
118118
119119countLeadingSpaces ∷ String → Int
120- countLeadingSpaces = S .count (isSpace <<< S .fromChar )
120+ countLeadingSpaces = S .count (isSpace <<< S .singleton )
121121
122122isBulleted ∷ String → Boolean
123123isBulleted s =
@@ -136,7 +136,7 @@ isBulleted s =
136136isOrderedListMarker ∷ String → Boolean
137137isOrderedListMarker s =
138138 let
139- n = S .count (isDigit <<< S .fromChar ) s
139+ n = S .count (isDigit <<< S .singleton ) s
140140 next = S .take 1 (S .drop n s)
141141 ls = countLeadingSpaces (S .drop (n + 1 ) s)
142142 in
@@ -146,14 +146,14 @@ listItemType ∷ String → SD.ListType
146146listItemType s
147147 | isBulleted s = SD.Bullet (S .take 1 s)
148148 | otherwise =
149- let n = S .count (isDigit <<< S .fromChar ) s
149+ let n = S .count (isDigit <<< S .singleton ) s
150150 in SD.Ordered (S .take 1 (S .drop n s))
151151
152152listItemIndent ∷ String → Int
153153listItemIndent s
154154 | isBulleted s = 1 + min 4 (countLeadingSpaces (S .drop 1 s))
155155 | otherwise =
156- let n = S .count (isDigit <<< S .fromChar ) s
156+ let n = S .count (isDigit <<< S .singleton ) s
157157 in n + 1 + min 4 (countLeadingSpaces (S .drop (n + 1 ) s))
158158
159159isListItemLine ∷ String → Boolean
@@ -207,7 +207,7 @@ splitIndentedChunks ss =
207207isCodeFence ∷ String → Boolean
208208isCodeFence s = isSimpleFence s || (isEvaluatedCode s && isSimpleFence (S .drop 1 s))
209209 where
210- isSimpleFence s = S .count (isFenceChar <<< S .fromChar ) s >= 3
210+ isSimpleFence s = S .count (isFenceChar <<< S .singleton ) s >= 3
211211
212212isEvaluatedCode ∷ String → Boolean
213213isEvaluatedCode s = S .take 1 s == " !"
@@ -218,7 +218,7 @@ isFenceChar "`" = true
218218isFenceChar _ = false
219219
220220codeFenceInfo ∷ String → String
221- codeFenceInfo = S .trim <<< S .dropWhile (isFenceChar <<< S .fromChar )
221+ codeFenceInfo = S .trim <<< S .dropWhile (isFenceChar <<< S .singleton )
222222
223223codeFenceChar ∷ String → String
224224codeFenceChar = S .take 1
@@ -240,7 +240,7 @@ splitCodeFence indent fence ss =
240240 }
241241 where
242242 isClosingFence ∷ String → Boolean
243- isClosingFence s = S .count (\c → S .fromChar c == fence) (removeNonIndentingSpaces s) >= 3
243+ isClosingFence s = S .count (\c → S .singleton c == fence) (removeNonIndentingSpaces s) >= 3
244244
245245 removeIndentTo ∷ String → String
246246 removeIndentTo s = S .drop (min indent (countLeadingSpaces s)) s
@@ -289,7 +289,7 @@ parseContainers acc (L.Cons s ss)
289289 | isLinkReference (removeNonIndentingSpaces s) =
290290 let
291291 s1 = removeNonIndentingSpaces s
292- b = Data.Maybe.Unsafe .fromJust $ Ref .parseLinkReference s1
292+ b = unsafePartial M .fromJust $ Ref .parseLinkReference s1
293293 in
294294 parseContainers (L.Cons (CLinkReference b) acc) ss
295295 | otherwise = parseContainers (L.Cons (CText s) acc) ss
@@ -372,6 +372,6 @@ tabsToSpaces = S.replace "\t" " "
372372parseMd ∷ ∀ a . (SD.Value a ) ⇒ String → Either String (SD.SlamDownP a )
373373parseMd s = map SD.SlamDown bs
374374 where
375- lines = L .toList $ S .split " \n " $ S .replace " \r " " " $ tabsToSpaces s
375+ lines = L .fromFoldable $ S .split " \n " $ S .replace " \r " " " $ tabsToSpaces s
376376 ctrs = parseContainers mempty lines
377377 bs = parseBlocks ctrs
0 commit comments