@markdoc/markdoc 0.1.13 → 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 +45 -29
- package/dist/index.js.map +3 -3
- package/dist/index.mjs +45 -29
- 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/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/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/transformer.d.ts.map +1 -1
- package/dist/src/types.d.ts +1 -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/index.ts +3 -3
- package/package.json +10 -3
- package/src/formatter.test.ts +70 -7
- package/src/formatter.ts +41 -12
- package/src/renderers/html.test.ts +10 -6
- package/src/renderers/html.ts +3 -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/tag.ts +4 -0
- package/src/tags/conditional.ts +11 -2
- package/src/transformer.ts +12 -2
- package/src/types.ts +1 -1
- package/src/utils.ts +2 -2
- 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/index.mjs
CHANGED
|
@@ -6653,6 +6653,9 @@ var Tag = class {
|
|
|
6653
6653
|
this.children = children;
|
|
6654
6654
|
}
|
|
6655
6655
|
};
|
|
6656
|
+
Tag.isTag = (tag) => {
|
|
6657
|
+
return "$$mdtype" in tag && tag.$$mdtype === "Tag";
|
|
6658
|
+
};
|
|
6656
6659
|
|
|
6657
6660
|
// src/schema-types/class.ts
|
|
6658
6661
|
var Class = class {
|
|
@@ -6734,7 +6737,7 @@ var OPEN = "{%";
|
|
|
6734
6737
|
var CLOSE = "%}";
|
|
6735
6738
|
var IDENTIFIER_REGEX = /^[a-zA-Z0-9_-]+$/;
|
|
6736
6739
|
function isIdentifier(s2) {
|
|
6737
|
-
return IDENTIFIER_REGEX.test(s2);
|
|
6740
|
+
return typeof s2 === "string" && IDENTIFIER_REGEX.test(s2);
|
|
6738
6741
|
}
|
|
6739
6742
|
function isPromise(a) {
|
|
6740
6743
|
return a && typeof a === "object" && typeof a.then === "function";
|
|
@@ -6969,6 +6972,9 @@ function* formatChildren(a, options) {
|
|
|
6969
6972
|
yield* formatValue(child, options);
|
|
6970
6973
|
}
|
|
6971
6974
|
}
|
|
6975
|
+
function* formatInline(g) {
|
|
6976
|
+
yield [...g].join("").trim();
|
|
6977
|
+
}
|
|
6972
6978
|
function* formatTableRow(items) {
|
|
6973
6979
|
yield `| ${items.join(" | ")} |`;
|
|
6974
6980
|
}
|
|
@@ -7018,8 +7024,10 @@ function* formatVariable(v) {
|
|
|
7018
7024
|
yield v.path.map((p, i) => {
|
|
7019
7025
|
if (i === 0)
|
|
7020
7026
|
return p;
|
|
7021
|
-
if (isIdentifier(
|
|
7027
|
+
if (isIdentifier(p))
|
|
7022
7028
|
return "." + p;
|
|
7029
|
+
if (typeof p === "number")
|
|
7030
|
+
return `[${p}]`;
|
|
7023
7031
|
return `["${p}"]`;
|
|
7024
7032
|
}).join("");
|
|
7025
7033
|
}
|
|
@@ -7040,6 +7048,9 @@ function* trimStart(g) {
|
|
|
7040
7048
|
yield n;
|
|
7041
7049
|
yield* g;
|
|
7042
7050
|
}
|
|
7051
|
+
function* escapeMarkdownCharacters(s2, characters) {
|
|
7052
|
+
yield s2.replace(characters, "\\$&").replace(new RegExp("\xA0", "g"), " ");
|
|
7053
|
+
}
|
|
7043
7054
|
function* formatNode(n, o = {}) {
|
|
7044
7055
|
const no = { ...o, parent: n };
|
|
7045
7056
|
const indent = SPACE.repeat(no.indent || 0);
|
|
@@ -7079,7 +7090,7 @@ function* formatNode(n, o = {}) {
|
|
|
7079
7090
|
yield* formatValue(n.attributes.alt, no);
|
|
7080
7091
|
yield "]";
|
|
7081
7092
|
yield "(";
|
|
7082
|
-
yield* formatValue(n.attributes.src, no);
|
|
7093
|
+
yield* typeof n.attributes.src === "string" ? escapeMarkdownCharacters(n.attributes.src, /[()]/) : formatValue(n.attributes.src, no);
|
|
7083
7094
|
if (n.attributes.title) {
|
|
7084
7095
|
yield SPACE + `"${n.attributes.title}"`;
|
|
7085
7096
|
}
|
|
@@ -7091,7 +7102,7 @@ function* formatNode(n, o = {}) {
|
|
|
7091
7102
|
yield* formatChildren(n, no);
|
|
7092
7103
|
yield "]";
|
|
7093
7104
|
yield "(";
|
|
7094
|
-
yield* formatValue(n.attributes.href, no);
|
|
7105
|
+
yield* typeof n.attributes.href === "string" ? escapeMarkdownCharacters(n.attributes.href, /[()]/g) : formatValue(n.attributes.href, no);
|
|
7095
7106
|
if (n.attributes.title) {
|
|
7096
7107
|
yield SPACE + `"${n.attributes.title}"`;
|
|
7097
7108
|
}
|
|
@@ -7099,10 +7110,11 @@ function* formatNode(n, o = {}) {
|
|
|
7099
7110
|
break;
|
|
7100
7111
|
}
|
|
7101
7112
|
case "text": {
|
|
7102
|
-
|
|
7113
|
+
const { content } = n.attributes;
|
|
7114
|
+
if (ast_default.isAst(content))
|
|
7103
7115
|
yield OPEN + SPACE;
|
|
7104
|
-
yield* formatValue(
|
|
7105
|
-
if (ast_default.isAst(
|
|
7116
|
+
yield* typeof content === "string" ? escapeMarkdownCharacters(content, /[_*~]/g) : formatValue(content, no);
|
|
7117
|
+
if (ast_default.isAst(content))
|
|
7106
7118
|
yield SPACE + CLOSE;
|
|
7107
7119
|
break;
|
|
7108
7120
|
}
|
|
@@ -7123,7 +7135,10 @@ function* formatNode(n, o = {}) {
|
|
|
7123
7135
|
case "fence": {
|
|
7124
7136
|
yield NL;
|
|
7125
7137
|
yield indent;
|
|
7126
|
-
|
|
7138
|
+
const innerFence = n.attributes.content.match(/`{3,}/g) || [];
|
|
7139
|
+
const innerFenceLength = innerFence.map((s2) => s2.length).reduce(max, 0);
|
|
7140
|
+
const boundary = "`".repeat(innerFenceLength ? innerFenceLength + 1 : 3);
|
|
7141
|
+
yield boundary;
|
|
7127
7142
|
if (n.attributes.language)
|
|
7128
7143
|
yield n.attributes.language;
|
|
7129
7144
|
if (n.annotations.length)
|
|
@@ -7132,7 +7147,7 @@ function* formatNode(n, o = {}) {
|
|
|
7132
7147
|
yield NL;
|
|
7133
7148
|
yield indent;
|
|
7134
7149
|
yield n.attributes.content.split(NL).join(NL + indent);
|
|
7135
|
-
yield
|
|
7150
|
+
yield boundary;
|
|
7136
7151
|
yield NL;
|
|
7137
7152
|
break;
|
|
7138
7153
|
}
|
|
@@ -7177,25 +7192,25 @@ function* formatNode(n, o = {}) {
|
|
|
7177
7192
|
}
|
|
7178
7193
|
case "strong": {
|
|
7179
7194
|
yield "**";
|
|
7180
|
-
yield* formatChildren(n, no);
|
|
7195
|
+
yield* formatInline(formatChildren(n, no));
|
|
7181
7196
|
yield "**";
|
|
7182
7197
|
break;
|
|
7183
7198
|
}
|
|
7184
7199
|
case "em": {
|
|
7185
7200
|
yield "_";
|
|
7186
|
-
yield* formatChildren(n, no);
|
|
7201
|
+
yield* formatInline(formatChildren(n, no));
|
|
7187
7202
|
yield "_";
|
|
7188
7203
|
break;
|
|
7189
7204
|
}
|
|
7190
7205
|
case "code": {
|
|
7191
7206
|
yield "`";
|
|
7192
|
-
yield* formatValue(n.attributes.content, no);
|
|
7207
|
+
yield* formatInline(formatValue(n.attributes.content, no));
|
|
7193
7208
|
yield "`";
|
|
7194
7209
|
break;
|
|
7195
7210
|
}
|
|
7196
7211
|
case "s": {
|
|
7197
7212
|
yield "~~";
|
|
7198
|
-
yield* formatChildren(n, no);
|
|
7213
|
+
yield* formatInline(formatChildren(n, no));
|
|
7199
7214
|
yield "~~";
|
|
7200
7215
|
break;
|
|
7201
7216
|
}
|
|
@@ -7854,10 +7869,10 @@ var voidElements = new Set([
|
|
|
7854
7869
|
]);
|
|
7855
7870
|
function render(node2) {
|
|
7856
7871
|
if (typeof node2 === "string" || typeof node2 === "number")
|
|
7857
|
-
return escapeHtml(node2);
|
|
7872
|
+
return escapeHtml(String(node2));
|
|
7858
7873
|
if (Array.isArray(node2))
|
|
7859
7874
|
return node2.map(render).join("");
|
|
7860
|
-
if (node2 === null || typeof node2 !== "object")
|
|
7875
|
+
if (node2 === null || typeof node2 !== "object" || !Tag.isTag(node2))
|
|
7861
7876
|
return "";
|
|
7862
7877
|
const { name, attributes, children = [] } = node2;
|
|
7863
7878
|
if (!name)
|
|
@@ -7874,12 +7889,10 @@ function render(node2) {
|
|
|
7874
7889
|
return output;
|
|
7875
7890
|
}
|
|
7876
7891
|
|
|
7877
|
-
// src/renderers/react/
|
|
7892
|
+
// src/renderers/react/react.ts
|
|
7878
7893
|
function tagName(name, components) {
|
|
7879
|
-
return typeof name !== "string" ?
|
|
7894
|
+
return typeof name !== "string" ? name : name[0] !== name[0].toUpperCase() ? name : components instanceof Function ? components(name) : components[name];
|
|
7880
7895
|
}
|
|
7881
|
-
|
|
7882
|
-
// src/renderers/react/react.ts
|
|
7883
7896
|
function dynamic(node2, React, { components = {} } = {}) {
|
|
7884
7897
|
function deepRender2(value) {
|
|
7885
7898
|
if (value == null || typeof value !== "object")
|
|
@@ -7898,7 +7911,7 @@ function dynamic(node2, React, { components = {} } = {}) {
|
|
|
7898
7911
|
function render3(node3) {
|
|
7899
7912
|
if (Array.isArray(node3))
|
|
7900
7913
|
return React.createElement(React.Fragment, null, ...node3.map(render3));
|
|
7901
|
-
if (node3 === null || typeof node3 !== "object")
|
|
7914
|
+
if (node3 === null || typeof node3 !== "object" || !Tag.isTag(node3))
|
|
7902
7915
|
return node3;
|
|
7903
7916
|
const {
|
|
7904
7917
|
name,
|
|
@@ -7913,6 +7926,9 @@ function dynamic(node2, React, { components = {} } = {}) {
|
|
|
7913
7926
|
}
|
|
7914
7927
|
|
|
7915
7928
|
// src/renderers/react/static.ts
|
|
7929
|
+
function tagName2(name, components) {
|
|
7930
|
+
return typeof name !== "string" ? "Fragment" : name[0] !== name[0].toUpperCase() ? name : components instanceof Function ? components(name) : components[name];
|
|
7931
|
+
}
|
|
7916
7932
|
function renderArray(children) {
|
|
7917
7933
|
return children.map(render2).join(", ");
|
|
7918
7934
|
}
|
|
@@ -7931,7 +7947,7 @@ function deepRender(value) {
|
|
|
7931
7947
|
function render2(node2) {
|
|
7932
7948
|
if (Array.isArray(node2))
|
|
7933
7949
|
return `React.createElement(React.Fragment, null, ${renderArray(node2)})`;
|
|
7934
|
-
if (node2 === null || typeof node2 !== "object")
|
|
7950
|
+
if (node2 === null || typeof node2 !== "object" || !Tag.isTag(node2))
|
|
7935
7951
|
return JSON.stringify(node2);
|
|
7936
7952
|
const {
|
|
7937
7953
|
name,
|
|
@@ -7948,7 +7964,7 @@ function render2(node2) {
|
|
|
7948
7964
|
function reactStatic(node2) {
|
|
7949
7965
|
return `
|
|
7950
7966
|
(({components = {}} = {}) => {
|
|
7951
|
-
${
|
|
7967
|
+
${tagName2}
|
|
7952
7968
|
return ${render2(node2)};
|
|
7953
7969
|
})
|
|
7954
7970
|
`;
|
|
@@ -8017,10 +8033,10 @@ var tags_default = {
|
|
|
8017
8033
|
var import_lib = __toModule(require_lib());
|
|
8018
8034
|
|
|
8019
8035
|
// src/tokenizer/plugins/annotations.ts
|
|
8020
|
-
var
|
|
8036
|
+
var import_tag7 = __toModule(require_tag());
|
|
8021
8037
|
function createToken(state, content, contentStart) {
|
|
8022
8038
|
try {
|
|
8023
|
-
const { type, meta, nesting = 0 } = (0,
|
|
8039
|
+
const { type, meta, nesting = 0 } = (0, import_tag7.parse)(content, { Variable, Function: Function2 });
|
|
8024
8040
|
const token = state.push(type, "", nesting);
|
|
8025
8041
|
token.info = content;
|
|
8026
8042
|
token.meta = meta;
|
|
@@ -8029,7 +8045,7 @@ function createToken(state, content, contentStart) {
|
|
|
8029
8045
|
}
|
|
8030
8046
|
return token;
|
|
8031
8047
|
} catch (error2) {
|
|
8032
|
-
if (!(error2 instanceof
|
|
8048
|
+
if (!(error2 instanceof import_tag7.SyntaxError))
|
|
8033
8049
|
throw error2;
|
|
8034
8050
|
const {
|
|
8035
8051
|
message,
|
|
@@ -8087,10 +8103,10 @@ function core(state) {
|
|
|
8087
8103
|
const end = findTagEnd(token.info, start);
|
|
8088
8104
|
const content = token.info.slice(start + OPEN.length, end);
|
|
8089
8105
|
try {
|
|
8090
|
-
const { meta } = (0,
|
|
8106
|
+
const { meta } = (0, import_tag7.parse)(content.trim(), { Variable, Function: Function2 });
|
|
8091
8107
|
token.meta = meta;
|
|
8092
8108
|
} catch (error2) {
|
|
8093
|
-
if (!(error2 instanceof
|
|
8109
|
+
if (!(error2 instanceof import_tag7.SyntaxError))
|
|
8094
8110
|
throw error2;
|
|
8095
8111
|
if (!token.errors)
|
|
8096
8112
|
token.errors = [];
|
|
@@ -8480,14 +8496,14 @@ Markdoc.transform = transform2;
|
|
|
8480
8496
|
Markdoc.validate = validate;
|
|
8481
8497
|
Markdoc.createElement = createElement;
|
|
8482
8498
|
Markdoc.truthy = truthy;
|
|
8483
|
-
Markdoc.
|
|
8499
|
+
Markdoc.format = format;
|
|
8484
8500
|
export {
|
|
8485
8501
|
ast_default as Ast,
|
|
8486
8502
|
Tag,
|
|
8487
8503
|
Tokenizer,
|
|
8488
|
-
format as __EXPERIMENTAL__format,
|
|
8489
8504
|
createElement,
|
|
8490
8505
|
Markdoc as default,
|
|
8506
|
+
format,
|
|
8491
8507
|
functions_default as functions,
|
|
8492
8508
|
globalAttributes,
|
|
8493
8509
|
schema_exports as nodes,
|