Skip to content
This repository was archived by the owner on Jun 15, 2023. It is now read-only.

Commit 4c7ed28

Browse files
authored
Merge pull request #85 from paulyoung/paulyoung/0.12
Updates for 0.12
2 parents 1a7e40c + eeede6d commit 4c7ed28

File tree

16 files changed

+119
-566
lines changed

16 files changed

+119
-566
lines changed

README.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@ import Text.Markdown.SlamDown.Pretty
3434
Module documentation is [published on
3535
Pursuit](http://pursuit.purescript.org/packages/purescript-markdown).
3636

37-
### Tests
38-
39-
The tests use [purescript-strongcheck](http://github.com/purescript-contrib/purescript-strongcheck) to verify that an arbitrary `SlamDown` document can be rendered as a `String` and then parsed to a `SlamDown` equal to the original.
40-
4137
## Features
4238

4339
In general, SlamDown is a subset of [CommonMark](http://spec.commonmark.org/), supporting the following features:

bower.json

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,20 @@
2222
"package.json"
2323
],
2424
"dependencies": {
25-
"purescript-const": "^3.0.0",
26-
"purescript-functors": "^2.0.0",
27-
"purescript-lists": "^4.0.0",
28-
"purescript-parsing": "^4.0.0",
29-
"purescript-partial": "^1.2.0",
30-
"purescript-precise": "^2.0.0",
31-
"purescript-prelude": "^3.0.0",
32-
"purescript-sets": "^3.0.0",
33-
"purescript-strings": "^3.0.0",
34-
"purescript-strongcheck": "^3.0.0",
35-
"purescript-unicode": "^3.0.1",
36-
"purescript-validation": "^3.0.0",
37-
"purescript-datetime": "^3.0.0"
25+
"purescript-const": "^4.0.0",
26+
"purescript-datetime": "^4.0.0",
27+
"purescript-functors": "^3.0.1",
28+
"purescript-lists": "^5.0.0",
29+
"purescript-ordered-collections": "^1.0.0",
30+
"purescript-parsing": "^5.0.1",
31+
"purescript-partial": "^2.0.0",
32+
"purescript-precise": "^3.0.1",
33+
"purescript-prelude": "^4.0.1",
34+
"purescript-strings": "^4.0.0",
35+
"purescript-unicode": "^4.0.1",
36+
"purescript-validation": "^4.0.0"
37+
},
38+
"devDependencies": {
39+
"purescript-assert": "^4.0.0"
3840
}
3941
}

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
"test": "pulp test"
77
},
88
"devDependencies": {
9-
"pulp": "^11.0.0",
10-
"purescript": "^0.11.4",
11-
"purescript-psa": "^0.5.0",
9+
"pulp": "^12.3.0",
10+
"purescript": "^0.12.0",
11+
"purescript-psa": "^0.6.0",
1212
"rimraf": "^2.5.4"
1313
}
1414
}

src/Text/Markdown/SlamDown/Parser.purs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import Data.Foldable (any, all)
1111
import Data.List ((:))
1212
import Data.List as L
1313
import Data.Maybe as M
14-
import Data.Monoid (mempty)
15-
import Data.String as S
14+
import Data.String (Pattern(..), Replacement(..), drop, length, replace, split, take, trim) as S
15+
import Data.String.CodeUnits (countPrefix, dropWhile, singleton) as S
1616
import Data.String.Regex as RGX
1717
import Data.String.Regex.Unsafe as URX
1818
import Data.String.Regex.Flags as RXF
@@ -59,7 +59,7 @@ allChars p = all p <<< S.split (S.Pattern "")
5959

6060
removeNonIndentingSpaces String String
6161
removeNonIndentingSpaces s
62-
| S.count (isSpace <<< S.singleton) s < 4 = S.dropWhile (isSpace <<< S.singleton) s
62+
| S.countPrefix (isSpace <<< S.singleton) s < 4 = S.dropWhile (isSpace <<< S.singleton) s
6363
| otherwise = s
6464

