Skip to content

Commit c25661a

Browse files
committed
fix(stringify): do not add indent empty lines
1 parent 22c531e commit c25661a

File tree

8 files changed

+2117
-1
lines changed

8 files changed

+2117
-1
lines changed

src/to-markdown.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ export default (opts: RemarkMDCOptions = {}) => {
176176
if (nest > 1) {
177177
value = value
178178
.split('\n')
179-
.map(line => ' ' + line)
179+
.map(line => line.length > 0 ? ' ' + line : line)
180180
.join('\n')
181181
}
182182
}

test/__snapshots__/block-component.test.ts.snap

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1626,6 +1626,159 @@ array:
16261626
}
16271627
`;
16281628

1629+
exports[`block-component > nested-empty-line 1`] = `
1630+
{
1631+
"children": [
1632+
{
1633+
"attributes": {
1634+
"padding": "0px",
1635+
},
1636+
"children": [
1637+
{
1638+
"attributes": {},
1639+
"children": [
1640+
{
1641+
"children": [
1642+
{
1643+
"position": {
1644+
"end": {
1645+
"column": 35,
1646+
"line": 13,
1647+
"offset": 202,
1648+
},
1649+
"start": {
1650+
"column": 3,
1651+
"line": 13,
1652+
"offset": 170,
1653+
},
1654+
},
1655+
"type": "text",
1656+
"value": "This container has a code block.",
1657+
},
1658+
],
1659+
"position": {
1660+
"end": {
1661+
"column": 35,
1662+
"line": 13,
1663+
"offset": 202,
1664+
},
1665+
"start": {
1666+
"column": 3,
1667+
"line": 13,
1668+
"offset": 170,
1669+
},
1670+
},
1671+
"type": "paragraph",
1672+
},
1673+
{
1674+
"lang": "js",
1675+
"meta": null,
1676+
"position": {
1677+
"end": {
1678+
"column": 6,
1679+
"line": 19,
1680+
"offset": 266,
1681+
},
1682+
"start": {
1683+
"column": 3,
1684+
"line": 15,
1685+
"offset": 206,
1686+
},
1687+
},
1688+
"type": "code",
1689+
"value": "function test() {
1690+
console.log("test");
1691+
}",
1692+
},
1693+
],
1694+
"data": {
1695+
"hName": "container",
1696+
"hProperties": {
1697+
"styles": "pre {
1698+
border: 1px solid red !important;
1699+
1700+
span {
1701+
line-height: 1;
1702+
}
1703+
}
1704+
",
1705+
},
1706+
},
1707+
"fmAttributes": {
1708+
"styles": "pre {
1709+
border: 1px solid red !important;
1710+
1711+
span {
1712+
line-height: 1;
1713+
}
1714+
}
1715+
",
1716+
},
1717+
"name": "container",
1718+
"position": {
1719+
"end": {
1720+
"column": 6,
1721+
"line": 20,
1722+
"offset": 272,
1723+
},
1724+
"start": {
1725+
"column": 3,
1726+
"line": 2,
1727+
"offset": 29,
1728+
},
1729+
},
1730+
"rawData": "
1731+
styles: |
1732+
pre {
1733+
border: 1px solid red !important;
1734+
1735+
span {
1736+
line-height: 1;
1737+
}
1738+
}
1739+
---",
1740+
"type": "containerComponent",
1741+
},
1742+
],
1743+
"data": {
1744+
"hName": "container",
1745+
"hProperties": {
1746+
"padding": "0px",
1747+
},
1748+
},
1749+
"fmAttributes": {},
1750+
"name": "container",
1751+
"position": {
1752+
"end": {
1753+
"column": 3,
1754+
"line": 21,
1755+
"offset": 275,
1756+
},
1757+
"start": {
1758+
"column": 1,
1759+
"line": 1,
1760+
"offset": 0,
1761+
},
1762+
},
1763+
"type": "containerComponent",
1764+
},
1765+
],
1766+
"position": {
1767+
"end": {
1768+
"column": 3,
1769+
"line": 21,
1770+
"offset": 275,
1771+
},
1772+
"start": {
1773+
"column": 1,
1774+
"line": 1,
1775+
"offset": 0,
1776+
},
1777+
},
1778+
"type": "root",
1779+
}
1780+
`;
1781+
16291782
exports[`block-component > paragraphWithComponents 1`] = `
16301783
{
16311784
"children": [

test/__snapshots__/inline-component.test.ts.snap

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,169 @@ exports[`inline-component > empty 1`] = `
206206
}
207207
`;
208208

209+
exports[`inline-component > kbd 1`] = `
210+
{
211+
"children": [
212+
{
213+
"attributes": {},
214+
"children": [
215+
{
216+
"children": [
217+
{
218+
"position": {
219+
"end": {
220+
"column": 31,
221+
"line": 2,
222+
"offset": 36,
223+
},
224+
"start": {
225+
"column": 1,
226+
"line": 2,
227+
"offset": 6,
228+
},
229+
},
230+
"type": "text",
231+
"value": "You can also use the shortcut ",
232+
},
233+
{
234+
"attributes": {
235+
"value": "meta",
236+
},
237+
"children": [],
238+
"data": {
239+
"hName": "kbd",
240+
"hProperties": {
241+
"value": "meta",
242+
},
243+
},
244+
"fmAttributes": {},
245+
"name": "kbd",
246+
"position": {
247+
"end": {
248+
"column": 49,
249+
"line": 2,
250+
"offset": 54,
251+
},
252+
"start": {
253+
"column": 31,
254+
"line": 2,
255+
"offset": 36,
256+
},
257+
},
258+
"type": "textComponent",
259+
},
260+
{
261+
"position": {
262+
"end": {
263+
"column": 52,
264+
"line": 2,
265+
"offset": 57,
266+
},
267+
"start": {
268+
"column": 49,
269+
"line": 2,
270+
"offset": 54,
271+
},
272+
},
273+
"type": "text",
274+
"value": " + ",
275+
},
276+
{
277+
"attributes": {
278+
"value": ".",
279+
},
280+
"children": [],
281+
"data": {
282+
"hName": "kbd",
283+
"hProperties": {
284+
"value": ".",
285+
},
286+
},
287+
"fmAttributes": {},
288+
"name": "kbd",
289+
"position": {
290+
"end": {
291+
"column": 67,
292+
"line": 2,
293+
"offset": 72,
294+
},
295+
"start": {
296+
"column": 52,
297+
"line": 2,
298+
"offset": 57,
299+
},
300+
},
301+
"type": "textComponent",
302+
},
303+
{
304+
"position": {
305+
"end": {
306+
"column": 100,
307+
"line": 2,
308+
"offset": 105,
309+
},
310+
"start": {
311+
"column": 67,
312+
"line": 2,
313+
"offset": 72,
314+
},
315+
},
316+
"type": "text",
317+
"value": " to redirect to the Studio route.",
318+
},
319+
],
320+
"position": {
321+
"end": {
322+
"column": 100,
323+
"line": 2,
324+
"offset": 105,
325+
},
326+
"start": {
327+
"column": 1,
328+
"line": 2,
329+
"offset": 6,
330+
},
331+
},
332+
"type": "paragraph",
333+
},
334+
],
335+
"data": {
336+
"hName": "tip",
337+
"hProperties": {},
338+
},
339+
"fmAttributes": {},
340+
"name": "tip",
341+
"position": {
342+
"end": {
343+
"column": 3,
344+
"line": 3,
345+
"offset": 108,
346+
},
347+
"start": {
348+
"column": 1,
349+
"line": 1,
350+
"offset": 0,
351+
},
352+
},
353+
"type": "containerComponent",
354+
},
355+
],
356+
"position": {
357+
"end": {
358+
"column": 3,
359+
"line": 3,
360+
"offset": 108,
361+
},
362+
"start": {
363+
"column": 1,
364+
"line": 1,
365+
"offset": 0,
366+
},
367+
},
368+
"type": "root",
369+
}
370+
`;
371+
209372
exports[`inline-component > parentheses 1`] = `
210373
{
211374
"children": [

0 commit comments

Comments
 (0)