@markdoc/markdoc 0.1.3 → 0.1.4
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 +1 -1
- package/dist/index.d.ts +35 -20
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +63 -22
- package/dist/index.js.map +2 -2
- package/dist/index.mjs +63 -22
- package/dist/index.mjs.map +2 -2
- package/dist/src/ast/node.d.ts +2 -1
- package/dist/src/ast/node.d.ts.map +1 -1
- package/dist/src/parser.d.ts.map +1 -1
- package/dist/src/tags/partial.d.ts.map +1 -1
- package/dist/src/tokenizer/index.d.ts.map +1 -1
- package/dist/src/transformer.d.ts +1 -7
- package/dist/src/transformer.d.ts.map +1 -1
- package/dist/src/types.d.ts +6 -0
- package/dist/src/types.d.ts.map +1 -1
- package/index.ts +35 -20
- package/package.json +2 -2
- package/src/ast/node.test.ts +52 -0
- package/src/ast/node.ts +3 -0
- package/src/parser.ts +5 -1
- package/src/tags/partial.ts +20 -3
- package/src/tokenizer/index.ts +5 -1
- package/src/transformer.ts +17 -16
- package/src/types.ts +7 -0
- package/src/validator.test.ts +26 -0
package/dist/index.mjs
CHANGED
|
@@ -6912,7 +6912,10 @@ var Tokenizer = class {
|
|
|
6912
6912
|
this.parser = new import_lib.default(config);
|
|
6913
6913
|
this.parser.use(plugin, "annotations", {});
|
|
6914
6914
|
this.parser.use(plugin2, "frontmatter", {});
|
|
6915
|
-
this.parser.disable(
|
|
6915
|
+
this.parser.disable([
|
|
6916
|
+
"lheading",
|
|
6917
|
+
"code"
|
|
6918
|
+
]);
|
|
6916
6919
|
}
|
|
6917
6920
|
tokenize(content) {
|
|
6918
6921
|
return this.parser.parse(content.toString(), {});
|
|
@@ -6954,6 +6957,9 @@ var Class = class {
|
|
|
6954
6957
|
};
|
|
6955
6958
|
|
|
6956
6959
|
// src/transformer.ts
|
|
6960
|
+
function isPromise(a) {
|
|
6961
|
+
return a && typeof a === "object" && typeof a.then === "function";
|
|
6962
|
+
}
|
|
6957
6963
|
var globalAttributes = {
|
|
6958
6964
|
class: { type: Class, render: true },
|
|
6959
6965
|
id: { type: String, render: true }
|
|
@@ -6985,7 +6991,11 @@ var transformer_default = {
|
|
|
6985
6991
|
return output;
|
|
6986
6992
|
},
|
|
6987
6993
|
children(node, config = {}) {
|
|
6988
|
-
|
|
6994
|
+
const children = node.children.flatMap((child) => this.node(child, config));
|
|
6995
|
+
if (children.some(isPromise)) {
|
|
6996
|
+
return Promise.all(children);
|
|
6997
|
+
}
|
|
6998
|
+
return children;
|
|
6989
6999
|
},
|
|
6990
7000
|
node(node, config = {}) {
|
|
6991
7001
|
const schema = this.findSchema(node, config) ?? {};
|
|
@@ -6995,6 +7005,9 @@ var transformer_default = {
|
|
|
6995
7005
|
if (!schema || !schema.render)
|
|
6996
7006
|
return children;
|
|
6997
7007
|
const attributes = this.attributes(node, config);
|
|
7008
|
+
if (isPromise(attributes) || isPromise(children)) {
|
|
7009
|
+
return Promise.all([attributes, children]).then((values) => new Tag(schema.render, ...values));
|
|
7010
|
+
}
|
|
6998
7011
|
return new Tag(schema.render, attributes, children);
|
|
6999
7012
|
}
|
|
7000
7013
|
};
|
|
@@ -7010,6 +7023,7 @@ var Node = class {
|
|
|
7010
7023
|
this.children = children;
|
|
7011
7024
|
this.type = type;
|
|
7012
7025
|
this.tag = tag;
|
|
7026
|
+
this.annotations = [];
|
|
7013
7027
|
}
|
|
7014
7028
|
*walk() {
|
|
7015
7029
|
for (const child of this.children) {
|
|
@@ -7116,7 +7130,9 @@ var mappings = {
|
|
|
7116
7130
|
variable: "text"
|
|
7117
7131
|
};
|
|
7118
7132
|
function annotate(node, attributes) {
|
|
7119
|
-
for (const
|
|
7133
|
+
for (const attribute of attributes) {
|
|
7134
|
+
node.annotations.push(attribute);
|
|
7135
|
+
const { name, value, type } = attribute;
|
|
7120
7136
|
if (type === "attribute")
|
|
7121
7137
|
node.attributes[name] = value;
|
|
7122
7138
|
else if (type === "class")
|
|
@@ -7124,6 +7140,7 @@ function annotate(node, attributes) {
|
|
|
7124
7140
|
node.attributes.class[name] = value;
|
|
7125
7141
|
else
|
|
7126
7142
|
node.attributes.class = { [name]: value };
|
|
7143
|
+
}
|
|
7127
7144
|
}
|
|
7128
7145
|
function handleAttrs(token, type) {
|
|
7129
7146
|
switch (type) {
|
|
@@ -7523,10 +7540,25 @@ var tagElse = {
|
|
|
7523
7540
|
};
|
|
7524
7541
|
|
|
7525
7542
|
// src/tags/partial.ts
|
|
7543
|
+
var PartialFile = class {
|
|
7544
|
+
validate(file, config) {
|
|
7545
|
+
const { partials = {} } = config;
|
|
7546
|
+
const partial2 = partials[file];
|
|
7547
|
+
if (!partial2)
|
|
7548
|
+
return [
|
|
7549
|
+
{
|
|
7550
|
+
id: "attribute-value-invalid",
|
|
7551
|
+
level: "error",
|
|
7552
|
+
message: `Partial \`${file}\` not found. The 'file' attribute must be set in \`config.partials\``
|
|
7553
|
+
}
|
|
7554
|
+
];
|
|
7555
|
+
return [];
|
|
7556
|
+
}
|
|
7557
|
+
};
|
|
7526
7558
|
var partial = {
|
|
7527
7559
|
selfClosing: true,
|
|
7528
7560
|
attributes: {
|
|
7529
|
-
file: { type:
|
|
7561
|
+
file: { type: PartialFile, render: false, required: true },
|
|
7530
7562
|
variables: { type: Object, render: false }
|
|
7531
7563
|
},
|
|
7532
7564
|
transform(node, config) {
|
|
@@ -7950,31 +7982,40 @@ function validate2(content, options) {
|
|
|
7950
7982
|
function createElement(name, attributes = {}, ...children) {
|
|
7951
7983
|
return { name, attributes, children };
|
|
7952
7984
|
}
|
|
7953
|
-
var
|
|
7954
|
-
|
|
7955
|
-
|
|
7956
|
-
|
|
7957
|
-
|
|
7958
|
-
|
|
7959
|
-
|
|
7960
|
-
|
|
7961
|
-
Tokenizer,
|
|
7962
|
-
parseTags,
|
|
7963
|
-
transformer: transformer_default,
|
|
7964
|
-
validator: validate,
|
|
7965
|
-
parse: parse3,
|
|
7966
|
-
transform: transform2,
|
|
7967
|
-
validate: validate2,
|
|
7968
|
-
createElement,
|
|
7969
|
-
truthy
|
|
7985
|
+
var Markdoc = class {
|
|
7986
|
+
constructor(config) {
|
|
7987
|
+
this.parse = parse3;
|
|
7988
|
+
this.resolve = (content) => resolve2(content, this.config);
|
|
7989
|
+
this.transform = (content) => transform2(content, this.config);
|
|
7990
|
+
this.validate = (content) => validate2(content, this.config);
|
|
7991
|
+
this.config = config;
|
|
7992
|
+
}
|
|
7970
7993
|
};
|
|
7994
|
+
Markdoc.nodes = schema_exports;
|
|
7995
|
+
Markdoc.tags = tags_default;
|
|
7996
|
+
Markdoc.functions = functions_default;
|
|
7997
|
+
Markdoc.globalAttributes = globalAttributes;
|
|
7998
|
+
Markdoc.renderers = renderers_default;
|
|
7999
|
+
Markdoc.transforms = transforms_default;
|
|
8000
|
+
Markdoc.Ast = ast_default;
|
|
8001
|
+
Markdoc.Tag = Tag;
|
|
8002
|
+
Markdoc.Tokenizer = Tokenizer;
|
|
8003
|
+
Markdoc.parseTags = parseTags;
|
|
8004
|
+
Markdoc.transformer = transformer_default;
|
|
8005
|
+
Markdoc.validator = validate;
|
|
8006
|
+
Markdoc.parse = parse3;
|
|
8007
|
+
Markdoc.transform = transform2;
|
|
8008
|
+
Markdoc.validate = validate2;
|
|
8009
|
+
Markdoc.createElement = createElement;
|
|
8010
|
+
Markdoc.truthy = truthy;
|
|
7971
8011
|
export {
|
|
7972
8012
|
ast_default as Ast,
|
|
7973
8013
|
Tag,
|
|
7974
8014
|
Tokenizer,
|
|
7975
8015
|
createElement,
|
|
7976
|
-
|
|
8016
|
+
Markdoc as default,
|
|
7977
8017
|
functions_default as functions,
|
|
8018
|
+
globalAttributes,
|
|
7978
8019
|
schema_exports as nodes,
|
|
7979
8020
|
parse3 as parse,
|
|
7980
8021
|
parseTags,
|