6565
isRuleChar String Boolean
@@ -77,15 +77,15 @@ isRule s =
7777
isATXHeader String Boolean
7878
isATXHeader s =
7979
let
80-
level = S.count (\c → S.singleton c == "#") s
80+
level = S.countPrefix (\c → S.singleton c == "#") s
8181
rest = S.drop level s
8282
in
8383
level >= 1 && level <= 6 && S.take 1 rest == " "
8484

8585
splitATXHeader String { level Int, contents String }
8686
splitATXHeader s =
8787
let
88-
level = S.count (\c → S.singleton c == "#") s
88+
level = S.countPrefix (\c → S.singleton c == "#") s
8989
contents = S.drop (level + 1) s
9090
in
9191
{ level: level
@@ -120,7 +120,7 @@ splitBlockquote ss =
120120
blockquoteContents s = S.drop (if S.take 2 s == "> " then 2 else 1) s
121121

122122
countLeadingSpaces String Int
123-
countLeadingSpaces = S.count (isSpace <<< S.singleton)
123+
countLeadingSpaces = S.countPrefix (isSpace <<< S.singleton)
124124

125125
isBulleted String Boolean
126126
isBulleted s =
@@ -139,7 +139,7 @@ isBulleted s =
139139
isOrderedListMarker String Boolean
140140
isOrderedListMarker s =
141141
let
142-
n = S.count (isDigit <<< S.singleton) s
142+
n = S.countPrefix (isDigit <<< S.singleton) s
143143
next = S.take 1 (S.drop n s)
144144
ls = countLeadingSpaces (S.drop (n + 1) s)
145145
in
@@ -149,14 +149,14 @@ listItemType ∷ String → SD.ListType
149149
listItemType s
150150
| isBulleted s = SD.Bullet (S.take 1 s)
151151
| otherwise =
152-
let n = S.count (isDigit <<< S.singleton) s
152+
let n = S.countPrefix (isDigit <<< S.singleton) s
153153
in SD.Ordered (S.take 1 (S.drop n s))
154154

155155
listItemIndent String Int
156156
listItemIndent s
157157
| isBulleted s = 1 + min 4 (countLeadingSpaces (S.drop 1 s))
158158
| otherwise =
159-
let n = S.count (isDigit <<< S.singleton) s
159+
let n = S.countPrefix (isDigit <<< S.singleton) s
160160
in n + 1 + min 4 (countLeadingSpaces (S.drop (n + 1) s))
161161

162162
isListItemLine String Boolean
@@ -210,7 +210,7 @@ splitIndentedChunks ss =
210210
isCodeFence String Boolean
211211
isCodeFence s = isSimpleFence s || (isEvaluatedCode s && isSimpleFence (S.drop 1 s))
212212
where
213-
isSimpleFence s' = S.count (isFenceChar <<< S.singleton) s' >= 3
213+
isSimpleFence s' = S.countPrefix (isFenceChar <<< S.singleton) s' >= 3
214214

215215
isEvaluatedCode String Boolean
216216
isEvaluatedCode s = S.take 1 s == "!"
@@ -243,7 +243,7 @@ splitCodeFence indent fence ss =
243243
}
244244
where
245245
isClosingFence String Boolean
246-
isClosingFence s = S.count (\c → S.singleton c == fence) (removeNonIndentingSpaces s) >= 3
246+
isClosingFence s = S.countPrefix (\c → S.singleton c == fence) (removeNonIndentingSpaces s) >= 3
247247

248248
removeIndentTo String String
249249
removeIndentTo s = S.drop (min indent (countLeadingSpaces s)) s

