Skip to content

Commit e90eed4

Browse files
committed
feat: Make it work for madlib 0.21.1
1 parent 61a721d commit e90eed4

File tree

5 files changed

+74
-38
lines changed

5 files changed

+74
-38
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ build
33
madlib_modules
44
node_modules
55
.module_cache
6+
src/Example.mad
7+
.DS_Store

madlib.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "MadMarkdownParser",
3-
"version": "0.0.3",
4-
"madlibVersion": "0.12.0",
3+
"version": "0.0.4",
4+
"madlibVersion": "0.21.1",
55
"main": "src/Main.mad",
66
"importAliases": {
77
".": "src"

src/Example.mad

+4-4
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ here are the items:
5454
// P.runParser(P.many(P.anyChar), mdBig)
5555
// P.runParser(P.many(P.choice([P.anyChar])), mdBig)
5656

57-
58-
parseMarkdown(mdFixture) |> IO.log
59-
60-
57+
main = () => {
58+
parseMarkdown(mdFixture) |> IO.log
59+
parseMarkdown(mdFixture) |> IO.cLog
60+
}

src/Main.mad

+25-25
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { dropWhile, filter } from "List"
1+
import { dropWhile, mapMaybe } from "List"
22
import { always, equals, identity } from "Function"
33
import { Just, Nothing } from "Maybe"
44
import type { Either } from "Either"
@@ -42,14 +42,15 @@ between = (start, mid, end) => pipe(
4242
apL($, end)
4343
)(start)
4444

45-
contentCharacter :: P.Parser Char
46-
contentCharacter = P.choice([
47-
P.letter,
48-
P.digit,
49-
P.char('!'),
50-
P.char('?'),
51-
P.char(' ')
52-
])
45+
46+
// contentCharacter :: P.Parser Char
47+
// contentCharacter = P.choice([
48+
// P.letter,
49+
// P.digit,
50+
// P.char('!'),
51+
// P.char('?'),
52+
// P.char(' ')
53+
// ])
5354

5455
// https://stackoverflow.com/questions/1547899/which-characters-make-a-url-invalid
5556
linkCharacter :: P.Parser Char
@@ -89,13 +90,21 @@ bold = pipe(
8990
apL($, P.string("**"))
9091
)(P.string("**"))
9192

93+
9294
italic :: P.Parser ContentPart
93-
italic = pipe(
94-
mapL((a, b) => Italic(String.pushChar(a, b))),
95-
ap($, P.notChar(' ')),
96-
ap($, pipe(P.many, map(String.fromList))(P.notOneOf(['*', '\n']))),
97-
apL($, P.char('*'))
98-
)(P.char('*'))
95+
italic = do {
96+
_ <- P.char('*')
97+
firstChar <- P.notChar(' ')
98+
nextChars <- P.many(P.notOneOf(['*', '\n']))
99+
_ <- P.char('*')
100+
101+
return pipe(
102+
String.fromList,
103+
String.pushChar(firstChar),
104+
Italic,
105+
of
106+
)([firstChar, ...nextChars])
107+
}
99108

100109
inlineCode :: P.Parser ContentPart
101110
inlineCode = pipe(
@@ -273,16 +282,7 @@ markdownParser :: P.Parser Markdown
273282
markdownParser = pipe(
274283
P.choice,
275284
P.many,
276-
map(pipe(
277-
filter(where {
278-
Just(x) =>
279-
true
280-
281-
Nothing =>
282-
false
283-
}),
284-
map(where { Just(x) => x })
285-
))
285+
map(mapMaybe((x) => x)),
286286
)([map(always(Nothing), P.spaces), map(Just, block)])
287287

288288

version.lock

+41-7
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
11
{
2-
"api": {
2+
"buildHash": "ab8cca75a596bb1bcc10877846ce3dd2",
3+
"jsApi": {
4+
"apiInstances": [],
35
"apiAliases": {
4-
"Content": "(List ContentPart)",
5-
"Markdown": "(List Block)"
6+
"Markdown": "(List Block)",
7+
"Content": "(List ContentPart)"
68
},
7-
"apiInstances": [],
89
"apiInterfaces": {},
910
"apiNames": {
1011
"parseMarkdown": "String -> Either String (List Block)"
1112
},
1213
"apiTypes": {
14+
"ContentPart": [
15+
"Text String",
16+
"Bold String",
17+
"Italic String",
18+
"InlineCode String",
19+
"Link String String",
20+
"Image String String",
21+
"LineReturn"
22+
],
1323
"Block": [
1424
"H1 Content",
1525
"H2 Content",
@@ -21,7 +31,20 @@
2131
"Blockquote Content",
2232
"Code String String",
2333
"UnorderedList (List Content)"
24-
],
34+
]
35+
}
36+
},
37+
"llvmApi": {
38+
"apiInstances": [],
39+
"apiAliases": {
40+
"Markdown": "(List Block)",
41+
"Content": "(List ContentPart)"
42+
},
43+
"apiInterfaces": {},
44+
"apiNames": {
45+
"parseMarkdown": "String -> Either String (List Block)"
46+
},
47+
"apiTypes": {
2548
"ContentPart": [
2649
"Text String",
2750
"Bold String",
@@ -30,9 +53,20 @@
3053
"Link String String",
3154
"Image String String",
3255
"LineReturn"
56+
],
57+
"Block": [
58+
"H1 Content",
59+
"H2 Content",
60+
"H3 Content",
61+
"H4 Content",
62+
"H5 Content",
63+
"H6 Content",
64+
"Paragraph Content",
65+
"Blockquote Content",
66+
"Code String String",
67+
"UnorderedList (List Content)"
3368
]
3469
}
3570
},
36-
"buildHash": "e1f3048c1f97de9540efb556aa817949",
37-
"versionHash": "7f76975313afde67f0b4efca59761e8a"
71+
"versionHash": "7417b617700b295682ee25ac611b0db6"
3872
}

0 commit comments

Comments
 (0)