Skip to content

Commit e857502

Browse files
progfayprogfay
authored and
progfay
committed
Merge pull request #538 from progfay/fix-parsing-deco-strong-complex
1 parent 91b7d8b commit e857502

File tree

5 files changed

+157
-7
lines changed

5 files changed

+157
-7
lines changed

src/block/node/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ export const convertToNodes = combineNodeParsers(
4747
CommandLineNodeParser,
4848
FormulaNodeParser,
4949
BlankNodeParser,
50+
DecorationNodeParser,
5051
StrongImageNodeParser,
5152
StrongIconNodeParser,
5253
StrongNodeParser,
53-
DecorationNodeParser,
5454
ImageNodeParser,
5555
ExternalLinkNodeParser,
5656
IconNodeParser,

tests/line/__snapshots__/decoration.test.ts.snap

Lines changed: 109 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,22 @@ Array [
5858
"indent": 0,
5959
"nodes": Array [
6060
Object {
61-
"text": "[! ",
62-
"type": "plain",
63-
},
64-
Object {
61+
"decos": Array [
62+
"!",
63+
],
6564
"nodes": Array [
6665
Object {
67-
"text": "[[[[a",
66+
"text": "[[[[[",
6867
"type": "plain",
6968
},
69+
Object {
70+
"content": "",
71+
"href": "a",
72+
"pathType": "relative",
73+
"type": "link",
74+
},
7075
],
71-
"type": "strong",
76+
"type": "decoration",
7277
},
7378
],
7479
"type": "line",
@@ -99,6 +104,104 @@ Array [
99104
]
100105
`;
101106

107+
exports[`decoration Decoration with strong icon notation (it's just icon, not strong): toMatchSnapshotWhenParsing 1`] = `
108+
Array [
109+
Object {
110+
"indent": 0,
111+
"nodes": Array [
112+
Object {
113+
"decos": Array [
114+
"*-1",
115+
],
116+
"nodes": Array [
117+
Object {
118+
"text": "[",
119+
"type": "plain",
120+
},
121+
Object {
122+
"content": "",
123+
"href": "progfay.icon",
124+
"pathType": "relative",
125+
"type": "link",
126+
},
127+
],
128+
"type": "decoration",
129+
},
130+
Object {
131+
"text": "]",
132+
"type": "plain",
133+
},
134+
],
135+
"type": "line",
136+
},
137+
]
138+
`;
139+
140+
exports[`decoration Decoration with strong image notation (it's just image, not strong): toMatchSnapshotWhenParsing 1`] = `
141+
Array [
142+
Object {
143+
"indent": 0,
144+
"nodes": Array [
145+
Object {
146+
"decos": Array [
147+
"*-1",
148+
],
149+
"nodes": Array [
150+
Object {
151+
"text": "[",
152+
"type": "plain",
153+
},
154+
Object {
155+
"link": "",
156+
"src": "https://example.com/image.png",
157+
"type": "image",
158+
},
159+
],
160+
"type": "decoration",
161+
},
162+
Object {
163+
"text": "]",
164+
"type": "plain",
165+
},
166+
],
167+
"type": "line",
168+
},
169+
]
170+
`;
171+
172+
exports[`decoration Decoration with strong notation (it's just link): toMatchSnapshotWhenParsing 1`] = `
173+
Array [
174+
Object {
175+
"indent": 0,
176+
"nodes": Array [
177+
Object {
178+
"decos": Array [
179+
"*-1",
180+
],
181+
"nodes": Array [
182+
Object {
183+
"text": "[",
184+
"type": "plain",
185+
},
186+
Object {
187+
"content": "",
188+
"href": "link",
189+
"pathType": "relative",
190+
"type": "link",
191+
},
192+
],
193+
"type": "decoration",
194+
},
195+
Object {
196+
"text": "]",
197+
"type": "plain",
198+
},
199+
],
200+
"type": "line",
201+
},
202+
]
203+
`;
204+
102205
exports[`decoration Simple decoration: toMatchSnapshotWhenParsing 1`] = `
103206
Array [
104207
Object {

tests/line/__snapshots__/strong.test.ts.snap

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,37 @@ Array [
1515
]
1616
`;
1717

18+
exports[`strong Decoration in Strong notation: toMatchSnapshotWhenParsing 1`] = `
19+
Array [
20+
Object {
21+
"indent": 0,
22+
"nodes": Array [
23+
Object {
24+
"text": "[[",
25+
"type": "plain",
26+
},
27+
Object {
28+
"decos": Array [
29+
"!",
30+
],
31+
"nodes": Array [
32+
Object {
33+
"text": "deco",
34+
"type": "plain",
35+
},
36+
],
37+
"type": "decoration",
38+
},
39+
Object {
40+
"text": "]]",
41+
"type": "plain",
42+
},
43+
],
44+
"type": "line",
45+
},
46+
]
47+
`;
48+
1849
exports[`strong Simple strong: toMatchSnapshotWhenParsing 1`] = `
1950
Array [
2051
Object {

tests/line/decoration.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,16 @@ describe('decoration', () => {
8181
it('Decoration with many [ and link', () => {
8282
expect('[! [[[[[[a]]').toMatchSnapshotWhenParsing({ hasTitle: false })
8383
})
84+
85+
it("Decoration with strong notation (it's just link)", () => {
86+
expect('[* [[link]]]').toMatchSnapshotWhenParsing({ hasTitle: false })
87+
})
88+
89+
it("Decoration with strong icon notation (it's just icon, not strong)", () => {
90+
expect('[* [[progfay.icon]]]').toMatchSnapshotWhenParsing({ hasTitle: false })
91+
})
92+
93+
it("Decoration with strong image notation (it's just image, not strong)", () => {
94+
expect('[* [[https://example.com/image.png]]]').toMatchSnapshotWhenParsing({ hasTitle: false })
95+
})
8496
})

tests/line/strong.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,8 @@ describe('strong', () => {
66
it('[[]] is not strong', () => {
77
expect('[[]]').toMatchSnapshotWhenParsing({ hasTitle: false })
88
})
9+
10+
it('Decoration in Strong notation', () => {
11+
expect('[[[! deco]]]').toMatchSnapshotWhenParsing({ hasTitle: false })
12+
})
913
})

0 commit comments

Comments
 (0)