src/Text/Markdown/SlamDown/Parser/Inline.purs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ import Data.HugeNum as HN
2323
import Data.Int as Int
2424
import Data.List as L
2525
import Data.Maybe as M
26-
import Data.String as S
26+
import Data.String (joinWith, trim) as S
27+
import Data.String.CodeUnits (fromCharArray, singleton, toCharArray) as S
2728
import Data.Traversable (traverse)
2829
import Data.Tuple (Tuple(..), fst, snd)
2930
import Data.Validation.Semigroup as V
@@ -278,7 +279,7 @@ inlines = L.many inline2 <* PS.eof
278279
M.Nothing → pure $ Right $ SD.TextBox $ SD.transTextBox (const $ Compose M.Nothing) template
279280
M.Just _ → do
280281
PU.skipSpaces
281-
mdef ← PC.optionMaybe $ PC.try $ parseTextBox (_ /= ')') (expr id) template
282+
mdef ← PC.optionMaybe $ PC.try $ parseTextBox (_ /= ')') (expr identity) template
282283
case mdef of
283284
M.Just def → do
284285
PU.skipSpaces
@@ -386,8 +387,8 @@ inlines = L.many inline2 <* PS.eof
386387
dropDown P.Parser String (SD.FormField a)
387388
dropDown = do
388389
let item = SD.stringValue <<< S.trim <$> manyOf \c → not $ c `elem` ['{','}',',','!','`','(',')']
389-
ls ← PU.braces $ expr id $ (PC.try (PU.skipSpaces *> item)) `PC.sepBy` (PU.skipSpaces *> PS.string ",")
390-
sel ← PC.optionMaybe $ PU.skipSpaces *> (PU.parens $ expr id $ item)
390+
ls ← PU.braces $ expr identity $ (PC.try (PU.skipSpaces *> item)) `PC.sepBy` (PU.skipSpaces *> PS.string ",")
391+
sel ← PC.optionMaybe $ PU.skipSpaces *> (PU.parens $ expr identity $ item)
391392
pure $ SD.DropDown sel ls
392393

393394
other P.Parser String (SD.Inline a)

src/Text/Markdown/SlamDown/Parser/References.purs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import Prelude
77
import Data.Array as A
88
import Data.Either as E
99
import Data.Maybe as M
10-
import Data.String as S
10+
import Data.String (trim) as S
11+
import Data.String.CodeUnits (fromCharArray) as S
1112

1213
import Text.Parsing.Parser as P
1314
import Text.Parsing.Parser.Combinators as PC

src/Text/Markdown/SlamDown/Parser/Utils.purs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ module Text.Markdown.SlamDown.Parser.Utils
1010
import Prelude
1111

1212
import Data.Either (fromRight)
13-
import Data.String (singleton)
13+
import Data.String.CodeUnits (singleton)
1414
import Data.String.Regex as R
1515
import Data.String.Regex.Flags as RF
1616

src/Text/Markdown/SlamDown/Pretty.purs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ import Data.Identity (Identity(..))
1414
import Data.List as L
1515
import Data.Maybe as M
1616
import Data.Enum (fromEnum)
17-
import Data.Monoid (mempty)
1817
import Data.Newtype (unwrap)
19-
import Data.String as S
18+
import Data.String (Pattern(..), indexOf, joinWith, length, split, stripSuffix) as S
19+
import Data.String.CodeUnits (fromCharArray) as S
2020
import Data.Unfoldable as U
2121

2222
import Text.Markdown.SlamDown.Syntax as SD
@@ -174,11 +174,11 @@ prettyPrintTextBox t =
174174
prettyPrintDefault SD.TextBox SD.Expr String
175175
prettyPrintDefault =
176176
case _ of
177-
SD.PlainText def → prettyPrintExpr id id def
178-
SD.Numeric def → prettyPrintExpr id HN.toString def
179-
SD.Date def → prettyPrintExpr id prettyPrintDate def
180-
SD.Time prec def → prettyPrintExpr id (prettyPrintTime prec) def
181-
SD.DateTime prec def → prettyPrintExpr id (prettyPrintDateTime prec) def
177+
SD.PlainText def → prettyPrintExpr identity identity def
178+
SD.Numeric def → prettyPrintExpr identity HN.toString def
179+
SD.Date def → prettyPrintExpr identity prettyPrintDate def
180+
SD.Time prec def → prettyPrintExpr identity (prettyPrintTime prec) def
181+
SD.DateTime prec def → prettyPrintExpr identity (prettyPrintDateTime prec) def
182182

183183

