@markdoc/markdoc 0.4.0 → 0.5.1
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 +10 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +25 -6
- package/dist/index.js.map +2 -2
- package/dist/index.mjs +25 -6
- package/dist/index.mjs.map +2 -2
- package/dist/react.js +2 -2
- package/dist/react.js.map +2 -2
- package/dist/src/ast/index.d.ts +1 -1
- package/dist/src/formatter.d.ts +1 -0
- package/dist/src/formatter.d.ts.map +1 -1
- package/dist/src/renderers/react/react.d.ts +8 -4
- package/dist/src/renderers/react/react.d.ts.map +1 -1
- package/dist/src/renderers/react/static.d.ts +7 -1
- package/dist/src/renderers/react/static.d.ts.map +1 -1
- package/dist/src/tags/index.d.ts +5 -5
- package/dist/src/types.d.ts +3 -3
- package/dist/src/types.d.ts.map +1 -1
- package/index.ts +3 -1
- package/package.json +3 -2
- package/src/formatter.test.ts +49 -0
- package/src/formatter.ts +20 -6
- package/src/renderers/react/react.test.ts +32 -0
- package/src/renderers/react/react.ts +7 -3
- package/src/renderers/react/static.ts +10 -2
- package/src/types.ts +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import Ast from './src/ast';
|
|
2
|
+
import Node from './src/ast/node';
|
|
2
3
|
import format from './src/formatter';
|
|
3
4
|
import functions from './src/functions';
|
|
4
5
|
import * as nodes from './src/schema';
|
|
@@ -11,7 +12,7 @@ import transformer, { globalAttributes } from './src/transformer';
|
|
|
11
12
|
import transforms from './src/transforms';
|
|
12
13
|
import { parseTags } from './src/utils';
|
|
13
14
|
import validator from './src/validator';
|
|
14
|
-
import type {
|
|
15
|
+
import type { ParserArgs } from './src/types';
|
|
15
16
|
import type Token from 'markdown-it/lib/token';
|
|
16
17
|
import type { Config, RenderableTreeNode, ValidateError } from './src/types';
|
|
17
18
|
export * from './src/types';
|
|
@@ -30,12 +31,12 @@ export declare function createElement(name: string | {
|
|
|
30
31
|
attributes: {};
|
|
31
32
|
children: any[];
|
|
32
33
|
};
|
|
33
|
-
export { nodes, tags, functions, globalAttributes, transforms, renderers, Ast, Tag, Tokenizer, parseTags, transformer, validator, truthy, format, };
|
|
34
|
+
export { nodes, tags, functions, globalAttributes, transforms, renderers, Ast, Node, Tag, Tokenizer, parseTags, transformer, validator, truthy, format, };
|
|
34
35
|
export default class Markdoc {
|
|
35
36
|
static nodes: typeof nodes;
|
|
36
37
|
static tags: {
|
|
37
38
|
else: import("./src/types").Schema<Readonly<Partial<{
|
|
38
|
-
nodes: Partial<Record<import("./src/types").NodeType, import("./src/types").Schema<
|
|
39
|
+
nodes: Partial<Record<import("./src/types").NodeType, import("./src/types").Schema<Partial<any>, string>>>;
|
|
39
40
|
tags: Record<string, import("./src/types").Schema<Readonly<Partial<any>>, string>>;
|
|
40
41
|
variables: Record<string, any>;
|
|
41
42
|
functions: Record<string, import("./src/types").ConfigFunction>;
|
|
@@ -47,7 +48,7 @@ export default class Markdoc {
|
|
|
47
48
|
} | undefined;
|
|
48
49
|
}>>, string>;
|
|
49
50
|
if: import("./src/types").Schema<Readonly<Partial<{
|
|
50
|
-
nodes: Partial<Record<import("./src/types").NodeType, import("./src/types").Schema<
|
|
51
|
+
nodes: Partial<Record<import("./src/types").NodeType, import("./src/types").Schema<Partial<any>, string>>>;
|
|
51
52
|
tags: Record<string, import("./src/types").Schema<Readonly<Partial<any>>, string>>;
|
|
52
53
|
variables: Record<string, any>;
|
|
53
54
|
functions: Record<string, import("./src/types").ConfigFunction>;
|
|
@@ -59,7 +60,7 @@ export default class Markdoc {
|
|
|
59
60
|
} | undefined;
|
|
60
61
|
}>>, string>;
|
|
61
62
|
partial: import("./src/types").Schema<Readonly<Partial<{
|
|
62
|
-
nodes: Partial<Record<import("./src/types").NodeType, import("./src/types").Schema<
|
|
63
|
+
nodes: Partial<Record<import("./src/types").NodeType, import("./src/types").Schema<Partial<any>, string>>>;
|
|
63
64
|
tags: Record<string, import("./src/types").Schema<Readonly<Partial<any>>, string>>;
|
|
64
65
|
variables: Record<string, any>;
|
|
65
66
|
functions: Record<string, import("./src/types").ConfigFunction>;
|
|
@@ -71,7 +72,7 @@ export default class Markdoc {
|
|
|
71
72
|
} | undefined;
|
|
72
73
|
}>>, string>;
|
|
73
74
|
slot: import("./src/types").Schema<Readonly<Partial<{
|
|
74
|
-
nodes: Partial<Record<import("./src/types").NodeType, import("./src/types").Schema<
|
|
75
|
+
nodes: Partial<Record<import("./src/types").NodeType, import("./src/types").Schema<Partial<any>, string>>>;
|
|
75
76
|
tags: Record<string, import("./src/types").Schema<Readonly<Partial<any>>, string>>;
|
|
76
77
|
variables: Record<string, any>;
|
|
77
78
|
functions: Record<string, import("./src/types").ConfigFunction>;
|
|
@@ -83,7 +84,7 @@ export default class Markdoc {
|
|
|
83
84
|
} | undefined;
|
|
84
85
|
}>>, string>;
|
|
85
86
|
table: import("./src/types").Schema<Readonly<Partial<{
|
|
86
|
-
nodes: Partial<Record<import("./src/types").NodeType, import("./src/types").Schema<
|
|
87
|
+
nodes: Partial<Record<import("./src/types").NodeType, import("./src/types").Schema<Partial<any>, string>>>;
|
|
87
88
|
tags: Record<string, import("./src/types").Schema<Readonly<Partial<any>>, string>>;
|
|
88
89
|
variables: Record<string, any>;
|
|
89
90
|
functions: Record<string, import("./src/types").ConfigFunction>;
|
|
@@ -117,7 +118,7 @@ export default class Markdoc {
|
|
|
117
118
|
isVariable(value?: any): value is import("./src/ast/variable").default;
|
|
118
119
|
getAstValues(value: any): Generator<import("./src/types").AstType, void, unknown>;
|
|
119
120
|
resolve(value: any, config?: Readonly<Partial<{
|
|
120
|
-
nodes: Partial<Record<import("./src/types").NodeType, import("./src/types").Schema<
|
|
121
|
+
nodes: Partial<Record<import("./src/types").NodeType, import("./src/types").Schema<Partial<any>, string>>>;
|
|
121
122
|
tags: Record<string, import("./src/types").Schema<Readonly<Partial<any>>, string>>;
|
|
122
123
|
variables: Record<string, any>;
|
|
123
124
|
functions: Record<string, import("./src/types").ConfigFunction>;
|
|
@@ -144,7 +145,7 @@ export default class Markdoc {
|
|
|
144
145
|
static truthy: typeof truthy;
|
|
145
146
|
static format: typeof format;
|
|
146
147
|
config: Readonly<Partial<{
|
|
147
|
-
nodes: Partial<Record<import("./src/types").NodeType, import("./src/types").Schema<
|
|
148
|
+
nodes: Partial<Record<import("./src/types").NodeType, import("./src/types").Schema<Partial<any>, string>>>;
|
|
148
149
|
tags: Record<string, import("./src/types").Schema<Readonly<Partial<any>>, string>>;
|
|
149
150
|
variables: Record<string, any>;
|
|
150
151
|
functions: Record<string, import("./src/types").ConfigFunction>;
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,WAAW,CAAC;AAC5B,OAAO,MAAM,MAAM,iBAAiB,CAAC;AACrC,OAAO,SAAS,MAAM,iBAAiB,CAAC;AAExC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AACtC,OAAO,SAAS,MAAM,iBAAiB,CAAC;AACxC,OAAO,GAAG,MAAM,WAAW,CAAC;AAC5B,OAAO,IAAI,MAAM,YAAY,CAAC;AAC9B,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAChD,OAAO,SAAS,MAAM,iBAAiB,CAAC;AACxC,OAAO,WAAW,EAAE,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAClE,OAAO,UAAU,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,SAA2B,MAAM,iBAAiB,CAAC;AAE1D,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,WAAW,CAAC;AAC5B,OAAO,IAAI,MA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,mBAAa;IAC7B,MAAM,CAAC,QAAQ,kBAAY;IAC3B,MAAM,CAAC,aAAa,uBAAiB;IACrC,MAAM,CAAC,MAAM,gBAAU;IACvB,MAAM,CAAC,MAAM,gBAAU;IAEvB,MAAM;;;;;;;;;;;QAAC;gBACK,MAAM,EAAE,MAAM;IAI1B,KAAK,eAAS;IACd,OAAO,YAAa,WAAW,cAAc,CAAC,CAAC,CAAC,CAAC,YACjB;IAChC,SAAS,YAAa,WAAW,gBAAgB,CAAC,CAAC,CAAC,CAAC,0BACnB;IAClC,QAAQ,YAAa,WAAW,eAAe,CAAC,CAAC,CAAC,CAAC,qBAClB;CAClC"}
|
package/dist/index.js
CHANGED
|
@@ -6655,6 +6655,7 @@ var require_markdown_it = __commonJS({
|
|
|
6655
6655
|
// index.ts
|
|
6656
6656
|
__export(exports, {
|
|
6657
6657
|
Ast: () => ast_default,
|
|
6658
|
+
Node: () => Node,
|
|
6658
6659
|
Tag: () => Tag,
|
|
6659
6660
|
Tokenizer: () => Tokenizer,
|
|
6660
6661
|
createElement: () => createElement,
|
|
@@ -7189,7 +7190,7 @@ function* formatNode(n, o = {}) {
|
|
|
7189
7190
|
yield* formatValue(n.attributes.alt, no);
|
|
7190
7191
|
yield "]";
|
|
7191
7192
|
yield "(";
|
|
7192
|
-
yield* typeof n.attributes.src === "string" ? escapeMarkdownCharacters(n.attributes.src, /[()]/) : formatValue(n.attributes.src, no);
|
|
7193
|
+
yield* typeof n.attributes.src === "string" ? escapeMarkdownCharacters(n.attributes.src, /[()]/g) : formatValue(n.attributes.src, no);
|
|
7193
7194
|
if (n.attributes.title) {
|
|
7194
7195
|
yield SPACE + `"${n.attributes.title}"`;
|
|
7195
7196
|
}
|
|
@@ -7241,6 +7242,7 @@ function* formatNode(n, o = {}) {
|
|
|
7241
7242
|
const innerFence = n.attributes.content.match(/`{3,}/g) || [];
|
|
7242
7243
|
const innerFenceLength = innerFence.map((s2) => s2.length).reduce(max, 0);
|
|
7243
7244
|
const boundary = "`".repeat(innerFenceLength ? innerFenceLength + 1 : 3);
|
|
7245
|
+
const needsNlBeforeEndBoundary = !n.attributes.content.endsWith(NL);
|
|
7244
7246
|
yield boundary;
|
|
7245
7247
|
if (n.attributes.language)
|
|
7246
7248
|
yield n.attributes.language;
|
|
@@ -7250,6 +7252,9 @@ function* formatNode(n, o = {}) {
|
|
|
7250
7252
|
yield NL;
|
|
7251
7253
|
yield indent;
|
|
7252
7254
|
yield n.attributes.content.split(NL).join(NL + indent);
|
|
7255
|
+
if (needsNlBeforeEndBoundary) {
|
|
7256
|
+
yield NL;
|
|
7257
|
+
}
|
|
7253
7258
|
yield boundary;
|
|
7254
7259
|
yield NL;
|
|
7255
7260
|
break;
|
|
@@ -7280,7 +7285,18 @@ function* formatNode(n, o = {}) {
|
|
|
7280
7285
|
case "list": {
|
|
7281
7286
|
const isLoose = n.children.some((n2) => n2.children.some((c) => c.type === "paragraph"));
|
|
7282
7287
|
for (let i = 0; i < n.children.length; i++) {
|
|
7283
|
-
const prefix =
|
|
7288
|
+
const prefix = (() => {
|
|
7289
|
+
if (!n.attributes.ordered)
|
|
7290
|
+
return n.attributes.marker ?? UL;
|
|
7291
|
+
let number = "1";
|
|
7292
|
+
const startNumber = n.attributes.start ?? 1;
|
|
7293
|
+
if (i === 0)
|
|
7294
|
+
number = startNumber.toString();
|
|
7295
|
+
if (o.orderedListMode === "increment") {
|
|
7296
|
+
number = (parseInt(startNumber) + i).toString();
|
|
7297
|
+
}
|
|
7298
|
+
return `${number}${n.attributes.marker ?? OL}`;
|
|
7299
|
+
})();
|
|
7284
7300
|
let d = format(n.children[i], increment(no, prefix.length + 1));
|
|
7285
7301
|
if (!isLoose || i === n.children.length - 1) {
|
|
7286
7302
|
d = d.trim();
|
|
@@ -8036,7 +8052,7 @@ function render(node2) {
|
|
|
8036
8052
|
function tagName(name, components) {
|
|
8037
8053
|
return typeof name !== "string" ? name : name[0] !== name[0].toUpperCase() ? name : components instanceof Function ? components(name) : components[name];
|
|
8038
8054
|
}
|
|
8039
|
-
function dynamic(node2, React, { components = {} } = {}) {
|
|
8055
|
+
function dynamic(node2, React, { components = {}, resolveTagName = tagName } = {}) {
|
|
8040
8056
|
function deepRender2(value) {
|
|
8041
8057
|
if (value == null || typeof value !== "object")
|
|
8042
8058
|
return value;
|
|
@@ -8063,7 +8079,7 @@ function dynamic(node2, React, { components = {} } = {}) {
|
|
|
8063
8079
|
} = node3;
|
|
8064
8080
|
if (className)
|
|
8065
8081
|
attrs.className = className;
|
|
8066
|
-
return React.createElement(
|
|
8082
|
+
return React.createElement(resolveTagName(name, components), Object.keys(attrs).length == 0 ? null : deepRender2(attrs), ...children.map(render3));
|
|
8067
8083
|
}
|
|
8068
8084
|
return render3(node2);
|
|
8069
8085
|
}
|
|
@@ -8104,10 +8120,13 @@ function render2(node2) {
|
|
|
8104
8120
|
${Object.keys(attrs).length == 0 ? "null" : deepRender(attrs)},
|
|
8105
8121
|
${renderArray(children)})`;
|
|
8106
8122
|
}
|
|
8107
|
-
function reactStatic(node2) {
|
|
8123
|
+
function reactStatic(node2, { resolveTagName = tagName2 } = {}) {
|
|
8124
|
+
if (resolveTagName.name !== "tagName") {
|
|
8125
|
+
throw new Error("resolveTagName must be named tagName");
|
|
8126
|
+
}
|
|
8108
8127
|
return `
|
|
8109
8128
|
(({components = {}} = {}) => {
|
|
8110
|
-
${
|
|
8129
|
+
${resolveTagName}
|
|
8111
8130
|
return ${render2(node2)};
|
|
8112
8131
|
})
|
|
8113
8132
|
`;
|