@markdoc/markdoc 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +13 -8
- package/dist/index.js.map +2 -2
- package/dist/index.mjs +13 -8
- package/dist/index.mjs.map +2 -2
- package/dist/src/formatter.d.ts.map +1 -1
- package/package.json +7 -3
- package/src/formatter.test.ts +43 -20
- package/src/formatter.ts +23 -11
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatter.d.ts","sourceRoot":"","sources":["../../src/formatter.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAA4B,IAAI,EAAE,KAAK,EAAY,MAAM,SAAS,CAAC;AAE/E,aAAK,OAAO,GAAG;IACb,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,MAAM,CAAC,EAAE,IAAI,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;
|
|
1
|
+
{"version":3,"file":"formatter.d.ts","sourceRoot":"","sources":["../../src/formatter.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAA4B,IAAI,EAAE,KAAK,EAAY,MAAM,SAAS,CAAC;AAE/E,aAAK,OAAO,GAAG;IACb,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,MAAM,CAAC,EAAE,IAAI,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAubF,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,MAAM,CAIlE"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@markdoc/markdoc",
|
|
3
3
|
"author": "Ryan Paul",
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.2",
|
|
5
5
|
"description": "A text markup language for documentation",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"module": "dist/index.mjs",
|
|
@@ -40,8 +40,12 @@
|
|
|
40
40
|
"react": "*"
|
|
41
41
|
},
|
|
42
42
|
"peerDependenciesMeta": {
|
|
43
|
-
"@types/react": {
|
|
44
|
-
|
|
43
|
+
"@types/react": {
|
|
44
|
+
"optional": true
|
|
45
|
+
},
|
|
46
|
+
"react": {
|
|
47
|
+
"optional": true
|
|
48
|
+
}
|
|
45
49
|
},
|
|
46
50
|
"devDependencies": {
|
|
47
51
|
"@types/jasmine": "^3.10.2",
|
package/src/formatter.test.ts
CHANGED
|
@@ -21,7 +21,7 @@ Markdoc is a **Markdown**-based \`syntax\` and _toolchain_ for creating ~~custom
|
|
|
21
21
|
[Link](/href "title")
|
|
22
22
|

|
|
23
23
|
|
|
24
|
-
{% callout #id .class .class2 a="check" b={"e":{"with space": 5}} c=8 d=[1, "2",true] %}
|
|
24
|
+
{% callout #id .class .class2 a="check" b={"e":{"with space": 5}} c=8 d=[1, "2",true, null] %}
|
|
25
25
|
Markdoc is open-source—check out it's [source](http://github.com/markdoc/markdoc) to see how it works.
|
|
26
26
|
{% /callout %}
|
|
27
27
|
|
|
@@ -61,7 +61,7 @@ Markdoc is a **Markdown**-based \`syntax\` and _toolchain_ for creating ~~custom
|
|
|
61
61
|
a="check"
|
|
62
62
|
b={e: {"with space": 5}}
|
|
63
63
|
c=8
|
|
64
|
-
d=[1, "2", true] %}
|
|
64
|
+
d=[1, "2", true, null] %}
|
|
65
65
|
Markdoc is open-source—check out it's [source](http://github.com/markdoc/markdoc) to see how it works.
|
|
66
66
|
{% /callout %}
|
|
67
67
|
|
|
@@ -139,7 +139,15 @@ subtitle: Subtitle
|
|
|
139
139
|
|
|
140
140
|
it('escape markdown content', () => {
|
|
141
141
|
const source = `
|
|
142
|
-
|
|
142
|
+
regular_word_with_underscores
|
|
143
|
+
|
|
144
|
+
\\* List item
|
|
145
|
+
|
|
146
|
+
\\> Blockquote
|
|
147
|
+
|
|
148
|
+
\\# Heading
|
|
149
|
+
|
|
150
|
+
\\### Heading
|
|
143
151
|
|
|
144
152
|
**/docs/\\***
|
|
145
153
|
|
|
@@ -616,6 +624,23 @@ Yes!
|
|
|
616
624
|
stable(expected);
|
|
617
625
|
});
|
|
618
626
|
|
|
627
|
+
it('lists with complex items', () => {
|
|
628
|
+
const source = `
|
|
629
|
+
* **One {% colspan=1 %}**
|
|
630
|
+
* **Two {% colspan=2 %}**
|
|
631
|
+
* **Three {% colspan=3 %}**
|
|
632
|
+
`;
|
|
633
|
+
|
|
634
|
+
const expected = `
|
|
635
|
+
- **One**{% colspan=1 %}
|
|
636
|
+
- **Two**{% colspan=2 %}
|
|
637
|
+
- **Three**{% colspan=3 %}
|
|
638
|
+
`;
|
|
639
|
+
|
|
640
|
+
check(source, expected);
|
|
641
|
+
stable(expected);
|
|
642
|
+
});
|
|
643
|
+
|
|
619
644
|
it('fences with block level tags', () => {
|
|
620
645
|
const source = `{% tab %}
|
|
621
646
|
\`\`\`json {% filename="package.json" %}
|
|
@@ -654,23 +679,6 @@ Package.json
|
|
|
654
679
|
check(source, expected);
|
|
655
680
|
});
|
|
656
681
|
|
|
657
|
-
it('complex lists', () => {
|
|
658
|
-
const source = `
|
|
659
|
-
* **One {% colspan=1 %}**
|
|
660
|
-
* **Two {% colspan=2 %}**
|
|
661
|
-
* **Three {% colspan=3 %}**
|
|
662
|
-
`;
|
|
663
|
-
|
|
664
|
-
const expected = `
|
|
665
|
-
- **One**{% colspan=1 %}
|
|
666
|
-
- **Two**{% colspan=2 %}
|
|
667
|
-
- **Three**{% colspan=3 %}
|
|
668
|
-
`;
|
|
669
|
-
|
|
670
|
-
check(source, expected);
|
|
671
|
-
stable(expected);
|
|
672
|
-
});
|
|
673
|
-
|
|
674
682
|
it('nested fences', () => {
|
|
675
683
|
const source = `
|
|
676
684
|
${'`'.repeat(4)}
|
|
@@ -685,4 +693,19 @@ ${'`'.repeat(4)}
|
|
|
685
693
|
|
|
686
694
|
stable(source);
|
|
687
695
|
});
|
|
696
|
+
it('multi-paragraph blockquotes', () => {
|
|
697
|
+
const source = `
|
|
698
|
+
> Blockquote {% .class %}
|
|
699
|
+
>
|
|
700
|
+
> with two paragraphs`;
|
|
701
|
+
|
|
702
|
+
const expected = `
|
|
703
|
+
> Blockquote {% .class %}
|
|
704
|
+
>
|
|
705
|
+
> with two paragraphs
|
|
706
|
+
`;
|
|
707
|
+
|
|
708
|
+
check(source, expected);
|
|
709
|
+
stable(expected);
|
|
710
|
+
});
|
|
688
711
|
});
|
package/src/formatter.ts
CHANGED
|
@@ -17,6 +17,8 @@ const UL = '- '; // Unordered list
|
|
|
17
17
|
|
|
18
18
|
const MAX_TAG_OPENING_WIDTH = 80;
|
|
19
19
|
|
|
20
|
+
const WRAPPING_TYPES = ['strong', 'em', 's'];
|
|
21
|
+
|
|
20
22
|
const max = (a: number, b: number) => Math.max(a, b);
|
|
21
23
|
const increment = (o: Options, n = 2) => ({
|
|
22
24
|
...o,
|
|
@@ -42,7 +44,7 @@ function formatScalar(v: Value): string {
|
|
|
42
44
|
return format(v);
|
|
43
45
|
}
|
|
44
46
|
if (v === null) {
|
|
45
|
-
return '';
|
|
47
|
+
return 'null';
|
|
46
48
|
}
|
|
47
49
|
if (Array.isArray(v)) {
|
|
48
50
|
return '[' + v.map(formatScalar).join(SEP) + ']';
|
|
@@ -195,18 +197,29 @@ function* formatNode(n: Node, o: Options = {}) {
|
|
|
195
197
|
}
|
|
196
198
|
case 'text': {
|
|
197
199
|
const { content } = n.attributes;
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
200
|
+
|
|
201
|
+
if (Ast.isAst(content)) {
|
|
202
|
+
yield OPEN + SPACE;
|
|
203
|
+
yield* formatValue(content, no);
|
|
204
|
+
yield SPACE + CLOSE;
|
|
205
|
+
} else {
|
|
206
|
+
if (o.parent && WRAPPING_TYPES.includes(o.parent.type)) {
|
|
207
|
+
// Escape **strong**, _em_, and ~~s~~
|
|
208
|
+
yield* escapeMarkdownCharacters(content, /[*_~]/g);
|
|
209
|
+
} else {
|
|
210
|
+
// Escape > blockquote, * list item, and heading
|
|
211
|
+
yield* escapeMarkdownCharacters(content, /^[*>#]/);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
203
215
|
break;
|
|
204
216
|
}
|
|
205
217
|
case 'blockquote': {
|
|
206
|
-
|
|
207
|
-
yield
|
|
208
|
-
|
|
209
|
-
|
|
218
|
+
const prefix = '>' + SPACE;
|
|
219
|
+
yield n.children
|
|
220
|
+
.map((child) => format(child, no).trimStart())
|
|
221
|
+
.map((d) => NL + indent + prefix + d)
|
|
222
|
+
.join(indent + prefix);
|
|
210
223
|
break;
|
|
211
224
|
}
|
|
212
225
|
case 'hr': {
|
|
@@ -234,7 +247,6 @@ function* formatNode(n: Node, o: Options = {}) {
|
|
|
234
247
|
yield* formatAnnotations(n);
|
|
235
248
|
yield NL;
|
|
236
249
|
yield indent;
|
|
237
|
-
// TODO use formatChildren once we can differentiate inline from block tags within fences
|
|
238
250
|
yield n.attributes.content.split(NL).join(NL + indent); // yield* formatChildren(n, no);
|
|
239
251
|
yield boundary;
|
|
240
252
|
yield NL;
|