184184
prettyPrintFormElement a. (SD.Value a) SD.FormField a String
@@ -200,8 +200,8 @@ prettyPrintFormElement el =
200200
SD.CheckBoxes (SD.Unevaluated bs) (SD.Unevaluated ls) →
201201
"[!`" <> bs <> "`] !`" <> ls <> "`"
202202
SD.DropDown sel lbls →
203-
braces (prettyPrintExpr id (A.fromFoldable >>> map SD.renderValue >>> S.joinWith ", ") lbls)
204-
<> M.maybe "" (parens <<< prettyPrintExpr id SD.renderValue) sel
203+
braces (prettyPrintExpr identity (A.fromFoldable >>> map SD.renderValue >>> S.joinWith ", ") lbls)
204+
<> M.maybe "" (parens <<< prettyPrintExpr identity SD.renderValue) sel
205205
_ → "Unsupported form element"
206206

207207
prettyPrintExpr a. (String String) (a String) SD.Expr a String

src/Text/Markdown/SlamDown/Syntax.purs

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,34 +9,28 @@ module Text.Markdown.SlamDown.Syntax
99

1010
import Prelude
1111

12+
import Data.Eq (class Eq1)
1213
import Data.List as L
13-
import Data.Monoid (class Monoid, mempty)
14-
import Test.StrongCheck.Arbitrary as SCA
15-
import Test.StrongCheck.Gen as Gen
16-
17-
import Text.Markdown.SlamDown.Syntax.Block as SDB
18-
import Text.Markdown.SlamDown.Syntax.FormField as SDF
19-
import Text.Markdown.SlamDown.Syntax.Inline as SDI
14+
import Data.Ord (class Ord1)
15+
import Text.Markdown.SlamDown.Syntax.Block (Block(..), CodeBlockType(..), ListType(..)) as SDB
16+
import Text.Markdown.SlamDown.Syntax.FormField (class Value, Expr(..), FormField, FormFieldP(..), TextBox(..), TimePrecision(..), getLiteral, getUnevaluated, renderValue, stringValue, transFormField, transTextBox, traverseFormField, traverseTextBox) as SDF
17+
import Text.Markdown.SlamDown.Syntax.Inline (Inline(..), LinkTarget(..)) as SDI
2018

2119
-- | `SlamDownP` is the type of SlamDown abstract syntax trees which take values in `a`.
22-
data SlamDownP a = SlamDown (L.List (SDB.Block a))
20+
newtype SlamDownP a = SlamDown (L.List (SDB.Block a))
2321

2422
type SlamDown = SlamDownP String
2523

26-
instance functorSlamDownPFunctor SlamDownP where
27-
map f (SlamDown bs) = SlamDown (map f <$> bs)
24+
derive instance functorSlamDownPFunctor SlamDownP
2825

2926
instance showSlamDownP ∷ (Show a) Show (SlamDownP a) where
3027
show (SlamDown bs) = "(SlamDown " <> show bs <> ")"
3128

32-
derive instance eqSlamDownP ∷ (Eq a, Ord a) Eq (SlamDownP a)
33-
derive instance ordSlamDownP ∷ (Eq a, Ord a) Ord (SlamDownP a)
34-
35-
instance semigroupSlamDownPSemigroup (SlamDownP a) where
36-
append (SlamDown bs1) (SlamDown bs2) = SlamDown (bs1 <> bs2)
29+
derive newtype instance eqSlamDownPEq a Eq (SlamDownP a)
30+
derive instance eq1SlamDownPEq1 SlamDownP
3731

38-
instance monoidSlamDownPMonoid (SlamDownP a) where
39-
mempty = SlamDown mempty
32+
derive newtype instance ordSlamDownPOrd a Ord (SlamDownP a)
33+
derive instance ord1SlamDownPOrd1 SlamDownP
4034

41-
instance arbitrarySlamDownP(SCA.Arbitrary a, Eq a) SCA.Arbitrary (SlamDownP a) where
42-
arbitrary = SlamDown <<< L.fromFoldable <$> Gen.arrayOf SCA.arbitrary
35+
derive newtype instance semigroupSlamDownPSemigroup (SlamDownP a)
36+
derive newtype instance monoidSlamDownPMonoid (SlamDownP a)

src/Text/Markdown/SlamDown/Syntax/Block.purs

Lines changed: 8 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@ module Text.Markdown.SlamDown.Syntax.Block
66

77
import Prelude
88

