@markdoc/markdoc 0.1.12 → 0.2.0
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/README.md +9 -7
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +83 -53
- package/dist/index.js.map +3 -3
- package/dist/index.mjs +83 -53
- package/dist/index.mjs.map +3 -3
- package/dist/react.js +16 -5
- package/dist/react.js.map +3 -3
- package/dist/src/formatter.d.ts.map +1 -1
- package/dist/src/parser.d.ts.map +1 -1
- package/dist/src/renderers/html.d.ts.map +1 -1
- package/dist/src/renderers/react/react.d.ts +1 -1
- package/dist/src/renderers/react/react.d.ts.map +1 -1
- package/dist/src/renderers/react/static.d.ts +1 -1
- package/dist/src/renderers/react/static.d.ts.map +1 -1
- package/dist/src/schema-types/id.d.ts +5 -0
- package/dist/src/schema-types/id.d.ts.map +1 -0
- package/dist/src/tag.d.ts +1 -0
- package/dist/src/tag.d.ts.map +1 -1
- package/dist/src/tags/conditional.d.ts +1 -1
- package/dist/src/tags/conditional.d.ts.map +1 -1
- package/dist/src/tags/partial.d.ts.map +1 -1
- package/dist/src/tags/table.d.ts.map +1 -1
- package/dist/src/transformer.d.ts.map +1 -1
- package/dist/src/types.d.ts +2 -1
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/utils.d.ts +1 -1
- package/dist/src/utils.d.ts.map +1 -1
- package/dist/src/validator.d.ts.map +1 -1
- package/index.ts +3 -3
- package/package.json +10 -3
- package/src/formatter.test.ts +109 -6
- package/src/formatter.ts +51 -27
- package/src/parser.ts +2 -1
- package/src/renderers/html.test.ts +17 -6
- package/src/renderers/html.ts +4 -2
- package/src/renderers/react/react.test.ts +5 -12
- package/src/renderers/react/react.ts +21 -4
- package/src/renderers/react/static.ts +21 -3
- package/src/schema-types/id.ts +15 -0
- package/src/tag.ts +4 -0
- package/src/tags/conditional.ts +11 -2
- package/src/tags/partial.ts +1 -0
- package/src/tags/table.ts +1 -0
- package/src/transformer.ts +14 -3
- package/src/types.ts +2 -1
- package/src/utils.ts +2 -2
- package/src/validator.test.ts +67 -0
- package/src/validator.ts +9 -6
- package/dist/src/renderers/react/shared.d.ts +0 -5
- package/dist/src/renderers/react/shared.d.ts.map +0 -1
- package/src/renderers/react/shared.ts +0 -16
package/dist/react.js
CHANGED
|
@@ -1,9 +1,20 @@
|
|
|
1
|
-
// src/
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
// src/tag.ts
|
|
2
|
+
var Tag = class {
|
|
3
|
+
constructor(name = "div", attributes = {}, children = []) {
|
|
4
|
+
this.$$mdtype = "Tag";
|
|
5
|
+
this.name = name;
|
|
6
|
+
this.attributes = attributes;
|
|
7
|
+
this.children = children;
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
Tag.isTag = (tag) => {
|
|
11
|
+
return "$$mdtype" in tag && tag.$$mdtype === "Tag";
|
|
12
|
+
};
|
|
5
13
|
|
|
6
14
|
// src/renderers/react/react.ts
|
|
15
|
+
function tagName(name, components) {
|
|
16
|
+
return typeof name !== "string" ? name : name[0] !== name[0].toUpperCase() ? name : components instanceof Function ? components(name) : components[name];
|
|
17
|
+
}
|
|
7
18
|
function dynamic(node, React, { components = {} } = {}) {
|
|
8
19
|
function deepRender(value) {
|
|
9
20
|
if (value == null || typeof value !== "object")
|
|
@@ -22,7 +33,7 @@ function dynamic(node, React, { components = {} } = {}) {
|
|
|
22
33
|
function render(node2) {
|
|
23
34
|
if (Array.isArray(node2))
|
|
24
35
|
return React.createElement(React.Fragment, null, ...node2.map(render));
|
|
25
|
-
if (node2 === null || typeof node2 !== "object")
|
|
36
|
+
if (node2 === null || typeof node2 !== "object" || !Tag.isTag(node2))
|
|
26
37
|
return node2;
|
|
27
38
|
const {
|
|
28
39
|
name,
|
package/dist/react.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../src/
|
|
4
|
-
"sourcesContent": ["import type {
|
|
5
|
-
"mappings": ";
|
|
3
|
+
"sources": ["../src/tag.ts", "../src/renderers/react/react.ts"],
|
|
4
|
+
"sourcesContent": ["import type { RenderableTreeNode } from './types';\n\nexport default class Tag<\n N extends string = string,\n A extends Record<string, any> = Record<string, any>\n> {\n readonly $$mdtype = 'Tag' as const;\n\n static isTag = (tag: any): tag is Tag => {\n return '$$mdtype' in tag && tag.$$mdtype === 'Tag';\n };\n\n name: N;\n attributes: A;\n children: RenderableTreeNode[];\n\n constructor(\n name = 'div' as N,\n attributes = {} as A,\n children: RenderableTreeNode[] = []\n ) {\n this.name = name;\n this.attributes = attributes;\n this.children = children;\n }\n}\n", "import Tag from '../../tag';\nimport { RenderableTreeNodes, Scalar } from '../../types';\n\nimport type { createElement, ComponentType, Fragment, ReactNode } from 'react';\n\ntype ReactShape = Readonly<{\n createElement: typeof createElement;\n Fragment: typeof Fragment;\n}>;\n\ntype Component = ComponentType<unknown>;\n\nfunction tagName(\n name: string,\n components: Record<string, Component> | ((string: string) => Component)\n): string | Component {\n return typeof name !== 'string'\n ? name // This can be an object, e.g. when React.forwardRef is used\n : name[0] !== name[0].toUpperCase()\n ? name\n : components instanceof Function\n ? components(name)\n : components[name];\n}\n\nexport default function dynamic(\n node: RenderableTreeNodes,\n React: ReactShape,\n { components = {} } = {}\n) {\n function deepRender(value: any): any {\n if (value == null || typeof value !== 'object') return value;\n\n if (Array.isArray(value)) return value.map((item) => deepRender(item));\n\n if (value.$$mdtype === 'Tag') return render(value);\n\n if (typeof value !== 'object') return value;\n\n const output: Record<string, Scalar> = {};\n for (const [k, v] of Object.entries(value)) output[k] = deepRender(v);\n return output;\n }\n\n function render(node: RenderableTreeNodes): ReactNode {\n if (Array.isArray(node))\n return React.createElement(React.Fragment, null, ...node.map(render));\n\n if (node === null || typeof node !== 'object' || !Tag.isTag(node))\n return node;\n\n const {\n name,\n attributes: { class: className, ...attrs } = {},\n children = [],\n } = node;\n\n if (className) attrs.className = className;\n\n return React.createElement(\n tagName(name, components),\n Object.keys(attrs).length == 0 ? null : deepRender(attrs),\n ...children.map(render)\n );\n }\n\n return render(node);\n}\n"],
|
|
5
|
+
"mappings": ";AAEA,gBAGE;AAAA,EAWA,YACE,OAAO,OACP,aAAa,IACb,WAAiC,IACjC;AAdO,oBAAW;AAelB,SAAK,OAAO;AACZ,SAAK,aAAa;AAClB,SAAK,WAAW;AAAA;AAAA;AAfX,AANT,IAMS,QAAQ,CAAC,QAAyB;AACvC,SAAO,cAAc,OAAO,IAAI,aAAa;AAAA;;;ACGjD,iBACE,MACA,YACoB;AACpB,SAAO,OAAO,SAAS,WACnB,OACA,KAAK,OAAO,KAAK,GAAG,gBACpB,OACA,sBAAsB,WACtB,WAAW,QACX,WAAW;AAAA;AAGF,iBACb,MACA,OACA,EAAE,aAAa,OAAO,IACtB;AACA,sBAAoB,OAAiB;AACnC,QAAI,SAAS,QAAQ,OAAO,UAAU;AAAU,aAAO;AAEvD,QAAI,MAAM,QAAQ;AAAQ,aAAO,MAAM,IAAI,CAAC,SAAS,WAAW;AAEhE,QAAI,MAAM,aAAa;AAAO,aAAO,OAAO;AAE5C,QAAI,OAAO,UAAU;AAAU,aAAO;AAEtC,UAAM,SAAiC;AACvC,eAAW,CAAC,GAAG,MAAM,OAAO,QAAQ;AAAQ,aAAO,KAAK,WAAW;AACnE,WAAO;AAAA;AAGT,kBAAgB,OAAsC;AACpD,QAAI,MAAM,QAAQ;AAChB,aAAO,MAAM,cAAc,MAAM,UAAU,MAAM,GAAG,MAAK,IAAI;AAE/D,QAAI,UAAS,QAAQ,OAAO,UAAS,YAAY,CAAC,IAAI,MAAM;AAC1D,aAAO;AAET,UAAM;AAAA,MACJ;AAAA,MACA,YAAY,EAAE,OAAO,cAAc,UAAU;AAAA,MAC7C,WAAW;AAAA,QACT;AAEJ,QAAI;AAAW,YAAM,YAAY;AAEjC,WAAO,MAAM,cACX,QAAQ,MAAM,aACd,OAAO,KAAK,OAAO,UAAU,IAAI,OAAO,WAAW,QACnD,GAAG,SAAS,IAAI;AAAA;AAIpB,SAAO,OAAO;AAAA;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -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;AA2aF,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,MAAM,CAIlE"}
|
package/dist/src/parser.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../../src/parser.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../../src/parser.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,YAAY,CAAC;AAM9B,OAAO,KAAK,KAAK,MAAM,uBAAuB,CAAC;AAsK/C,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,IAAI,CAAC,EAAE,MAAM,QAiB5D"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"html.d.ts","sourceRoot":"","sources":["../../../src/renderers/html.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"html.d.ts","sourceRoot":"","sources":["../../../src/renderers/html.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAsBpD,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,IAAI,EAAE,mBAAmB,GAAG,MAAM,CAuBhE"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { RenderableTreeNodes } from '../../types';
|
|
1
2
|
import type { createElement, Fragment, ReactNode } from 'react';
|
|
2
|
-
import type { RenderableTreeNodes } from '../../types';
|
|
3
3
|
declare type ReactShape = Readonly<{
|
|
4
4
|
createElement: typeof createElement;
|
|
5
5
|
Fragment: typeof Fragment;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react.d.ts","sourceRoot":"","sources":["../../../../src/renderers/react/react.ts"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"react.d.ts","sourceRoot":"","sources":["../../../../src/renderers/react/react.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAU,MAAM,aAAa,CAAC;AAE1D,OAAO,KAAK,EAAE,aAAa,EAAiB,QAAQ,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAE/E,aAAK,UAAU,GAAG,QAAQ,CAAC;IACzB,aAAa,EAAE,OAAO,aAAa,CAAC;IACpC,QAAQ,EAAE,OAAO,QAAQ,CAAC;CAC3B,CAAC,CAAC;AAiBH,MAAM,CAAC,OAAO,UAAU,OAAO,CAC7B,IAAI,EAAE,mBAAmB,EACzB,KAAK,EAAE,UAAU,EACjB,EAAE,UAAe,EAAE;;CAAK,aAuCzB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"static.d.ts","sourceRoot":"","sources":["../../../../src/renderers/react/static.ts"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"static.d.ts","sourceRoot":"","sources":["../../../../src/renderers/react/static.ts"],"names":[],"mappings":"AACA,OAAO,EAAsB,mBAAmB,EAAE,MAAM,aAAa,CAAC;AA6DtE,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,IAAI,EAAE,mBAAmB,GAAG,MAAM,CAOrE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"id.d.ts","sourceRoot":"","sources":["../../../src/schema-types/id.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,4BAA4B,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAE9E,qBAAa,EAAG,YAAW,4BAA4B;IACrD,QAAQ,CAAC,KAAK,EAAE,GAAG,GAAG,eAAe,EAAE;CAWxC"}
|
package/dist/src/tag.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { RenderableTreeNode } from './types';
|
|
2
2
|
export default class Tag<N extends string = string, A extends Record<string, any> = Record<string, any>> {
|
|
3
3
|
readonly $$mdtype: "Tag";
|
|
4
|
+
static isTag: (tag: any) => tag is Tag<string, Record<string, any>>;
|
|
4
5
|
name: N;
|
|
5
6
|
attributes: A;
|
|
6
7
|
children: RenderableTreeNode[];
|
package/dist/src/tag.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tag.d.ts","sourceRoot":"","sources":["../../src/tag.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAElD,MAAM,CAAC,OAAO,OAAO,GAAG,CACtB,CAAC,SAAS,MAAM,GAAG,MAAM,EACzB,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;IAEnD,QAAQ,CAAC,QAAQ,QAAkB;IAEnC,IAAI,EAAE,CAAC,CAAC;IACR,UAAU,EAAE,CAAC,CAAC;IACd,QAAQ,EAAE,kBAAkB,EAAE,CAAC;gBAG7B,IAAI,IAAa,EACjB,UAAU,IAAU,EACpB,QAAQ,GAAE,kBAAkB,EAAO;CAMtC"}
|
|
1
|
+
{"version":3,"file":"tag.d.ts","sourceRoot":"","sources":["../../src/tag.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAElD,MAAM,CAAC,OAAO,OAAO,GAAG,CACtB,CAAC,SAAS,MAAM,GAAG,MAAM,EACzB,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;IAEnD,QAAQ,CAAC,QAAQ,QAAkB;IAEnC,MAAM,CAAC,KAAK,QAAS,GAAG,6CAEtB;IAEF,IAAI,EAAE,CAAC,CAAC;IACR,UAAU,EAAE,CAAC,CAAC;IACd,QAAQ,EAAE,kBAAkB,EAAE,CAAC;gBAG7B,IAAI,IAAa,EACjB,UAAU,IAAU,EACpB,QAAQ,GAAE,kBAAkB,EAAO;CAMtC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"conditional.d.ts","sourceRoot":"","sources":["../../../src/tags/conditional.ts"],"names":[],"mappings":"AAEA,OAAO,
|
|
1
|
+
{"version":3,"file":"conditional.d.ts","sourceRoot":"","sources":["../../../src/tags/conditional.ts"],"names":[],"mappings":"AAEA,OAAO,EAKL,MAAM,EAEP,MAAM,UAAU,CAAC;AAIlB,wBAAgB,MAAM,CAAC,KAAK,EAAE,GAAG,WAEhC;AAmBD,eAAO,MAAM,KAAK,EAAE,MAmBnB,CAAC;AAEF,eAAO,MAAM,OAAO,EAAE,MAKrB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"partial.d.ts","sourceRoot":"","sources":["../../../src/tags/partial.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAgB,MAAM,EAAmB,MAAM,UAAU,CAAC;AAoBtE,eAAO,MAAM,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"partial.d.ts","sourceRoot":"","sources":["../../../src/tags/partial.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAgB,MAAM,EAAmB,MAAM,UAAU,CAAC;AAoBtE,eAAO,MAAM,OAAO,EAAE,MA8BrB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"table.d.ts","sourceRoot":"","sources":["../../../src/tags/table.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAEvC,eAAO,MAAM,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"table.d.ts","sourceRoot":"","sources":["../../../src/tags/table.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAEvC,eAAO,MAAM,KAAK,EAAE,MAGnB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transformer.d.ts","sourceRoot":"","sources":["../../src/transformer.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"transformer.d.ts","sourceRoot":"","sources":["../../src/transformer.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAMV,MAAM,EACN,WAAW,EACZ,MAAM,SAAS,CAAC;AAEjB,aAAK,gBAAgB,GAAG,MAAM,CAAC,YAAY,CAAC,CAAC;AAE7C,eAAO,MAAM,gBAAgB,EAAE,gBAG9B,CAAC;;AAEF,wBA2DiB"}
|
package/dist/src/types.d.ts
CHANGED
|
@@ -51,7 +51,7 @@ export declare type LocationEdge = {
|
|
|
51
51
|
};
|
|
52
52
|
export declare type NodeType = 'blockquote' | 'code' | 'comment' | 'document' | 'em' | 'error' | 'fence' | 'hardbreak' | 'heading' | 'hr' | 'image' | 'inline' | 'item' | 'link' | 'list' | 'node' | 'paragraph' | 's' | 'softbreak' | 'strong' | 'table' | 'tag' | 'tbody' | 'td' | 'text' | 'th' | 'thead' | 'tr';
|
|
53
53
|
export declare type Primitive = null | boolean | number | string;
|
|
54
|
-
export declare type RenderableTreeNode = Tag |
|
|
54
|
+
export declare type RenderableTreeNode = Tag | Scalar;
|
|
55
55
|
export declare type RenderableTreeNodes = RenderableTreeNode | RenderableTreeNode[];
|
|
56
56
|
export declare type Scalar = Primitive | Scalar[] | {
|
|
57
57
|
[key: string]: Scalar;
|
|
@@ -61,6 +61,7 @@ export declare type Schema<C extends Config = Config, R = string> = {
|
|
|
61
61
|
children?: string[];
|
|
62
62
|
attributes?: Record<string, SchemaAttribute>;
|
|
63
63
|
selfClosing?: boolean;
|
|
64
|
+
inline?: boolean;
|
|
64
65
|
transform?(node: Node, config: C): MaybePromise<RenderableTreeNodes>;
|
|
65
66
|
validate?(node: Node, config: C): MaybePromise<ValidationError[]>;
|
|
66
67
|
};
|
package/dist/src/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,gBAAgB,CAAC;AACvC,OAAO,KAAK,IAAI,MAAM,YAAY,CAAC;AACnC,OAAO,KAAK,GAAG,MAAM,gBAAgB,CAAC;AACtC,OAAO,KAAK,GAAG,MAAM,OAAO,CAAC;AAE7B,YAAY,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC;AAC1B,MAAM,CAAC,OAAO,MAAM,QAAQ,GAAG,IAAI,CAAC;AACpC,MAAM,CAAC,OAAO,MAAM,QAAQ,GAAG,GAAG,CAAC;AAEnC,oBAAY,YAAY,CAAC,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;AAE7C,MAAM,WAAW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,CAAC,CAAC;IACpE,UAAU,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC5D,QAAQ,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,GAAG,kBAAkB,EAAE,CAAC;CAC5D;AAED,oBAAY,eAAe,GAAG;IAC5B,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,GAAG,OAAO,GAAG,UAAU,CAAC;IAC3D,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACrB,CAAC;AAEF,oBAAY,aAAa,GAAG;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,KAAK,EAAE,eAAe,CAAC;CACxB,CAAC;AAEF,oBAAY,cAAc,GACtB,mBAAmB,GACnB,OAAO,MAAM,GACb,OAAO,MAAM,GACb,OAAO,OAAO,GACd,OAAO,MAAM,GACb,OAAO,KAAK,GACZ,QAAQ,GACR,QAAQ,GACR,SAAS,GACT,QAAQ,GACR,OAAO,CAAC;AAEZ,oBAAY,KAAK,GAAG,OAAO,GAAG,MAAM,CAAC"}
|
package/dist/src/utils.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type Token from 'markdown-it/lib/token';
|
|
|
2
2
|
export declare const OPEN = "{%";
|
|
3
3
|
export declare const CLOSE = "%}";
|
|
4
4
|
export declare const IDENTIFIER_REGEX: RegExp;
|
|
5
|
-
export declare function isIdentifier(s:
|
|
5
|
+
export declare function isIdentifier(s: any): s is string;
|
|
6
6
|
export declare function isPromise(a: any): a is Promise<any>;
|
|
7
7
|
export declare function findTagEnd(content: string, start?: number): number | null;
|
|
8
8
|
export declare function parseTags(content: string, firstLine?: number): Token[];
|
package/dist/src/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,KAAK,MAAM,uBAAuB,CAAC;AAQ/C,eAAO,MAAM,IAAI,OAAO,CAAC;AACzB,eAAO,MAAM,KAAK,OAAO,CAAC;AAE1B,eAAO,MAAM,gBAAgB,QAAqB,CAAC;AAEnD,wBAAgB,YAAY,CAAC,CAAC,EAAE,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,KAAK,MAAM,uBAAuB,CAAC;AAQ/C,eAAO,MAAM,IAAI,OAAO,CAAC;AACzB,eAAO,MAAM,KAAK,OAAO,CAAC;AAE1B,eAAO,MAAM,gBAAgB,QAAqB,CAAC;AAEnD,wBAAgB,YAAY,CAAC,CAAC,EAAE,GAAG,GAAG,CAAC,IAAI,MAAM,CAEhD;AAED,wBAAgB,SAAS,CAAC,CAAC,EAAE,GAAG,GAAG,CAAC,IAAI,OAAO,CAAC,GAAG,CAAC,CAEnD;AAED,wBAAgB,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,SAAI,iBA0BpD;AAoBD,wBAAgB,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,SAAI,GAAG,KAAK,EAAE,CA+DjE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validator.d.ts","sourceRoot":"","sources":["../../src/validator.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,IAAI,EAEJ,MAAM,EACN,eAAe,EACf,eAAe,EACf,KAAK,EACN,MAAM,SAAS,CAAC;AAUjB,aAAK,SAAS,GAAG,WAAW,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC,CAAC;AAEtD,wBAAgB,YAAY,CAC1B,IAAI,EAAE,SAAS,EACf,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE,MAAM,GACb,OAAO,GAAG,eAAe,EAAE,CA2B7B;AAqED,MAAM,CAAC,OAAO,UAAU,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"validator.d.ts","sourceRoot":"","sources":["../../src/validator.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,IAAI,EAEJ,MAAM,EACN,eAAe,EACf,eAAe,EACf,KAAK,EACN,MAAM,SAAS,CAAC;AAUjB,aAAK,SAAS,GAAG,WAAW,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC,CAAC;AAEtD,wBAAgB,YAAY,CAC1B,IAAI,EAAE,SAAS,EACf,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE,MAAM,GACb,OAAO,GAAG,eAAe,EAAE,CA2B7B;AAqED,MAAM,CAAC,OAAO,UAAU,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,kDA2I3D"}
|
package/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import Ast from './src/ast';
|
|
2
|
-
import
|
|
2
|
+
import format from './src/formatter';
|
|
3
3
|
import functions from './src/functions';
|
|
4
4
|
import parser from './src/parser';
|
|
5
5
|
import * as nodes from './src/schema';
|
|
@@ -134,7 +134,7 @@ export {
|
|
|
134
134
|
transformer,
|
|
135
135
|
validator,
|
|
136
136
|
truthy,
|
|
137
|
-
|
|
137
|
+
format,
|
|
138
138
|
};
|
|
139
139
|
|
|
140
140
|
export default class Markdoc {
|
|
@@ -155,7 +155,7 @@ export default class Markdoc {
|
|
|
155
155
|
static validate = validate;
|
|
156
156
|
static createElement = createElement;
|
|
157
157
|
static truthy = truthy;
|
|
158
|
-
static
|
|
158
|
+
static format = format;
|
|
159
159
|
|
|
160
160
|
config;
|
|
161
161
|
constructor(config: Config) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@markdoc/markdoc",
|
|
3
3
|
"author": "Ryan Paul",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.2.0",
|
|
5
5
|
"description": "A text markup language for documentation",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"module": "dist/index.mjs",
|
|
@@ -32,9 +32,16 @@
|
|
|
32
32
|
"engines": {
|
|
33
33
|
"node": ">=14.7.0"
|
|
34
34
|
},
|
|
35
|
+
"optionalDependencies": {
|
|
36
|
+
"@types/markdown-it": "12.2.3"
|
|
37
|
+
},
|
|
35
38
|
"peerDependencies": {
|
|
36
|
-
"@types/
|
|
37
|
-
"
|
|
39
|
+
"@types/react": "*",
|
|
40
|
+
"react": "*"
|
|
41
|
+
},
|
|
42
|
+
"peerDependenciesMeta": {
|
|
43
|
+
"@types/react": {"optional": true},
|
|
44
|
+
"react": {"optional": true}
|
|
38
45
|
},
|
|
39
46
|
"devDependencies": {
|
|
40
47
|
"@types/jasmine": "^3.10.2",
|
package/src/formatter.test.ts
CHANGED
|
@@ -133,7 +133,38 @@ subtitle: Subtitle
|
|
|
133
133
|
---
|
|
134
134
|
|
|
135
135
|
`;
|
|
136
|
-
|
|
136
|
+
stable(source);
|
|
137
|
+
stable(source);
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
it('escape markdown content', () => {
|
|
141
|
+
const source = `
|
|
142
|
+
\\* Asterisk
|
|
143
|
+
|
|
144
|
+
**/docs/\\***
|
|
145
|
+
|
|
146
|
+
~~**a \\_sentence\\_ with \\_underscores**~~
|
|
147
|
+
|
|
148
|
+
- Item with [brackets]
|
|
149
|
+
|
|
150
|
+
\`\`\`
|
|
151
|
+
\\*\\_[\\[]
|
|
152
|
+
\`\`\`
|
|
153
|
+
|
|
154
|
+
{% table %}
|
|
155
|
+
- **[Link](https://example.com?q=()**
|
|
156
|
+
- **[Link](https://example.com?q=\\()**
|
|
157
|
+
- 
|
|
158
|
+
- 
|
|
159
|
+
{% /table %}
|
|
160
|
+
|
|
161
|
+
paragraph 1
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
paragraph 2
|
|
166
|
+
`;
|
|
167
|
+
|
|
137
168
|
stable(source);
|
|
138
169
|
});
|
|
139
170
|
|
|
@@ -164,7 +195,7 @@ subtitle: Subtitle
|
|
|
164
195
|
X
|
|
165
196
|
{% /if %}
|
|
166
197
|
{% $user.name %}
|
|
167
|
-
{% key x=$user.name
|
|
198
|
+
{% key x=$user.name y=$flag z=$array[5] /%}
|
|
168
199
|
`;
|
|
169
200
|
const expected = `
|
|
170
201
|
{% tag "complex primary" /%}
|
|
@@ -175,7 +206,7 @@ X
|
|
|
175
206
|
|
|
176
207
|
{% $user.name %}
|
|
177
208
|
|
|
178
|
-
{% key x=$user.name
|
|
209
|
+
{% key x=$user.name y=$flag z=$array[5] /%}
|
|
179
210
|
`;
|
|
180
211
|
|
|
181
212
|
check(source, expected);
|
|
@@ -248,11 +279,21 @@ Yes!
|
|
|
248
279
|
stable(expected);
|
|
249
280
|
});
|
|
250
281
|
|
|
282
|
+
it('long inline tags', () => {
|
|
283
|
+
const source = `{% button type="button" href="https://example.com/a-very-long-inline-tag" %}A very long inline tag{% /button %}
|
|
284
|
+
`;
|
|
285
|
+
stable(source);
|
|
286
|
+
|
|
287
|
+
const inlineParent = `### {% image src="/src" alt="A very long alt text to test if the tag wraps or not" /%}
|
|
288
|
+
`;
|
|
289
|
+
check(inlineParent, inlineParent);
|
|
290
|
+
});
|
|
291
|
+
|
|
251
292
|
it('long tags with maxTagOpeningWidth=Infinity', () => {
|
|
252
293
|
const source = `
|
|
253
294
|
{% tag a=true b="My very long text well over 80 characters in total" c=123456789 d=false /%}
|
|
254
295
|
`;
|
|
255
|
-
|
|
296
|
+
stable(source, { maxTagOpeningWidth: Infinity });
|
|
256
297
|
});
|
|
257
298
|
|
|
258
299
|
it('nested tags — allowIndentation: true', () => {
|
|
@@ -410,7 +451,6 @@ Yes!
|
|
|
410
451
|
\`\`\`
|
|
411
452
|
{% $code %}
|
|
412
453
|
\`\`\`
|
|
413
|
-
|
|
414
454
|
- Two
|
|
415
455
|
|
|
416
456
|
My second paragraph
|
|
@@ -448,6 +488,21 @@ Yes!
|
|
|
448
488
|
stable(expected);
|
|
449
489
|
});
|
|
450
490
|
|
|
491
|
+
it('loose lists with direct inline children', () => {
|
|
492
|
+
const source = `
|
|
493
|
+
- List
|
|
494
|
+
{% list %}
|
|
495
|
+
One
|
|
496
|
+
{% /list %}
|
|
497
|
+
Inline text:
|
|
498
|
+
{% list %}
|
|
499
|
+
Two
|
|
500
|
+
{% /list %}
|
|
501
|
+
`;
|
|
502
|
+
|
|
503
|
+
stable(source);
|
|
504
|
+
});
|
|
505
|
+
|
|
451
506
|
it('complicated nested lists', () => {
|
|
452
507
|
const source = `
|
|
453
508
|
* Create your CNAME record
|
|
@@ -580,6 +635,54 @@ Yes!
|
|
|
580
635
|
{% /tab %}
|
|
581
636
|
`;
|
|
582
637
|
|
|
583
|
-
|
|
638
|
+
stable(source);
|
|
639
|
+
});
|
|
640
|
+
|
|
641
|
+
it('fences with no language', () => {
|
|
642
|
+
const source = `
|
|
643
|
+
\`\`\`{% filename="package.json" %}
|
|
644
|
+
Package.json
|
|
645
|
+
\`\`\`
|
|
646
|
+
`;
|
|
647
|
+
|
|
648
|
+
const expected = `
|
|
649
|
+
\`\`\` {% filename="package.json" %}
|
|
650
|
+
Package.json
|
|
651
|
+
\`\`\`
|
|
652
|
+
`;
|
|
653
|
+
|
|
654
|
+
check(source, expected);
|
|
655
|
+
});
|
|
656
|
+
|
|
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
|
+
it('nested fences', () => {
|
|
675
|
+
const source = `
|
|
676
|
+
${'`'.repeat(4)}
|
|
677
|
+
|
|
678
|
+
${'`'.repeat(3)}
|
|
679
|
+
Fence within a fence
|
|
680
|
+
${'`'.repeat(3)}
|
|
681
|
+
|
|
682
|
+
|
|
683
|
+
${'`'.repeat(4)}
|
|
684
|
+
`;
|
|
685
|
+
|
|
686
|
+
stable(source);
|
|
584
687
|
});
|
|
585
688
|
});
|
package/src/formatter.ts
CHANGED
|
@@ -29,6 +29,10 @@ function* formatChildren(a: Node, options: Options) {
|
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
+
function* formatInline(g: Generator<string>) {
|
|
33
|
+
yield [...g].join('').trim();
|
|
34
|
+
}
|
|
35
|
+
|
|
32
36
|
function* formatTableRow(items: Array<string>) {
|
|
33
37
|
yield `| ${items.join(' | ')} |`;
|
|
34
38
|
}
|
|
@@ -93,7 +97,8 @@ function* formatVariable(v: Variable) {
|
|
|
93
97
|
yield v.path
|
|
94
98
|
.map((p, i) => {
|
|
95
99
|
if (i === 0) return p;
|
|
96
|
-
if (isIdentifier(
|
|
100
|
+
if (isIdentifier(p)) return '.' + p;
|
|
101
|
+
if (typeof p === 'number') return `[${p}]`;
|
|
97
102
|
return `["${p}"]`;
|
|
98
103
|
})
|
|
99
104
|
.join('');
|
|
@@ -117,6 +122,14 @@ function* trimStart(g: Generator<string>) {
|
|
|
117
122
|
yield* g;
|
|
118
123
|
}
|
|
119
124
|
|
|
125
|
+
function* escapeMarkdownCharacters(s: string, characters: RegExp) {
|
|
126
|
+
yield s
|
|
127
|
+
.replace(characters, '\\$&')
|
|
128
|
+
// TODO keep as entity in the AST?
|
|
129
|
+
// Non-breaking space (0xA0)
|
|
130
|
+
.replace(new RegExp('\xa0', 'g'), ' ');
|
|
131
|
+
}
|
|
132
|
+
|
|
120
133
|
function* formatNode(n: Node, o: Options = {}) {
|
|
121
134
|
const no = { ...o, parent: n };
|
|
122
135
|
const indent = SPACE.repeat(no.indent || 0);
|
|
@@ -134,20 +147,20 @@ function* formatNode(n: Node, o: Options = {}) {
|
|
|
134
147
|
yield indent;
|
|
135
148
|
yield '#'.repeat(n.attributes.level || 1);
|
|
136
149
|
yield SPACE;
|
|
137
|
-
yield* formatChildren(n, no);
|
|
150
|
+
yield* trimStart(formatChildren(n, no));
|
|
138
151
|
yield* formatAnnotations(n);
|
|
139
152
|
yield NL;
|
|
140
153
|
break;
|
|
141
154
|
}
|
|
142
155
|
case 'paragraph': {
|
|
143
156
|
yield NL;
|
|
144
|
-
yield indent;
|
|
145
157
|
yield* formatChildren(n, no);
|
|
146
158
|
yield* formatAnnotations(n);
|
|
147
159
|
yield NL;
|
|
148
160
|
break;
|
|
149
161
|
}
|
|
150
162
|
case 'inline': {
|
|
163
|
+
yield indent;
|
|
151
164
|
yield* formatChildren(n, no);
|
|
152
165
|
break;
|
|
153
166
|
}
|
|
@@ -157,7 +170,9 @@ function* formatNode(n: Node, o: Options = {}) {
|
|
|
157
170
|
yield* formatValue(n.attributes.alt, no);
|
|
158
171
|
yield ']';
|
|
159
172
|
yield '(';
|
|
160
|
-
yield*
|
|
173
|
+
yield* typeof n.attributes.src === 'string'
|
|
174
|
+
? escapeMarkdownCharacters(n.attributes.src, /[()]/)
|
|
175
|
+
: formatValue(n.attributes.src, no);
|
|
161
176
|
if (n.attributes.title) {
|
|
162
177
|
yield SPACE + `"${n.attributes.title}"`;
|
|
163
178
|
}
|
|
@@ -169,7 +184,9 @@ function* formatNode(n: Node, o: Options = {}) {
|
|
|
169
184
|
yield* formatChildren(n, no);
|
|
170
185
|
yield ']';
|
|
171
186
|
yield '(';
|
|
172
|
-
yield*
|
|
187
|
+
yield* typeof n.attributes.href === 'string'
|
|
188
|
+
? escapeMarkdownCharacters(n.attributes.href, /[()]/g)
|
|
189
|
+
: formatValue(n.attributes.href, no);
|
|
173
190
|
if (n.attributes.title) {
|
|
174
191
|
yield SPACE + `"${n.attributes.title}"`;
|
|
175
192
|
}
|
|
@@ -177,9 +194,12 @@ function* formatNode(n: Node, o: Options = {}) {
|
|
|
177
194
|
break;
|
|
178
195
|
}
|
|
179
196
|
case 'text': {
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
197
|
+
const { content } = n.attributes;
|
|
198
|
+
if (Ast.isAst(content)) yield OPEN + SPACE;
|
|
199
|
+
yield* typeof content === 'string'
|
|
200
|
+
? escapeMarkdownCharacters(content, /[_*~]/g)
|
|
201
|
+
: formatValue(content, no);
|
|
202
|
+
if (Ast.isAst(content)) yield SPACE + CLOSE;
|
|
183
203
|
break;
|
|
184
204
|
}
|
|
185
205
|
case 'blockquote': {
|
|
@@ -199,15 +219,24 @@ function* formatNode(n: Node, o: Options = {}) {
|
|
|
199
219
|
case 'fence': {
|
|
200
220
|
yield NL;
|
|
201
221
|
yield indent;
|
|
202
|
-
|
|
203
|
-
|
|
222
|
+
|
|
223
|
+
const innerFence = n.attributes.content.match(/`{3,}/g) || [];
|
|
224
|
+
|
|
225
|
+
const innerFenceLength = innerFence
|
|
226
|
+
.map((s: string) => s.length)
|
|
227
|
+
.reduce(max, 0);
|
|
228
|
+
|
|
229
|
+
const boundary = '`'.repeat(innerFenceLength ? innerFenceLength + 1 : 3);
|
|
230
|
+
|
|
231
|
+
yield boundary;
|
|
232
|
+
if (n.attributes.language) yield n.attributes.language;
|
|
204
233
|
if (n.annotations.length) yield SPACE;
|
|
205
234
|
yield* formatAnnotations(n);
|
|
206
235
|
yield NL;
|
|
207
236
|
yield indent;
|
|
208
237
|
// TODO use formatChildren once we can differentiate inline from block tags within fences
|
|
209
238
|
yield n.attributes.content.split(NL).join(NL + indent); // yield* formatChildren(n, no);
|
|
210
|
-
yield
|
|
239
|
+
yield boundary;
|
|
211
240
|
yield NL;
|
|
212
241
|
break;
|
|
213
242
|
}
|
|
@@ -225,7 +254,7 @@ function* formatNode(n: Node, o: Options = {}) {
|
|
|
225
254
|
(o.maxTagOpeningWidth || MAX_TAG_OPENING_WIDTH);
|
|
226
255
|
|
|
227
256
|
// {% tag attributes={...} %}
|
|
228
|
-
yield (isLongTagOpening
|
|
257
|
+
yield (!n.inline && isLongTagOpening
|
|
229
258
|
? tag.join(NL + SPACE.repeat(open.length) + indent)
|
|
230
259
|
: inlineTag) +
|
|
231
260
|
SPACE +
|
|
@@ -247,43 +276,41 @@ function* formatNode(n: Node, o: Options = {}) {
|
|
|
247
276
|
}
|
|
248
277
|
case 'list': {
|
|
249
278
|
const prefix = n.attributes.ordered ? OL : UL;
|
|
250
|
-
yield NL;
|
|
251
279
|
for (const child of n.children) {
|
|
252
280
|
const d = format(child, increment(no, prefix.length)).trim();
|
|
253
|
-
yield indent + prefix + d;
|
|
254
|
-
yield NL;
|
|
281
|
+
yield NL + indent + prefix + d;
|
|
255
282
|
}
|
|
283
|
+
yield NL;
|
|
256
284
|
break;
|
|
257
285
|
}
|
|
258
286
|
case 'item': {
|
|
259
287
|
for (let i = 0; i < n.children.length; i++) {
|
|
260
|
-
|
|
261
|
-
yield* formatValue(child, no);
|
|
288
|
+
yield* formatValue(n.children[i], no);
|
|
262
289
|
if (i === 0) yield* formatAnnotations(n);
|
|
263
290
|
}
|
|
264
291
|
break;
|
|
265
292
|
}
|
|
266
293
|
case 'strong': {
|
|
267
294
|
yield '**';
|
|
268
|
-
yield* formatChildren(n, no);
|
|
295
|
+
yield* formatInline(formatChildren(n, no));
|
|
269
296
|
yield '**';
|
|
270
297
|
break;
|
|
271
298
|
}
|
|
272
299
|
case 'em': {
|
|
273
300
|
yield '_';
|
|
274
|
-
yield* formatChildren(n, no);
|
|
301
|
+
yield* formatInline(formatChildren(n, no));
|
|
275
302
|
yield '_';
|
|
276
303
|
break;
|
|
277
304
|
}
|
|
278
305
|
case 'code': {
|
|
279
306
|
yield '`';
|
|
280
|
-
yield* formatValue(n.attributes.content, no);
|
|
307
|
+
yield* formatInline(formatValue(n.attributes.content, no));
|
|
281
308
|
yield '`';
|
|
282
309
|
break;
|
|
283
310
|
}
|
|
284
311
|
case 's': {
|
|
285
312
|
yield '~~';
|
|
286
|
-
yield* formatChildren(n, no);
|
|
313
|
+
yield* formatInline(formatChildren(n, no));
|
|
287
314
|
yield '~~';
|
|
288
315
|
break;
|
|
289
316
|
}
|
|
@@ -313,11 +340,8 @@ function* formatNode(n: Node, o: Options = {}) {
|
|
|
313
340
|
yield NL;
|
|
314
341
|
yield indent + '---';
|
|
315
342
|
}
|
|
316
|
-
for (
|
|
317
|
-
|
|
318
|
-
yield NL;
|
|
319
|
-
// TODO see if we should move trim() to `td`
|
|
320
|
-
yield indent + UL + d.trim();
|
|
343
|
+
for (const d of row) {
|
|
344
|
+
yield NL + indent + UL + d;
|
|
321
345
|
}
|
|
322
346
|
}
|
|
323
347
|
}
|
|
@@ -354,7 +378,7 @@ function* formatNode(n: Node, o: Options = {}) {
|
|
|
354
378
|
}
|
|
355
379
|
case 'td':
|
|
356
380
|
case 'th': {
|
|
357
|
-
yield [...formatChildren(n, no), ...formatAnnotations(n)].join('');
|
|
381
|
+
yield [...formatChildren(n, no), ...formatAnnotations(n)].join('').trim();
|
|
358
382
|
break;
|
|
359
383
|
}
|
|
360
384
|
case 'tbody': {
|