@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/README.md
CHANGED
|
@@ -54,13 +54,7 @@ Check out [our docs](https://markdoc.dev/docs) for more guidance on how to use M
|
|
|
54
54
|
|
|
55
55
|
### TypeScript
|
|
56
56
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
```sh
|
|
60
|
-
npm install @markdoc/markdoc @types/react @types/markdown-it
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
Additionally, this is the minimal `tsconfig.json` required to use Markdoc in your TypeScript project:
|
|
57
|
+
This is the minimal `tsconfig.json` required to use Markdoc in your TypeScript project:
|
|
64
58
|
|
|
65
59
|
```json
|
|
66
60
|
{
|
|
@@ -72,6 +66,14 @@ Additionally, this is the minimal `tsconfig.json` required to use Markdoc in you
|
|
|
72
66
|
}
|
|
73
67
|
```
|
|
74
68
|
|
|
69
|
+
### React
|
|
70
|
+
|
|
71
|
+
If you are using React, install Markdoc with:
|
|
72
|
+
|
|
73
|
+
```sh
|
|
74
|
+
npm install @markdoc/markdoc react @types/react
|
|
75
|
+
```
|
|
76
|
+
|
|
75
77
|
## Contributing
|
|
76
78
|
|
|
77
79
|
Contributions and feedback are welcome and encouraged. Check out our [contributing guidelines](.github/CONTRIBUTING.md) on how to do so.
|
package/dist/index.d.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 * as nodes from './src/schema';
|
|
5
5
|
import renderers from './src/renderers';
|
|
@@ -30,7 +30,7 @@ export declare function createElement(name: string | {
|
|
|
30
30
|
attributes: {};
|
|
31
31
|
children: any[];
|
|
32
32
|
};
|
|
33
|
-
export { nodes, tags, functions, globalAttributes, transforms, renderers, Ast, Tag, Tokenizer, parseTags, transformer, validator, truthy,
|
|
33
|
+
export { nodes, tags, functions, globalAttributes, transforms, renderers, Ast, Tag, Tokenizer, parseTags, transformer, validator, truthy, format, };
|
|
34
34
|
export default class Markdoc {
|
|
35
35
|
static nodes: typeof nodes;
|
|
36
36
|
static tags: {
|
|
@@ -120,7 +120,7 @@ export default class Markdoc {
|
|
|
120
120
|
static validate: typeof validate;
|
|
121
121
|
static createElement: typeof createElement;
|
|
122
122
|
static truthy: typeof truthy;
|
|
123
|
-
static
|
|
123
|
+
static format: typeof format;
|
|
124
124
|
config: Readonly<Partial<{
|
|
125
125
|
nodes: Partial<Record<import("./src/types").NodeType, import("./src/types").Schema<Readonly<Partial<any>>, string>>>;
|
|
126
126
|
tags: Record<string, import("./src/types").Schema<Readonly<Partial<any>>, string>>;
|
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,
|
|
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,OA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|
6603
6603
|
Ast: () => ast_default,
|
|
6604
6604
|
Tag: () => Tag,
|
|
6605
6605
|
Tokenizer: () => Tokenizer,
|
|
6606
|
-
__EXPERIMENTAL__format: () => format,
|
|
6607
6606
|
createElement: () => createElement,
|
|
6608
6607
|
default: () => Markdoc,
|
|
6608
|
+
format: () => format,
|
|
6609
6609
|
functions: () => functions_default,
|
|
6610
6610
|
globalAttributes: () => globalAttributes,
|
|
6611
6611
|
nodes: () => schema_exports,
|
|
@@ -6677,6 +6677,9 @@ var Tag = class {
|
|
|
6677
6677
|
this.children = children;
|
|
6678
6678
|
}
|
|
6679
6679
|
};
|
|
6680
|
+
Tag.isTag = (tag) => {
|
|
6681
|
+
return "$$mdtype" in tag && tag.$$mdtype === "Tag";
|
|
6682
|
+
};
|
|
6680
6683
|
|
|
6681
6684
|
// src/schema-types/class.ts
|
|
6682
6685
|
var Class = class {
|
|
@@ -6702,6 +6705,21 @@ var Class = class {
|
|
|
6702
6705
|
}
|
|
6703
6706
|
};
|
|
6704
6707
|
|
|
6708
|
+
// src/schema-types/id.ts
|
|
6709
|
+
var Id = class {
|
|
6710
|
+
validate(value) {
|
|
6711
|
+
if (typeof value === "string" && value.match(/^[a-zA-Z]/))
|
|
6712
|
+
return [];
|
|
6713
|
+
return [
|
|
6714
|
+
{
|
|
6715
|
+
id: "attribute-value-invalid",
|
|
6716
|
+
level: "error",
|
|
6717
|
+
message: "The 'id' attribute must start with a letter"
|
|
6718
|
+
}
|
|
6719
|
+
];
|
|
6720
|
+
}
|
|
6721
|
+
};
|
|
6722
|
+
|
|
6705
6723
|
// src/utils.ts
|
|
6706
6724
|
var import_tag = __toModule(require_tag());
|
|
6707
6725
|
|
|
@@ -6743,7 +6761,7 @@ var OPEN = "{%";
|
|
|
6743
6761
|
var CLOSE = "%}";
|
|
6744
6762
|
var IDENTIFIER_REGEX = /^[a-zA-Z0-9_-]+$/;
|
|
6745
6763
|
function isIdentifier(s2) {
|
|
6746
|
-
return IDENTIFIER_REGEX.test(s2);
|
|
6764
|
+
return typeof s2 === "string" && IDENTIFIER_REGEX.test(s2);
|
|
6747
6765
|
}
|
|
6748
6766
|
function isPromise(a) {
|
|
6749
6767
|
return a && typeof a === "object" && typeof a.then === "function";
|
|
@@ -6848,7 +6866,7 @@ function parseTags(content, firstLine = 0) {
|
|
|
6848
6866
|
// src/transformer.ts
|
|
6849
6867
|
var globalAttributes = {
|
|
6850
6868
|
class: { type: Class, render: true },
|
|
6851
|
-
id: { type:
|
|
6869
|
+
id: { type: Id, render: true }
|
|
6852
6870
|
};
|
|
6853
6871
|
var transformer_default = {
|
|
6854
6872
|
findSchema(node2, { nodes = {}, tags = {} } = {}) {
|
|
@@ -6978,6 +6996,9 @@ function* formatChildren(a, options) {
|
|
|
6978
6996
|
yield* formatValue(child, options);
|
|
6979
6997
|
}
|
|
6980
6998
|
}
|
|
6999
|
+
function* formatInline(g) {
|
|
7000
|
+
yield [...g].join("").trim();
|
|
7001
|
+
}
|
|
6981
7002
|
function* formatTableRow(items) {
|
|
6982
7003
|
yield `| ${items.join(" | ")} |`;
|
|
6983
7004
|
}
|
|
@@ -7027,8 +7048,10 @@ function* formatVariable(v) {
|
|
|
7027
7048
|
yield v.path.map((p, i) => {
|
|
7028
7049
|
if (i === 0)
|
|
7029
7050
|
return p;
|
|
7030
|
-
if (isIdentifier(
|
|
7051
|
+
if (isIdentifier(p))
|
|
7031
7052
|
return "." + p;
|
|
7053
|
+
if (typeof p === "number")
|
|
7054
|
+
return `[${p}]`;
|
|
7032
7055
|
return `["${p}"]`;
|
|
7033
7056
|
}).join("");
|
|
7034
7057
|
}
|
|
@@ -7049,6 +7072,9 @@ function* trimStart(g) {
|
|
|
7049
7072
|
yield n;
|
|
7050
7073
|
yield* g;
|
|
7051
7074
|
}
|
|
7075
|
+
function* escapeMarkdownCharacters(s2, characters) {
|
|
7076
|
+
yield s2.replace(characters, "\\$&").replace(new RegExp("\xA0", "g"), " ");
|
|
7077
|
+
}
|
|
7052
7078
|
function* formatNode(n, o = {}) {
|
|
7053
7079
|
const no = { ...o, parent: n };
|
|
7054
7080
|
const indent = SPACE.repeat(no.indent || 0);
|
|
@@ -7065,20 +7091,20 @@ function* formatNode(n, o = {}) {
|
|
|
7065
7091
|
yield indent;
|
|
7066
7092
|
yield "#".repeat(n.attributes.level || 1);
|
|
7067
7093
|
yield SPACE;
|
|
7068
|
-
yield* formatChildren(n, no);
|
|
7094
|
+
yield* trimStart(formatChildren(n, no));
|
|
7069
7095
|
yield* formatAnnotations(n);
|
|
7070
7096
|
yield NL;
|
|
7071
7097
|
break;
|
|
7072
7098
|
}
|
|
7073
7099
|
case "paragraph": {
|
|
7074
7100
|
yield NL;
|
|
7075
|
-
yield indent;
|
|
7076
7101
|
yield* formatChildren(n, no);
|
|
7077
7102
|
yield* formatAnnotations(n);
|
|
7078
7103
|
yield NL;
|
|
7079
7104
|
break;
|
|
7080
7105
|
}
|
|
7081
7106
|
case "inline": {
|
|
7107
|
+
yield indent;
|
|
7082
7108
|
yield* formatChildren(n, no);
|
|
7083
7109
|
break;
|
|
7084
7110
|
}
|
|
@@ -7088,7 +7114,7 @@ function* formatNode(n, o = {}) {
|
|
|
7088
7114
|
yield* formatValue(n.attributes.alt, no);
|
|
7089
7115
|
yield "]";
|
|
7090
7116
|
yield "(";
|
|
7091
|
-
yield* formatValue(n.attributes.src, no);
|
|
7117
|
+
yield* typeof n.attributes.src === "string" ? escapeMarkdownCharacters(n.attributes.src, /[()]/) : formatValue(n.attributes.src, no);
|
|
7092
7118
|
if (n.attributes.title) {
|
|
7093
7119
|
yield SPACE + `"${n.attributes.title}"`;
|
|
7094
7120
|
}
|
|
@@ -7100,7 +7126,7 @@ function* formatNode(n, o = {}) {
|
|
|
7100
7126
|
yield* formatChildren(n, no);
|
|
7101
7127
|
yield "]";
|
|
7102
7128
|
yield "(";
|
|
7103
|
-
yield* formatValue(n.attributes.href, no);
|
|
7129
|
+
yield* typeof n.attributes.href === "string" ? escapeMarkdownCharacters(n.attributes.href, /[()]/g) : formatValue(n.attributes.href, no);
|
|
7104
7130
|
if (n.attributes.title) {
|
|
7105
7131
|
yield SPACE + `"${n.attributes.title}"`;
|
|
7106
7132
|
}
|
|
@@ -7108,10 +7134,11 @@ function* formatNode(n, o = {}) {
|
|
|
7108
7134
|
break;
|
|
7109
7135
|
}
|
|
7110
7136
|
case "text": {
|
|
7111
|
-
|
|
7137
|
+
const { content } = n.attributes;
|
|
7138
|
+
if (ast_default.isAst(content))
|
|
7112
7139
|
yield OPEN + SPACE;
|
|
7113
|
-
yield* formatValue(
|
|
7114
|
-
if (ast_default.isAst(
|
|
7140
|
+
yield* typeof content === "string" ? escapeMarkdownCharacters(content, /[_*~]/g) : formatValue(content, no);
|
|
7141
|
+
if (ast_default.isAst(content))
|
|
7115
7142
|
yield SPACE + CLOSE;
|
|
7116
7143
|
break;
|
|
7117
7144
|
}
|
|
@@ -7132,15 +7159,19 @@ function* formatNode(n, o = {}) {
|
|
|
7132
7159
|
case "fence": {
|
|
7133
7160
|
yield NL;
|
|
7134
7161
|
yield indent;
|
|
7135
|
-
|
|
7136
|
-
|
|
7162
|
+
const innerFence = n.attributes.content.match(/`{3,}/g) || [];
|
|
7163
|
+
const innerFenceLength = innerFence.map((s2) => s2.length).reduce(max, 0);
|
|
7164
|
+
const boundary = "`".repeat(innerFenceLength ? innerFenceLength + 1 : 3);
|
|
7165
|
+
yield boundary;
|
|
7166
|
+
if (n.attributes.language)
|
|
7167
|
+
yield n.attributes.language;
|
|
7137
7168
|
if (n.annotations.length)
|
|
7138
7169
|
yield SPACE;
|
|
7139
7170
|
yield* formatAnnotations(n);
|
|
7140
7171
|
yield NL;
|
|
7141
7172
|
yield indent;
|
|
7142
7173
|
yield n.attributes.content.split(NL).join(NL + indent);
|
|
7143
|
-
yield
|
|
7174
|
+
yield boundary;
|
|
7144
7175
|
yield NL;
|
|
7145
7176
|
break;
|
|
7146
7177
|
}
|
|
@@ -7153,7 +7184,7 @@ function* formatNode(n, o = {}) {
|
|
|
7153
7184
|
const tag = [open + n.tag, ...formatAttributes(n)];
|
|
7154
7185
|
const inlineTag = tag.join(SPACE);
|
|
7155
7186
|
const isLongTagOpening = inlineTag.length + open.length * 2 > (o.maxTagOpeningWidth || MAX_TAG_OPENING_WIDTH);
|
|
7156
|
-
yield (isLongTagOpening ? tag.join(NL + SPACE.repeat(open.length) + indent) : inlineTag) + SPACE + (n.children.length ? "" : "/") + CLOSE;
|
|
7187
|
+
yield (!n.inline && isLongTagOpening ? tag.join(NL + SPACE.repeat(open.length) + indent) : inlineTag) + SPACE + (n.children.length ? "" : "/") + CLOSE;
|
|
7157
7188
|
if (n.children.length) {
|
|
7158
7189
|
yield* formatChildren(n, no.allowIndentation ? increment(no) : no);
|
|
7159
7190
|
if (!n.inline) {
|
|
@@ -7168,18 +7199,16 @@ function* formatNode(n, o = {}) {
|
|
|
7168
7199
|
}
|
|
7169
7200
|
case "list": {
|
|
7170
7201
|
const prefix = n.attributes.ordered ? OL : UL;
|
|
7171
|
-
yield NL;
|
|
7172
7202
|
for (const child of n.children) {
|
|
7173
7203
|
const d = format(child, increment(no, prefix.length)).trim();
|
|
7174
|
-
yield indent + prefix + d;
|
|
7175
|
-
yield NL;
|
|
7204
|
+
yield NL + indent + prefix + d;
|
|
7176
7205
|
}
|
|
7206
|
+
yield NL;
|
|
7177
7207
|
break;
|
|
7178
7208
|
}
|
|
7179
7209
|
case "item": {
|
|
7180
7210
|
for (let i = 0; i < n.children.length; i++) {
|
|
7181
|
-
|
|
7182
|
-
yield* formatValue(child, no);
|
|
7211
|
+
yield* formatValue(n.children[i], no);
|
|
7183
7212
|
if (i === 0)
|
|
7184
7213
|
yield* formatAnnotations(n);
|
|
7185
7214
|
}
|
|
@@ -7187,25 +7216,25 @@ function* formatNode(n, o = {}) {
|
|
|
7187
7216
|
}
|
|
7188
7217
|
case "strong": {
|
|
7189
7218
|
yield "**";
|
|
7190
|
-
yield* formatChildren(n, no);
|
|
7219
|
+
yield* formatInline(formatChildren(n, no));
|
|
7191
7220
|
yield "**";
|
|
7192
7221
|
break;
|
|
7193
7222
|
}
|
|
7194
7223
|
case "em": {
|
|
7195
7224
|
yield "_";
|
|
7196
|
-
yield* formatChildren(n, no);
|
|
7225
|
+
yield* formatInline(formatChildren(n, no));
|
|
7197
7226
|
yield "_";
|
|
7198
7227
|
break;
|
|
7199
7228
|
}
|
|
7200
7229
|
case "code": {
|
|
7201
7230
|
yield "`";
|
|
7202
|
-
yield* formatValue(n.attributes.content, no);
|
|
7231
|
+
yield* formatInline(formatValue(n.attributes.content, no));
|
|
7203
7232
|
yield "`";
|
|
7204
7233
|
break;
|
|
7205
7234
|
}
|
|
7206
7235
|
case "s": {
|
|
7207
7236
|
yield "~~";
|
|
7208
|
-
yield* formatChildren(n, no);
|
|
7237
|
+
yield* formatInline(formatChildren(n, no));
|
|
7209
7238
|
yield "~~";
|
|
7210
7239
|
break;
|
|
7211
7240
|
}
|
|
@@ -7234,10 +7263,8 @@ function* formatNode(n, o = {}) {
|
|
|
7234
7263
|
yield NL;
|
|
7235
7264
|
yield indent + "---";
|
|
7236
7265
|
}
|
|
7237
|
-
for (
|
|
7238
|
-
|
|
7239
|
-
yield NL;
|
|
7240
|
-
yield indent + UL + d.trim();
|
|
7266
|
+
for (const d of row) {
|
|
7267
|
+
yield NL + indent + UL + d;
|
|
7241
7268
|
}
|
|
7242
7269
|
}
|
|
7243
7270
|
}
|
|
@@ -7268,7 +7295,7 @@ function* formatNode(n, o = {}) {
|
|
|
7268
7295
|
}
|
|
7269
7296
|
case "td":
|
|
7270
7297
|
case "th": {
|
|
7271
|
-
yield [...formatChildren(n, no), ...formatAnnotations(n)].join("");
|
|
7298
|
+
yield [...formatChildren(n, no), ...formatAnnotations(n)].join("").trim();
|
|
7272
7299
|
break;
|
|
7273
7300
|
}
|
|
7274
7301
|
case "tbody": {
|
|
@@ -7495,7 +7522,7 @@ function handleAttrs(token, type) {
|
|
|
7495
7522
|
return { content: (token.meta || {}).variable || token.content };
|
|
7496
7523
|
case "fence": {
|
|
7497
7524
|
const [language] = token.info.split(" ", 1);
|
|
7498
|
-
return language === "" ? { content: token.content } : { content: token.content, language };
|
|
7525
|
+
return language === "" || language === OPEN ? { content: token.content } : { content: token.content, language };
|
|
7499
7526
|
}
|
|
7500
7527
|
case "td":
|
|
7501
7528
|
case "th": {
|
|
@@ -7865,11 +7892,11 @@ var voidElements = new Set([
|
|
|
7865
7892
|
"wbr"
|
|
7866
7893
|
]);
|
|
7867
7894
|
function render(node2) {
|
|
7868
|
-
if (typeof node2 === "string")
|
|
7869
|
-
return escapeHtml(node2);
|
|
7895
|
+
if (typeof node2 === "string" || typeof node2 === "number")
|
|
7896
|
+
return escapeHtml(String(node2));
|
|
7870
7897
|
if (Array.isArray(node2))
|
|
7871
7898
|
return node2.map(render).join("");
|
|
7872
|
-
if (node2 === null || typeof node2 !== "object")
|
|
7899
|
+
if (node2 === null || typeof node2 !== "object" || !Tag.isTag(node2))
|
|
7873
7900
|
return "";
|
|
7874
7901
|
const { name, attributes, children = [] } = node2;
|
|
7875
7902
|
if (!name)
|
|
@@ -7886,12 +7913,10 @@ function render(node2) {
|
|
|
7886
7913
|
return output;
|
|
7887
7914
|
}
|
|
7888
7915
|
|
|
7889
|
-
// src/renderers/react/
|
|
7916
|
+
// src/renderers/react/react.ts
|
|
7890
7917
|
function tagName(name, components) {
|
|
7891
|
-
return typeof name !== "string" ?
|
|
7918
|
+
return typeof name !== "string" ? name : name[0] !== name[0].toUpperCase() ? name : components instanceof Function ? components(name) : components[name];
|
|
7892
7919
|
}
|
|
7893
|
-
|
|
7894
|
-
// src/renderers/react/react.ts
|
|
7895
7920
|
function dynamic(node2, React, { components = {} } = {}) {
|
|
7896
7921
|
function deepRender2(value) {
|
|
7897
7922
|
if (value == null || typeof value !== "object")
|
|
@@ -7910,7 +7935,7 @@ function dynamic(node2, React, { components = {} } = {}) {
|
|
|
7910
7935
|
function render3(node3) {
|
|
7911
7936
|
if (Array.isArray(node3))
|
|
7912
7937
|
return React.createElement(React.Fragment, null, ...node3.map(render3));
|
|
7913
|
-
if (node3 === null || typeof node3 !== "object")
|
|
7938
|
+
if (node3 === null || typeof node3 !== "object" || !Tag.isTag(node3))
|
|
7914
7939
|
return node3;
|
|
7915
7940
|
const {
|
|
7916
7941
|
name,
|
|
@@ -7925,6 +7950,9 @@ function dynamic(node2, React, { components = {} } = {}) {
|
|
|
7925
7950
|
}
|
|
7926
7951
|
|
|
7927
7952
|
// src/renderers/react/static.ts
|
|
7953
|
+
function tagName2(name, components) {
|
|
7954
|
+
return typeof name !== "string" ? "Fragment" : name[0] !== name[0].toUpperCase() ? name : components instanceof Function ? components(name) : components[name];
|
|
7955
|
+
}
|
|
7928
7956
|
function renderArray(children) {
|
|
7929
7957
|
return children.map(render2).join(", ");
|
|
7930
7958
|
}
|
|
@@ -7943,7 +7971,7 @@ function deepRender(value) {
|
|
|
7943
7971
|
function render2(node2) {
|
|
7944
7972
|
if (Array.isArray(node2))
|
|
7945
7973
|
return `React.createElement(React.Fragment, null, ${renderArray(node2)})`;
|
|
7946
|
-
if (node2 === null || typeof node2 !== "object")
|
|
7974
|
+
if (node2 === null || typeof node2 !== "object" || !Tag.isTag(node2))
|
|
7947
7975
|
return JSON.stringify(node2);
|
|
7948
7976
|
const {
|
|
7949
7977
|
name,
|
|
@@ -7960,7 +7988,7 @@ function render2(node2) {
|
|
|
7960
7988
|
function reactStatic(node2) {
|
|
7961
7989
|
return `
|
|
7962
7990
|
(({components = {}} = {}) => {
|
|
7963
|
-
${
|
|
7991
|
+
${tagName2}
|
|
7964
7992
|
return ${render2(node2)};
|
|
7965
7993
|
})
|
|
7966
7994
|
`;
|
|
@@ -7986,6 +8014,7 @@ var PartialFile = class {
|
|
|
7986
8014
|
}
|
|
7987
8015
|
};
|
|
7988
8016
|
var partial = {
|
|
8017
|
+
inline: false,
|
|
7989
8018
|
selfClosing: true,
|
|
7990
8019
|
attributes: {
|
|
7991
8020
|
file: { type: PartialFile, render: false, required: true },
|
|
@@ -8012,7 +8041,8 @@ var partial = {
|
|
|
8012
8041
|
|
|
8013
8042
|
// src/tags/table.ts
|
|
8014
8043
|
var table2 = {
|
|
8015
|
-
children: ["table"]
|
|
8044
|
+
children: ["table"],
|
|
8045
|
+
inline: false
|
|
8016
8046
|
};
|
|
8017
8047
|
|
|
8018
8048
|
// src/tags/index.ts
|
|
@@ -8027,10 +8057,10 @@ var tags_default = {
|
|
|
8027
8057
|
var import_lib = __toModule(require_lib());
|
|
8028
8058
|
|
|
8029
8059
|
// src/tokenizer/plugins/annotations.ts
|
|
8030
|
-
var
|
|
8060
|
+
var import_tag7 = __toModule(require_tag());
|
|
8031
8061
|
function createToken(state, content, contentStart) {
|
|
8032
8062
|
try {
|
|
8033
|
-
const { type, meta, nesting = 0 } = (0,
|
|
8063
|
+
const { type, meta, nesting = 0 } = (0, import_tag7.parse)(content, { Variable, Function: Function2 });
|
|
8034
8064
|
const token = state.push(type, "", nesting);
|
|
8035
8065
|
token.info = content;
|
|
8036
8066
|
token.meta = meta;
|
|
@@ -8039,7 +8069,7 @@ function createToken(state, content, contentStart) {
|
|
|
8039
8069
|
}
|
|
8040
8070
|
return token;
|
|
8041
8071
|
} catch (error2) {
|
|
8042
|
-
if (!(error2 instanceof
|
|
8072
|
+
if (!(error2 instanceof import_tag7.SyntaxError))
|
|
8043
8073
|
throw error2;
|
|
8044
8074
|
const {
|
|
8045
8075
|
message,
|
|
@@ -8097,10 +8127,10 @@ function core(state) {
|
|
|
8097
8127
|
const end = findTagEnd(token.info, start);
|
|
8098
8128
|
const content = token.info.slice(start + OPEN.length, end);
|
|
8099
8129
|
try {
|
|
8100
|
-
const { meta } = (0,
|
|
8130
|
+
const { meta } = (0, import_tag7.parse)(content.trim(), { Variable, Function: Function2 });
|
|
8101
8131
|
token.meta = meta;
|
|
8102
8132
|
} catch (error2) {
|
|
8103
|
-
if (!(error2 instanceof
|
|
8133
|
+
if (!(error2 instanceof import_tag7.SyntaxError))
|
|
8104
8134
|
throw error2;
|
|
8105
8135
|
if (!token.errors)
|
|
8106
8136
|
token.errors = [];
|
|
@@ -8306,6 +8336,12 @@ function validator(node2, config) {
|
|
|
8306
8336
|
});
|
|
8307
8337
|
return errors;
|
|
8308
8338
|
}
|
|
8339
|
+
if (schema.inline != void 0 && node2.inline !== schema.inline)
|
|
8340
|
+
errors.push({
|
|
8341
|
+
id: "tag-placement-invalid",
|
|
8342
|
+
level: "critical",
|
|
8343
|
+
message: `'${node2.tag}' tag should be ${schema.inline ? "inline" : "block"}`
|
|
8344
|
+
});
|
|
8309
8345
|
if (schema.selfClosing && node2.children.length > 0)
|
|
8310
8346
|
errors.push({
|
|
8311
8347
|
id: "tag-selfclosing-has-children",
|
|
@@ -8351,12 +8387,6 @@ function validator(node2, config) {
|
|
|
8351
8387
|
continue;
|
|
8352
8388
|
}
|
|
8353
8389
|
value = value;
|
|
8354
|
-
if (key === "id" && value.match(/^[0-9]/))
|
|
8355
|
-
errors.push({
|
|
8356
|
-
id: "attribute-value-invalid",
|
|
8357
|
-
level: "error",
|
|
8358
|
-
message: "The id attribute must not start with a number"
|
|
8359
|
-
});
|
|
8360
8390
|
if (type) {
|
|
8361
8391
|
const valid = validateType(type, value, config);
|
|
8362
8392
|
if (valid === false) {
|
|
@@ -8490,4 +8520,4 @@ Markdoc.transform = transform2;
|
|
|
8490
8520
|
Markdoc.validate = validate;
|
|
8491
8521
|
Markdoc.createElement = createElement;
|
|
8492
8522
|
Markdoc.truthy = truthy;
|
|
8493
|
-
Markdoc.
|
|
8523
|
+
Markdoc.format = format;
|