9+
import Data.Eq (class Eq1)
910
import Data.List as L
10-
11-
import Test.StrongCheck.Arbitrary as SCA
12-
import Test.StrongCheck.Gen as Gen
13-
11+
import Data.Ord (class Ord1)
1412
import Text.Markdown.SlamDown.Syntax.Inline (Inline)
1513

1614
data Block a
@@ -22,18 +20,9 @@ data Block a
2220
| LinkReference String String
2321
| Rule
2422

25-
instance functorBlockFunctor Block where
26-
map f x =
27-
case x of
28-
Paragraph is → Paragraph (map f <$> is)
29-
Header n is → Header n (map f <$> is)
30-
Blockquote bs → Blockquote (map f <$> bs)
31-
Lst ty bss → Lst ty (map (map f) <$> bss)
32-
CodeBlock ty ss → CodeBlock ty ss
33-
LinkReference l uri → LinkReference l uri
34-
RuleRule
23+
derive instance functorBlockFunctor Block
3524

36-
instance showBlock(Show a) Show (Block a) where
25+
instance showBlockShow a Show (Block a) where
3726
show (Paragraph is) = "(Paragraph " <> show is <> ")"
3827
show (Header n is) = "(Header " <> show n <> " " <> show is <> ")"
3928
show (Blockquote bs) = "(Blockquote " <> show bs <> ")"
@@ -42,24 +31,10 @@ instance showBlock ∷ (Show a) ⇒ Show (Block a) where
4231
show (LinkReference l uri) = "(LinkReference " <> show l <> " " <> show uri <> ")"
4332
show Rule = "Rule"
4433

45-
derive instance eqBlock ∷ (Eq a, Ord a) Eq (Block a)
46-
derive instance ordBlock ∷ (Ord a) Ord (Block a)
47-
48-
-- | Nota bene: this does not generate any recursive structure
49-
instance arbitraryBlock ∷ (SCA.Arbitrary a, Eq a) SCA.Arbitrary (Block a) where
50-
arbitrary = do
51-
k ← Gen.chooseInt 0 6
52-
case k of
53-
0Paragraph <$> listOf SCA.arbitrary
54-
1Header <$> SCA.arbitrary <*> listOf SCA.arbitrary
55-
2 → pure $ Blockquote L.Nil
56-
3Lst <$> SCA.arbitrary <*> listOf (pure L.Nil)
57-
4CodeBlock <$> SCA.arbitrary <*> listOf SCA.arbitrary
58-
5LinkReference <$> SCA.arbitrary <*> SCA.arbitrary
59-
_ → pure Rule
60-
61-
listOf f a. (Monad f) Gen.GenT f a Gen.GenT f (L.List a)
62-
listOf = map L.fromFoldable <<< Gen.arrayOf
34+
derive instance eqBlockEq a Eq (Block a)
35+
derive instance eq1BlockEq1 Block
36+
derive instance ordBlockOrd a Ord (Block a)
37+
derive instance ord1BlockOrd1 Block
6338

6439
data ListType
6540
= Bullet String
@@ -72,11 +47,6 @@ instance showListType ∷ Show ListType where
7247
derive instance eqListTypeEq ListType
7348
derive instance ordListTypeOrd ListType
7449

75-
instance arbitraryListTypeSCA.Arbitrary ListType where
76-
arbitrary = do
77-
b ← SCA.arbitrary
78-
if b then Bullet <$> SCA.arbitrary else Ordered <$> SCA.arbitrary
79-
8050
data CodeBlockType
8151
= Indented
8252
| Fenced Boolean String
@@ -87,8 +57,3 @@ instance showCodeBlockType ∷ Show CodeBlockType where
8757

8858
derive instance eqCodeBlockTypeEq CodeBlockType
8959
derive instance ordCodeBlockTypeOrd CodeBlockType
90-
91-
instance arbitraryCodeBlockTypeSCA.Arbitrary CodeBlockType where
92-
arbitrary = do
93-
b ← SCA.arbitrary
94-
if b then pure Indented else Fenced <$> SCA.arbitrary <*> SCA.arbitrary

0 commit comments

Comments
 (0)