Skip to content

Commit 5baf876

Browse files
authored
Merge pull request #538 from progfay/fix-parsing-deco-strong-complex
2 parents 6fe5e37 + dacb41f commit 5baf876

File tree

5 files changed

+181
-10
lines changed

5 files changed

+181
-10
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: 128 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,20 +65,26 @@ Array [
6565
"indent": 0,
6666
"nodes": Array [
6767
Object {
68-
"raw": "[! ",
69-
"text": "[! ",
70-
"type": "plain",
71-
},
72-
Object {
68+
"decos": Array [
69+
"!",
70+
],
7371
"nodes": Array [
7472
Object {
75-
"raw": "[[[[a",
76-
"text": "[[[[a",
73+
"raw": "[[[[[",
74+
"text": "[[[[[",
7775
"type": "plain",
7876
},
77+
Object {
78+
"content": "",
79+
"href": "a",
80+
"pathType": "relative",
81+
"raw": "[a]",
82+
"type": "link",
83+
},
7984
],
80-
"raw": "[[[[[[a]]",
81-
"type": "strong",
85+
"raw": "[! [[[[[[a]]",
86+
"rawDecos": "!",
87+
"type": "decoration",
8288
},
8389
],
8490
"type": "line",
@@ -112,6 +118,119 @@ Array [
112118
]
113119
`;
114120

121+
exports[`decoration Decoration with strong icon notation (it's just icon, not strong): toMatchSnapshotWhenParsing 1`] = `
122+
Array [
123+
Object {
124+
"indent": 0,
125+
"nodes": Array [
126+
Object {
127+
"decos": Array [
128+
"*-1",
129+
],
130+
"nodes": Array [
131+
Object {
132+
"raw": "[",
133+
"text": "[",
134+
"type": "plain",
135+
},
136+
Object {
137+
"content": "",
138+
"href": "progfay.icon",
139+
"pathType": "relative",
140+
"raw": "[progfay.icon]",
141+
"type": "link",
142+
},
143+
],
144+
"raw": "[* [[progfay.icon]]",
145+
"rawDecos": "*",
146+
"type": "decoration",
147+
},
148+
Object {
149+
"raw": "]",
150+
"text": "]",
151+
"type": "plain",
152+
},
153+
],
154+
"type": "line",
155+
},
156+
]
157+
`;
158+
159+
exports[`decoration Decoration with strong image notation (it's just image, not strong): toMatchSnapshotWhenParsing 1`] = `
160+
Array [
161+
Object {
162+
"indent": 0,
163+
"nodes": Array [
164+
Object {
165+
"decos": Array [
166+
"*-1",
167+
],
168+
"nodes": Array [
169+
Object {
170+
"raw": "[",
171+
"text": "[",
172+
"type": "plain",
173+
},
174+
Object {
175+
"link": "",
176+
"raw": "[https://example.com/image.png]",
177+
"src": "https://example.com/image.png",
178+
"type": "image",
179+
},
180+
],
181+
"raw": "[* [[https://example.com/image.png]]",
182+
"rawDecos": "*",
183+
"type": "decoration",
184+
},
185+
Object {
186+
"raw": "]",
187+
"text": "]",
188+
"type": "plain",
189+
},
190+
],
191+
"type": "line",
192+
},
193+
]
194+
`;
195+
196+
exports[`decoration Decoration with strong notation (it's just link): toMatchSnapshotWhenParsing 1`] = `
197+
Array [
198+
Object {
199+
"indent": 0,
200+
"nodes": Array [
201+
Object {
202+
"decos": Array [
203+
"*-1",
204+
],
205+
"nodes": Array [
206+
Object {
207+
"raw": "[",
208+
"text": "[",
209+
"type": "plain",
210+
},
211+
Object {
212+
"content": "",
213+
"href": "link",
214+
"pathType": "relative",
215+
"raw": "[link]",
216+
"type": "link",
217+
},
218+
],
219+
"raw": "[* [[link]]",
220+
"rawDecos": "*",
221+
"type": "decoration",
222+
},
223+
Object {
224+
"raw": "]",
225+
"text": "]",
226+
"type": "plain",
227+
},
228+
],
229+
"type": "line",
230+
},
231+
]
232+
`;
233+
115234
exports[`decoration Simple decoration: toMatchSnapshotWhenParsing 1`] = `
116235
Array [
117236
Object {

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,42 @@ Array [
1616
]
1717
`;
1818

19+
exports[`strong Decoration in Strong notation: toMatchSnapshotWhenParsing 1`] = `
20+
Array [
21+
Object {
22+
"indent": 0,
23+
"nodes": Array [
24+
Object {
25+
"raw": "[[",
26+
"text": "[[",
27+
"type": "plain",
28+
},
29+
Object {
30+
"decos": Array [
31+
"!",
32+
],
33+
"nodes": Array [
34+
Object {
35+
"raw": "deco",
36+
"text": "deco",
37+
"type": "plain",
38+
},
39+
],
40+
"raw": "[! deco]",
41+
"rawDecos": "!",
42+
"type": "decoration",
43+
},
44+
Object {
45+
"raw": "]]",
46+
"text": "]]",
47+
"type": "plain",
48+
},
49+
],
50+
"type": "line",
51+
},
52+
]
53+
`;
54+
1955
exports[`strong Simple strong: toMatchSnapshotWhenParsing 1`] = `
2056
Array [
2157
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)