@markdoc/markdoc 0.5.6 → 0.5.7
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.d.ts +15 -81
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +513 -457
- package/dist/index.js.map +4 -4
- package/dist/index.mjs +508 -456
- package/dist/index.mjs.map +4 -4
- package/dist/react.js +16 -16
- package/dist/react.js.map +2 -2
- package/dist/src/ast/index.d.ts +3 -14
- package/dist/src/ast/index.d.ts.map +1 -1
- package/dist/src/formatter.d.ts +1 -1
- package/dist/src/formatter.d.ts.map +1 -1
- package/dist/src/renderers/react/react.d.ts +3 -3
- 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/tag.d.ts +1 -1
- package/dist/src/tag.d.ts.map +1 -1
- package/dist/src/tags/index.d.ts +5 -60
- package/dist/src/tags/index.d.ts.map +1 -1
- package/dist/src/transformer.d.ts +1 -1
- package/dist/src/transformer.d.ts.map +1 -1
- package/dist/src/transforms/table.d.ts.map +1 -1
- package/dist/src/types.d.ts +21 -21
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/validator.d.ts +3 -23
- package/dist/src/validator.d.ts.map +1 -1
- package/package.json +19 -12
- package/src/transforms/table.test.ts +20 -9
- package/src/transforms/table.ts +6 -13
- package/src/utils.test.ts +1 -1
- package/src/validator.ts +31 -5
package/dist/react.js
CHANGED
|
@@ -6,9 +6,11 @@ var Tag = class {
|
|
|
6
6
|
this.attributes = attributes;
|
|
7
7
|
this.children = children;
|
|
8
8
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
static {
|
|
10
|
+
this.isTag = (tag) => {
|
|
11
|
+
return !!(tag?.$$mdtype === "Tag");
|
|
12
|
+
};
|
|
13
|
+
}
|
|
12
14
|
};
|
|
13
15
|
|
|
14
16
|
// src/renderers/react/react.ts
|
|
@@ -17,17 +19,12 @@ function tagName(name, components) {
|
|
|
17
19
|
}
|
|
18
20
|
function dynamic(node, React, { components = {}, resolveTagName = tagName } = {}) {
|
|
19
21
|
function deepRender(value) {
|
|
20
|
-
if (value == null || typeof value !== "object")
|
|
21
|
-
|
|
22
|
-
if (
|
|
23
|
-
|
|
24
|
-
if (value.$$mdtype === "Tag")
|
|
25
|
-
return render(value);
|
|
26
|
-
if (typeof value !== "object")
|
|
27
|
-
return value;
|
|
22
|
+
if (value == null || typeof value !== "object") return value;
|
|
23
|
+
if (Array.isArray(value)) return value.map((item) => deepRender(item));
|
|
24
|
+
if (value.$$mdtype === "Tag") return render(value);
|
|
25
|
+
if (typeof value !== "object") return value;
|
|
28
26
|
const output = {};
|
|
29
|
-
for (const [k, v] of Object.entries(value))
|
|
30
|
-
output[k] = deepRender(v);
|
|
27
|
+
for (const [k, v] of Object.entries(value)) output[k] = deepRender(v);
|
|
31
28
|
return output;
|
|
32
29
|
}
|
|
33
30
|
function render(node2) {
|
|
@@ -40,9 +37,12 @@ function dynamic(node, React, { components = {}, resolveTagName = tagName } = {}
|
|
|
40
37
|
attributes: { class: className, ...attrs } = {},
|
|
41
38
|
children = []
|
|
42
39
|
} = node2;
|
|
43
|
-
if (className)
|
|
44
|
-
|
|
45
|
-
|
|
40
|
+
if (className) attrs.className = className;
|
|
41
|
+
return React.createElement(
|
|
42
|
+
resolveTagName(name, components),
|
|
43
|
+
Object.keys(attrs).length == 0 ? null : deepRender(attrs),
|
|
44
|
+
...children.map(render)
|
|
45
|
+
);
|
|
46
46
|
}
|
|
47
47
|
return render(node);
|
|
48
48
|
}
|
package/dist/react.js.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/tag.ts", "../src/renderers/react/react.ts"],
|
|
4
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 !!(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<any>;\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 type RenderOpts = {\n components?: Record<string, Component> | ((string: string) => Component);\n resolveTagName?: typeof tagName;\n};\nexport default function dynamic(\n node: RenderableTreeNodes,\n React: ReactShape,\n { components = {}, resolveTagName = tagName }: RenderOpts = {}\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 resolveTagName(name, components),\n Object.keys(attrs).length == 0 ? null : deepRender(attrs),\n ...children.map(render)\n );\n }\n\n return render(node);\n}\n"],
|
|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A,YAAY,EAAE,OAAO,WAAW,GAAG,MAAM,IAAI,CAAC;AAAA,MAC9C,WAAW,CAAC;AAAA,IACd,IAAIA;AAEJ,QAAI,UAAW,OAAM,YAAY;AAEjC,WAAO,MAAM;AAAA,MACX,eAAe,MAAM,UAAU;AAAA,MAC/B,OAAO,KAAK,KAAK,EAAE,UAAU,IAAI,OAAO,WAAW,KAAK;AAAA,MACxD,GAAG,SAAS,IAAI,MAAM;AAAA,IACxB;AAAA,EACF;AAEA,SAAO,OAAO,IAAI;AACpB;",
|
|
6
|
+
"names": ["node"]
|
|
7
7
|
}
|
package/dist/src/ast/index.d.ts
CHANGED
|
@@ -6,21 +6,10 @@ declare function fromJSON(text: string): Node | Node[];
|
|
|
6
6
|
declare const _default: {
|
|
7
7
|
fromJSON: typeof fromJSON;
|
|
8
8
|
isAst(value?: any): value is AstType;
|
|
9
|
-
isFunction(value?: any): value is Function;
|
|
10
|
-
isVariable(value?: any): value is Variable;
|
|
9
|
+
isFunction(value?: any): value is import("../types").Function;
|
|
10
|
+
isVariable(value?: any): value is import("../types").Variable;
|
|
11
11
|
getAstValues(value: any): Generator<AstType, void, unknown>;
|
|
12
|
-
resolve(value: any, config?:
|
|
13
|
-
nodes: Partial<Record<import("../types").NodeType, import("../types").Schema<Partial<any>, string>>>;
|
|
14
|
-
tags: Record<string, import("../types").Schema<Readonly<Partial<any>>, string>>;
|
|
15
|
-
variables: Record<string, any>;
|
|
16
|
-
functions: Record<string, import("../types").ConfigFunction>;
|
|
17
|
-
partials: Record<string, any>;
|
|
18
|
-
validation?: {
|
|
19
|
-
parents?: Node[] | undefined;
|
|
20
|
-
validateFunctions?: boolean | undefined;
|
|
21
|
-
environment?: string | undefined;
|
|
22
|
-
} | undefined;
|
|
23
|
-
}>>): any;
|
|
12
|
+
resolve(value: any, config?: import("../types").Config): any;
|
|
24
13
|
Function: typeof Function;
|
|
25
14
|
Node: typeof Node;
|
|
26
15
|
Variable: typeof Variable;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/ast/index.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,QAAQ,CAAC;AAC1B,OAAO,QAAQ,MAAM,YAAY,CAAC;AAClC,OAAO,QAAQ,MAAM,YAAY,CAAC;AAGlC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAcxC,iBAAS,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,EAAE,CAE7C
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/ast/index.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,QAAQ,CAAC;AAC1B,OAAO,QAAQ,MAAM,YAAY,CAAC;AAClC,OAAO,QAAQ,MAAM,YAAY,CAAC;AAGlC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAcxC,iBAAS,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,EAAE,CAE7C;;;;;;;;;;;;AAED,wBAIE"}
|
package/dist/src/formatter.d.ts
CHANGED
|
@@ -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,
|
|
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,KAAK,OAAO,GAAG;IACb,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,eAAe,CAAC,EAAE,WAAW,GAAG,QAAQ,CAAC;IACzC,MAAM,CAAC,EAAE,IAAI,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AA2eF,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,CAAC,EAAE,KAAK,GAAG,KAAK,EAAE,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,MAAM,CAI5E"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { RenderableTreeNodes } from '../../types';
|
|
2
2
|
import type { createElement, ComponentType, Fragment, ReactNode } from 'react';
|
|
3
|
-
|
|
3
|
+
type ReactShape = Readonly<{
|
|
4
4
|
createElement: typeof createElement;
|
|
5
5
|
Fragment: typeof Fragment;
|
|
6
6
|
}>;
|
|
7
|
-
|
|
7
|
+
type Component = ComponentType<any>;
|
|
8
8
|
declare function tagName(name: string, components: Record<string, Component> | ((string: string) => Component)): string | Component;
|
|
9
|
-
export
|
|
9
|
+
export type RenderOpts = {
|
|
10
10
|
components?: Record<string, Component> | ((string: string) => Component);
|
|
11
11
|
resolveTagName?: typeof tagName;
|
|
12
12
|
};
|
|
@@ -1 +1 @@
|
|
|
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,EAAE,aAAa,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAE/E,
|
|
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,EAAE,aAAa,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAE/E,KAAK,UAAU,GAAG,QAAQ,CAAC;IACzB,aAAa,EAAE,OAAO,aAAa,CAAC;IACpC,QAAQ,EAAE,OAAO,QAAQ,CAAC;CAC3B,CAAC,CAAC;AAEH,KAAK,SAAS,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC;AAEpC,iBAAS,OAAO,CACd,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,MAAM,KAAK,SAAS,CAAC,GACtE,MAAM,GAAG,SAAS,CAQpB;AAED,MAAM,MAAM,UAAU,GAAG;IACvB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,MAAM,KAAK,SAAS,CAAC,CAAC;IACzE,cAAc,CAAC,EAAE,OAAO,OAAO,CAAC;CACjC,CAAC;AACF,MAAM,CAAC,OAAO,UAAU,OAAO,CAC7B,IAAI,EAAE,mBAAmB,EACzB,KAAK,EAAE,UAAU,EACjB,EAAE,UAAe,EAAE,cAAwB,EAAE,GAAE,UAAe,aAuC/D"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { RenderableTreeNodes } from '../../types';
|
|
2
2
|
import type { ComponentType } from 'react';
|
|
3
|
-
|
|
3
|
+
type Component = ComponentType<unknown>;
|
|
4
4
|
declare function tagName(name: string, components: Record<string, Component> | ((string: string) => Component)): string | Component;
|
|
5
5
|
export default function reactStatic(node: RenderableTreeNodes, { resolveTagName }?: {
|
|
6
6
|
resolveTagName?: typeof tagName;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"static.d.ts","sourceRoot":"","sources":["../../../../src/renderers/react/static.ts"],"names":[],"mappings":"AACA,OAAO,EAAsB,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAEtE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAE3C,
|
|
1
|
+
{"version":3,"file":"static.d.ts","sourceRoot":"","sources":["../../../../src/renderers/react/static.ts"],"names":[],"mappings":"AACA,OAAO,EAAsB,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAEtE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAE3C,KAAK,SAAS,GAAG,aAAa,CAAC,OAAO,CAAC,CAAC;AAExC,iBAAS,OAAO,CACd,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,MAAM,KAAK,SAAS,CAAC,GACtE,MAAM,GAAG,SAAS,CAQpB;AA4CD,MAAM,CAAC,OAAO,UAAU,WAAW,CACjC,IAAI,EAAE,mBAAmB,EACzB,EAAE,cAAwB,EAAE,GAAE;IAAE,cAAc,CAAC,EAAE,OAAO,OAAO,CAAA;CAAO,GACrE,MAAM,CAYR"}
|
package/dist/src/tag.d.ts
CHANGED
|
@@ -1,7 +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
|
|
4
|
+
static isTag: (tag: any) => tag is Tag;
|
|
5
5
|
name: N;
|
|
6
6
|
attributes: A;
|
|
7
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,
|
|
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,EAAG,KAAK,CAAU;IAEnC,MAAM,CAAC,KAAK,GAAI,KAAK,GAAG,KAAG,GAAG,IAAI,GAAG,CAEnC;IAEF,IAAI,EAAE,CAAC,CAAC;IACR,UAAU,EAAE,CAAC,CAAC;IACd,QAAQ,EAAE,kBAAkB,EAAE,CAAC;gBAG7B,IAAI,GAAY,CAAC,EACjB,UAAU,GAAS,CAAC,EACpB,QAAQ,GAAE,kBAAkB,EAAO;CAMtC"}
|
package/dist/src/tags/index.d.ts
CHANGED
|
@@ -1,64 +1,9 @@
|
|
|
1
1
|
declare const _default: {
|
|
2
|
-
else: import("../types").Schema
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
partials: Record<string, any>;
|
|
8
|
-
validation?: {
|
|
9
|
-
parents?: import("../types").Node[] | undefined;
|
|
10
|
-
validateFunctions?: boolean | undefined;
|
|
11
|
-
environment?: string | undefined;
|
|
12
|
-
} | undefined;
|
|
13
|
-
}>>, string>;
|
|
14
|
-
if: import("../types").Schema<Readonly<Partial<{
|
|
15
|
-
nodes: Partial<Record<import("../types").NodeType, import("../types").Schema<Partial<any>, string>>>;
|
|
16
|
-
tags: Record<string, import("../types").Schema<Readonly<Partial<any>>, string>>;
|
|
17
|
-
variables: Record<string, any>;
|
|
18
|
-
functions: Record<string, import("../types").ConfigFunction>;
|
|
19
|
-
partials: Record<string, any>;
|
|
20
|
-
validation?: {
|
|
21
|
-
parents?: import("../types").Node[] | undefined;
|
|
22
|
-
validateFunctions?: boolean | undefined;
|
|
23
|
-
environment?: string | undefined;
|
|
24
|
-
} | undefined;
|
|
25
|
-
}>>, string>;
|
|
26
|
-
partial: import("../types").Schema<Readonly<Partial<{
|
|
27
|
-
nodes: Partial<Record<import("../types").NodeType, import("../types").Schema<Partial<any>, string>>>;
|
|
28
|
-
tags: Record<string, import("../types").Schema<Readonly<Partial<any>>, string>>;
|
|
29
|
-
variables: Record<string, any>;
|
|
30
|
-
functions: Record<string, import("../types").ConfigFunction>;
|
|
31
|
-
partials: Record<string, any>;
|
|
32
|
-
validation?: {
|
|
33
|
-
parents?: import("../types").Node[] | undefined;
|
|
34
|
-
validateFunctions?: boolean | undefined;
|
|
35
|
-
environment?: string | undefined;
|
|
36
|
-
} | undefined;
|
|
37
|
-
}>>, string>;
|
|
38
|
-
slot: import("../types").Schema<Readonly<Partial<{
|
|
39
|
-
nodes: Partial<Record<import("../types").NodeType, import("../types").Schema<Partial<any>, string>>>;
|
|
40
|
-
tags: Record<string, import("../types").Schema<Readonly<Partial<any>>, string>>;
|
|
41
|
-
variables: Record<string, any>;
|
|
42
|
-
functions: Record<string, import("../types").ConfigFunction>;
|
|
43
|
-
partials: Record<string, any>;
|
|
44
|
-
validation?: {
|
|
45
|
-
parents?: import("../types").Node[] | undefined;
|
|
46
|
-
validateFunctions?: boolean | undefined;
|
|
47
|
-
environment?: string | undefined;
|
|
48
|
-
} | undefined;
|
|
49
|
-
}>>, string>;
|
|
50
|
-
table: import("../types").Schema<Readonly<Partial<{
|
|
51
|
-
nodes: Partial<Record<import("../types").NodeType, import("../types").Schema<Partial<any>, string>>>;
|
|
52
|
-
tags: Record<string, import("../types").Schema<Readonly<Partial<any>>, string>>;
|
|
53
|
-
variables: Record<string, any>;
|
|
54
|
-
functions: Record<string, import("../types").ConfigFunction>;
|
|
55
|
-
partials: Record<string, any>;
|
|
56
|
-
validation?: {
|
|
57
|
-
parents?: import("../types").Node[] | undefined;
|
|
58
|
-
validateFunctions?: boolean | undefined;
|
|
59
|
-
environment?: string | undefined;
|
|
60
|
-
} | undefined;
|
|
61
|
-
}>>, string>;
|
|
2
|
+
else: import("../types").Schema;
|
|
3
|
+
if: import("../types").Schema;
|
|
4
|
+
partial: import("../types").Schema;
|
|
5
|
+
slot: import("../types").Schema;
|
|
6
|
+
table: import("../types").Schema;
|
|
62
7
|
};
|
|
63
8
|
export default _default;
|
|
64
9
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/tags/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/tags/index.ts"],"names":[],"mappings":";;;;;;;AAKA,wBAME"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Schema, Transformer } from './types';
|
|
2
|
-
|
|
2
|
+
type AttributesSchema = Schema['attributes'];
|
|
3
3
|
export declare const globalAttributes: AttributesSchema;
|
|
4
4
|
declare const _default: Transformer;
|
|
5
5
|
export default _default;
|
|
@@ -1 +1 @@
|
|
|
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,
|
|
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,KAAK,gBAAgB,GAAG,MAAM,CAAC,YAAY,CAAC,CAAC;AAE7C,eAAO,MAAM,gBAAgB,EAAE,gBAG9B,CAAC;wBAqEG,WAAW;AAnEhB,wBAmEiB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"table.d.ts","sourceRoot":"","sources":["../../../src/transforms/table.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAA6B,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"table.d.ts","sourceRoot":"","sources":["../../../src/transforms/table.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAA6B,MAAM,UAAU,CAAC;AAkChE,MAAM,CAAC,OAAO,UAAU,SAAS,CAC/B,QAAQ,EAAE,IAAI,EACd,eAAe,GAAE,MAAM,EAAW,QAmDnC"}
|
package/dist/src/types.d.ts
CHANGED
|
@@ -5,18 +5,18 @@ import type Tag from './tag';
|
|
|
5
5
|
export type { Node, Tag };
|
|
6
6
|
export declare type Function = Func;
|
|
7
7
|
export declare type Variable = Var;
|
|
8
|
-
export
|
|
8
|
+
export type MaybePromise<T> = T | Promise<T>;
|
|
9
9
|
export interface AstType {
|
|
10
10
|
readonly $$mdtype: 'Function' | 'Node' | 'Variable';
|
|
11
11
|
resolve(config: Config): any;
|
|
12
12
|
}
|
|
13
|
-
export
|
|
13
|
+
export type AttributeValue = {
|
|
14
14
|
type: string;
|
|
15
15
|
name: string;
|
|
16
16
|
value: any;
|
|
17
17
|
};
|
|
18
|
-
export
|
|
19
|
-
export
|
|
18
|
+
export type Config<R = string> = Readonly<ConfigType<R>>;
|
|
19
|
+
export type ConfigType<R = string> = Partial<{
|
|
20
20
|
nodes: Partial<Record<NodeType, Schema<ConfigType, R>>>;
|
|
21
21
|
tags: Record<string, Schema>;
|
|
22
22
|
variables: Record<string, any>;
|
|
@@ -28,7 +28,7 @@ export declare type ConfigType<R = string> = Partial<{
|
|
|
28
28
|
environment?: string;
|
|
29
29
|
};
|
|
30
30
|
}>;
|
|
31
|
-
export
|
|
31
|
+
export type ConfigFunction = {
|
|
32
32
|
returns?: ValidationType | ValidationType[];
|
|
33
33
|
parameters?: Record<string, SchemaAttribute>;
|
|
34
34
|
transform?(parameters: Record<string, any>, config: Config): any;
|
|
@@ -42,23 +42,23 @@ export interface CustomAttributeType {
|
|
|
42
42
|
new (): CustomAttributeTypeInterface;
|
|
43
43
|
readonly prototype: CustomAttributeTypeInterface;
|
|
44
44
|
}
|
|
45
|
-
export
|
|
45
|
+
export type Location = {
|
|
46
46
|
file?: string;
|
|
47
47
|
start: LocationEdge;
|
|
48
48
|
end: LocationEdge;
|
|
49
49
|
};
|
|
50
|
-
export
|
|
50
|
+
export type LocationEdge = {
|
|
51
51
|
line: number;
|
|
52
52
|
character?: number;
|
|
53
53
|
};
|
|
54
|
-
export
|
|
55
|
-
export
|
|
56
|
-
export
|
|
57
|
-
export
|
|
58
|
-
export
|
|
54
|
+
export 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';
|
|
55
|
+
export type Primitive = null | boolean | number | string;
|
|
56
|
+
export type RenderableTreeNode = Tag | Scalar;
|
|
57
|
+
export type RenderableTreeNodes = RenderableTreeNode | RenderableTreeNode[];
|
|
58
|
+
export type Scalar = Primitive | Scalar[] | {
|
|
59
59
|
[key: string]: Scalar;
|
|
60
60
|
};
|
|
61
|
-
export
|
|
61
|
+
export type Schema<C extends Config = Config, R = string> = {
|
|
62
62
|
render?: R;
|
|
63
63
|
children?: string[];
|
|
64
64
|
attributes?: Record<string, SchemaAttribute>;
|
|
@@ -69,7 +69,7 @@ export declare type Schema<C extends Config = Config, R = string> = {
|
|
|
69
69
|
validate?(node: Node, config: C): MaybePromise<ValidationError[]>;
|
|
70
70
|
description?: string;
|
|
71
71
|
};
|
|
72
|
-
export
|
|
72
|
+
export type SchemaAttribute = {
|
|
73
73
|
type?: ValidationType | ValidationType[];
|
|
74
74
|
render?: boolean | string;
|
|
75
75
|
default?: any;
|
|
@@ -79,8 +79,8 @@ export declare type SchemaAttribute = {
|
|
|
79
79
|
errorLevel?: ValidationError['level'];
|
|
80
80
|
description?: string;
|
|
81
81
|
};
|
|
82
|
-
export
|
|
83
|
-
export
|
|
82
|
+
export type SchemaMatches = RegExp | string[] | null;
|
|
83
|
+
export type SchemaSlot = {
|
|
84
84
|
render?: boolean | string;
|
|
85
85
|
required?: boolean;
|
|
86
86
|
};
|
|
@@ -90,21 +90,21 @@ export interface Transformer {
|
|
|
90
90
|
attributes(node: Node, config: Config): Record<string, any>;
|
|
91
91
|
children(node: Node, config: Config): RenderableTreeNode[];
|
|
92
92
|
}
|
|
93
|
-
export
|
|
93
|
+
export type ValidationError = {
|
|
94
94
|
id: string;
|
|
95
95
|
level: 'debug' | 'info' | 'warning' | 'error' | 'critical';
|
|
96
96
|
message: string;
|
|
97
97
|
location?: Location;
|
|
98
98
|
};
|
|
99
|
-
export
|
|
99
|
+
export type ValidateError = {
|
|
100
100
|
type: string;
|
|
101
101
|
lines: number[];
|
|
102
102
|
location?: Location;
|
|
103
103
|
error: ValidationError;
|
|
104
104
|
};
|
|
105
|
-
export
|
|
106
|
-
export
|
|
107
|
-
export
|
|
105
|
+
export type ValidationType = CustomAttributeType | typeof String | typeof Number | typeof Boolean | typeof Object | typeof Array | 'String' | 'Number' | 'Boolean' | 'Object' | 'Array';
|
|
106
|
+
export type Value = AstType | Scalar;
|
|
107
|
+
export type ParserArgs = {
|
|
108
108
|
file?: string;
|
|
109
109
|
slots?: boolean;
|
|
110
110
|
location?: boolean;
|
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,QAA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,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,MAAM,MAAM,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,MAAM,MAAM,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,MAAM,MAAM,KAAK,GAAG,OAAO,GAAG,MAAM,CAAC;AAErC,MAAM,MAAM,UAAU,GAAG;IACvB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,QAAQ,CAAC,EAAE,OAAO,CAAC;IAKnB,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;CAC5B,CAAC"}
|
package/dist/src/validator.d.ts
CHANGED
|
@@ -1,28 +1,8 @@
|
|
|
1
|
-
import type { Node, Config, SchemaAttribute, ValidationError, Value } from './types';
|
|
2
|
-
|
|
1
|
+
import type { Node, Config, SchemaAttribute, ValidateError, ValidationError, Value } from './types';
|
|
2
|
+
type TypeParam = NonNullable<SchemaAttribute['type']>;
|
|
3
3
|
export declare function validateType(type: TypeParam, value: Value, config: Config, key: string): boolean | ValidationError[];
|
|
4
4
|
export default function validator(node: Node, config: Config): ValidationError[] | Promise<ValidationError[]>;
|
|
5
5
|
export declare function walkWithParents(node: Node, parents?: Node[]): Generator<[Node, Node[]]>;
|
|
6
|
-
export declare function validateTree(content: Node, config: Config): Promise<(
|
|
7
|
-
type: import("./types").NodeType;
|
|
8
|
-
lines: number[];
|
|
9
|
-
location: import("./types").Location | undefined;
|
|
10
|
-
error: ValidationError;
|
|
11
|
-
} | {
|
|
12
|
-
type: import("./types").NodeType;
|
|
13
|
-
lines: number[];
|
|
14
|
-
location: import("./types").Location | undefined;
|
|
15
|
-
error: ValidationError;
|
|
16
|
-
})[]> | (Promise<{
|
|
17
|
-
type: import("./types").NodeType;
|
|
18
|
-
lines: number[];
|
|
19
|
-
location: import("./types").Location | undefined;
|
|
20
|
-
error: ValidationError;
|
|
21
|
-
}[]> | {
|
|
22
|
-
type: import("./types").NodeType;
|
|
23
|
-
lines: number[];
|
|
24
|
-
location: import("./types").Location | undefined;
|
|
25
|
-
error: ValidationError;
|
|
26
|
-
})[];
|
|
6
|
+
export declare function validateTree(content: Node, config: Config): Promise<ValidateError[]> | (ValidateError | Promise<ValidateError[]>)[];
|
|
27
7
|
export {};
|
|
28
8
|
//# sourceMappingURL=validator.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validator.d.ts","sourceRoot":"","sources":["../../src/validator.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"validator.d.ts","sourceRoot":"","sources":["../../src/validator.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAEV,IAAI,EAEJ,MAAM,EACN,eAAe,EACf,aAAa,EACb,eAAe,EACf,KAAK,EACN,MAAM,SAAS,CAAC;AAUjB,KAAK,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,EACd,GAAG,EAAE,MAAM,GACV,OAAO,GAAG,eAAe,EAAE,CA2B7B;AA2ED,MAAM,CAAC,OAAO,UAAU,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,kDAoK3D;AAED,wBAAiB,eAAe,CAC9B,IAAI,EAAE,IAAI,EACV,OAAO,GAAE,IAAI,EAAO,GACnB,SAAS,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAI3B;AA6BD,wBAAgB,YAAY,CAAC,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,2EAoBzD"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@markdoc/markdoc",
|
|
3
3
|
"author": "Ryan Paul",
|
|
4
|
-
"version": "0.5.
|
|
4
|
+
"version": "0.5.7",
|
|
5
5
|
"description": "A text markup language for documentation",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"module": "dist/index.mjs",
|
|
@@ -49,25 +49,32 @@
|
|
|
49
49
|
}
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
|
-
"@types/jasmine": "^
|
|
53
|
-
"@types/node": "^
|
|
54
|
-
"@
|
|
55
|
-
"@
|
|
52
|
+
"@types/jasmine": "^5.0.0",
|
|
53
|
+
"@types/node": "^18.0.0",
|
|
54
|
+
"@types/react": "^17.0.0",
|
|
55
|
+
"@eslint/js": "^9.0.0",
|
|
56
56
|
"deep-assert": "0.3.0",
|
|
57
|
-
"diff": "^4.0.
|
|
58
|
-
"esbuild": "0.
|
|
59
|
-
"eslint": "
|
|
60
|
-
"
|
|
57
|
+
"diff": "^4.0.4",
|
|
58
|
+
"esbuild": "0.25.0",
|
|
59
|
+
"eslint": "10.1.0",
|
|
60
|
+
"globals": "^16.0.0",
|
|
61
|
+
"jasmine": "5.13.0",
|
|
61
62
|
"jest-diff": "^28.1.3",
|
|
62
63
|
"markdown-it": "12.3.2",
|
|
63
|
-
"patch-package": "^
|
|
64
|
+
"patch-package": "^8.0.0",
|
|
64
65
|
"pegjs": "0.11.0-master.b7b87ea",
|
|
65
66
|
"prettier": "^2.5.1",
|
|
67
|
+
"typescript-eslint": "^8.0.0",
|
|
66
68
|
"ts-eager": "2.0.2",
|
|
67
|
-
"typedoc": "
|
|
68
|
-
"typescript": "^
|
|
69
|
+
"typedoc": "0.28.18",
|
|
70
|
+
"typescript": "^5.0.0",
|
|
69
71
|
"yaml-js": "^0.2.3"
|
|
70
72
|
},
|
|
73
|
+
"overrides": {
|
|
74
|
+
"ts-eager": {
|
|
75
|
+
"esbuild": "0.25.0"
|
|
76
|
+
}
|
|
77
|
+
},
|
|
71
78
|
"repository": {
|
|
72
79
|
"type": "git",
|
|
73
80
|
"url": "git+https://github.com/markdoc/markdoc.git"
|
|
@@ -23,8 +23,8 @@ This is invalid non-conditional content at the row level.
|
|
|
23
23
|
(e) => e.error.id === 'table-syntax'
|
|
24
24
|
);
|
|
25
25
|
|
|
26
|
-
// One error for the paragraph inside the conditional
|
|
27
|
-
// one for the bare paragraph
|
|
26
|
+
// One error for the paragraph inside the conditional,
|
|
27
|
+
// one for the bare paragraph at the row level
|
|
28
28
|
expect(tableSyntaxErrors.length).toBe(2);
|
|
29
29
|
for (const err of tableSyntaxErrors) {
|
|
30
30
|
expect(err.error.level).toBe('critical');
|
|
@@ -32,18 +32,21 @@ This is invalid non-conditional content at the row level.
|
|
|
32
32
|
expect(err.error.message).toContain('indented');
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
//
|
|
35
|
+
// Errors should point to the actual invalid content, not the table
|
|
36
36
|
const conditionalError = tableSyntaxErrors.find(
|
|
37
|
-
(e) => e.
|
|
37
|
+
(e) => e.location?.start.line === 7
|
|
38
38
|
);
|
|
39
|
-
expect(conditionalError).toBeDefined();
|
|
40
|
-
expect(conditionalError?.location?.start.line).toBeGreaterThan(0);
|
|
41
|
-
|
|
42
|
-
// The row-level error should point to the table tag (paragraph is discarded)
|
|
43
39
|
const rowLevelError = tableSyntaxErrors.find(
|
|
44
|
-
(e) => e.location?.start.line ===
|
|
40
|
+
(e) => e.location?.start.line === 9
|
|
45
41
|
);
|
|
42
|
+
expect(conditionalError).toBeDefined();
|
|
43
|
+
expect(conditionalError?.location?.start.line).toBe(7);
|
|
44
|
+
expect(conditionalError?.location?.end.line).toBe(8);
|
|
45
|
+
expect(conditionalError?.lines).toEqual([7, 8]);
|
|
46
46
|
expect(rowLevelError).toBeDefined();
|
|
47
|
+
expect(rowLevelError?.location?.start.line).toBe(9);
|
|
48
|
+
expect(rowLevelError?.location?.end.line).toBe(10);
|
|
49
|
+
expect(rowLevelError?.lines).toEqual([9, 10]);
|
|
47
50
|
});
|
|
48
51
|
|
|
49
52
|
it('does not produce errors for valid conditional rows', function () {
|
|
@@ -174,6 +177,10 @@ This is not a valid row
|
|
|
174
177
|
expect(tableSyntaxErrors.length).toBe(1);
|
|
175
178
|
expect(tableSyntaxErrors[0].error.level).toBe('critical');
|
|
176
179
|
expect(tableSyntaxErrors[0].error.message).toContain('tag callout');
|
|
180
|
+
// Error should point to the callout tag, not the if tag or table
|
|
181
|
+
expect(tableSyntaxErrors[0].location?.start.line).toBe(5);
|
|
182
|
+
expect(tableSyntaxErrors[0].location?.end.line).toBe(6);
|
|
183
|
+
expect(tableSyntaxErrors[0].lines).toEqual([5, 6]);
|
|
177
184
|
});
|
|
178
185
|
|
|
179
186
|
it('produces an error for non-conditional tags at the row level of a table', function () {
|
|
@@ -198,5 +205,9 @@ This is not a valid row
|
|
|
198
205
|
expect(tableSyntaxErrors.length).toBe(1);
|
|
199
206
|
expect(tableSyntaxErrors[0].error.level).toBe('critical');
|
|
200
207
|
expect(tableSyntaxErrors[0].error.message).toContain('tag');
|
|
208
|
+
// Error should point to the callout tag, not the table
|
|
209
|
+
expect(tableSyntaxErrors[0].location?.start.line).toBe(4);
|
|
210
|
+
expect(tableSyntaxErrors[0].location?.end.line).toBe(5);
|
|
211
|
+
expect(tableSyntaxErrors[0].lines).toEqual([4, 5]);
|
|
201
212
|
});
|
|
202
213
|
});
|
package/src/transforms/table.ts
CHANGED
|
@@ -23,19 +23,14 @@ function isComment(node: Node) {
|
|
|
23
23
|
);
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
function unexpectedNodeError({
|
|
27
|
-
type,
|
|
28
|
-
tag,
|
|
29
|
-
}: {
|
|
30
|
-
type: NodeType;
|
|
31
|
-
tag?: string;
|
|
32
|
-
}): ValidationError {
|
|
26
|
+
function unexpectedNodeError(node: Node): ValidationError {
|
|
33
27
|
return {
|
|
34
28
|
id: 'table-syntax',
|
|
35
29
|
level: 'critical',
|
|
36
|
-
message: `Found ${type}${
|
|
37
|
-
tag ? ` ${tag}` : ''
|
|
30
|
+
message: `Found ${node.type}${
|
|
31
|
+
node.tag ? ` ${node.tag}` : ''
|
|
38
32
|
} where a list was expected. Make sure all content inside table cells is indented.`,
|
|
33
|
+
location: node.location,
|
|
39
34
|
};
|
|
40
35
|
}
|
|
41
36
|
|
|
@@ -76,9 +71,7 @@ export default function transform(
|
|
|
76
71
|
) {
|
|
77
72
|
// Allow structural tags: else, nested conditionals, and comments
|
|
78
73
|
} else {
|
|
79
|
-
row.errors.push(
|
|
80
|
-
unexpectedNodeError({ type: child.type, tag: child.tag })
|
|
81
|
-
);
|
|
74
|
+
row.errors.push(unexpectedNodeError(child));
|
|
82
75
|
continue;
|
|
83
76
|
}
|
|
84
77
|
children.push(child);
|
|
@@ -86,7 +79,7 @@ export default function transform(
|
|
|
86
79
|
|
|
87
80
|
row.children = children;
|
|
88
81
|
} else if (row.type !== 'hr' && !isComment(row)) {
|
|
89
|
-
node.errors.push(unexpectedNodeError(
|
|
82
|
+
node.errors.push(unexpectedNodeError(row));
|
|
90
83
|
continue;
|
|
91
84
|
} else continue;
|
|
92
85
|
tbody.push(row);
|
package/src/utils.test.ts
CHANGED