@markdoc/markdoc 0.1.2 → 0.1.3
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 +4 -1
- package/dist/index.js +44 -15
- package/dist/index.js.map +2 -2
- package/dist/index.mjs +44 -15
- package/dist/index.mjs.map +2 -2
- package/dist/src/parser.d.ts.map +1 -1
- package/dist/src/schema.d.ts.map +1 -1
- package/dist/src/tokenizer/plugins/annotations.d.ts.map +1 -1
- package/dist/src/utils.d.ts +1 -1
- package/dist/src/utils.d.ts.map +1 -1
- package/global.d.ts +7 -0
- package/package.json +5 -3
- package/src/parser.test.ts +42 -0
- package/src/parser.ts +28 -2
- package/src/schema.ts +1 -0
- package/src/tokenizer/plugins/annotations.test.ts +60 -0
- package/src/tokenizer/plugins/annotations.ts +4 -0
- package/src/transforms/table.ts +1 -1
- package/src/utils.test.ts +15 -2
- package/src/utils.ts +10 -1
- package/src/validator.test.ts +10 -10
- package/src/validator.ts +11 -11
package/README.md
CHANGED
|
@@ -72,4 +72,7 @@ This project uses the [MIT license](LICENSE).
|
|
|
72
72
|
|
|
73
73
|
## Credits
|
|
74
74
|
|
|
75
|
-
|
|
75
|
+
Special shout out to:
|
|
76
|
+
|
|
77
|
+
- [@marcioAlmada](https://github.com/marcioAlmada) for providing us with the [@markdoc](https://github.com/markdoc) GitHub org.
|
|
78
|
+
- [@koomen](https://github.com/koomen) for gifting us https://markdoc.dev.
|
package/dist/index.js
CHANGED
|
@@ -6729,6 +6729,7 @@ function findTagEnd(content, start = 0) {
|
|
|
6729
6729
|
return pos;
|
|
6730
6730
|
}
|
|
6731
6731
|
}
|
|
6732
|
+
return null;
|
|
6732
6733
|
}
|
|
6733
6734
|
function parseTag(content, line, contentStart) {
|
|
6734
6735
|
try {
|
|
@@ -6758,7 +6759,11 @@ function parseTags(content, firstLine = 0) {
|
|
|
6758
6759
|
}
|
|
6759
6760
|
if (!content.startsWith(OPEN, pos))
|
|
6760
6761
|
continue;
|
|
6761
|
-
const end = findTagEnd(content, pos)
|
|
6762
|
+
const end = findTagEnd(content, pos);
|
|
6763
|
+
if (end == null) {
|
|
6764
|
+
pos = pos + OPEN.length;
|
|
6765
|
+
continue;
|
|
6766
|
+
}
|
|
6762
6767
|
const text2 = content.slice(pos, end + CLOSE.length);
|
|
6763
6768
|
const inner = content.slice(pos + OPEN.length, end);
|
|
6764
6769
|
const lineStart = content.lastIndexOf("\n", pos);
|
|
@@ -6804,6 +6809,9 @@ function createToken(state, content, contentStart) {
|
|
|
6804
6809
|
const token = state.push(type, "", nesting);
|
|
6805
6810
|
token.info = content;
|
|
6806
6811
|
token.meta = meta;
|
|
6812
|
+
if (!state.delimiters) {
|
|
6813
|
+
state.delimiters = [];
|
|
6814
|
+
}
|
|
6807
6815
|
return token;
|
|
6808
6816
|
} catch (error2) {
|
|
6809
6817
|
if (!(error2 instanceof import_tag2.SyntaxError))
|
|
@@ -7100,7 +7108,7 @@ function transform(document2) {
|
|
|
7100
7108
|
for (const row of rest) {
|
|
7101
7109
|
if (row.type === "list")
|
|
7102
7110
|
convertToRow(row);
|
|
7103
|
-
else if (row.type === "tag" && row.tag
|
|
7111
|
+
else if (row.type === "tag" && row.tag === "if") {
|
|
7104
7112
|
const children = [];
|
|
7105
7113
|
for (const child of row.children) {
|
|
7106
7114
|
if (child.type === "hr")
|
|
@@ -7147,11 +7155,11 @@ function handleAttrs(token, type) {
|
|
|
7147
7155
|
return { ordered: token.type.startsWith("ordered") };
|
|
7148
7156
|
case "link": {
|
|
7149
7157
|
const attrs = Object.fromEntries(token.attrs);
|
|
7150
|
-
return { href: attrs.href };
|
|
7158
|
+
return attrs.title ? { href: attrs.href, title: attrs.title } : { href: attrs.href };
|
|
7151
7159
|
}
|
|
7152
7160
|
case "image": {
|
|
7153
7161
|
const attrs = Object.fromEntries(token.attrs);
|
|
7154
|
-
return { alt: token.content, src: attrs.src };
|
|
7162
|
+
return attrs.title ? { alt: token.content, src: attrs.src, title: attrs.title } : { alt: token.content, src: attrs.src };
|
|
7155
7163
|
}
|
|
7156
7164
|
case "text":
|
|
7157
7165
|
case "code":
|
|
@@ -7160,6 +7168,26 @@ function handleAttrs(token, type) {
|
|
|
7160
7168
|
const [language] = token.info.split(" ", 1);
|
|
7161
7169
|
return language === "" ? { content: token.content } : { content: token.content, language };
|
|
7162
7170
|
}
|
|
7171
|
+
case "td":
|
|
7172
|
+
case "th": {
|
|
7173
|
+
if (token.attrs) {
|
|
7174
|
+
const attrs = Object.fromEntries(token.attrs);
|
|
7175
|
+
let align;
|
|
7176
|
+
if (attrs.style) {
|
|
7177
|
+
if (attrs.style.includes("left")) {
|
|
7178
|
+
align = "left";
|
|
7179
|
+
} else if (attrs.style.includes("center")) {
|
|
7180
|
+
align = "center";
|
|
7181
|
+
} else if (attrs.style.includes("right")) {
|
|
7182
|
+
align = "right";
|
|
7183
|
+
}
|
|
7184
|
+
}
|
|
7185
|
+
if (align) {
|
|
7186
|
+
return { align };
|
|
7187
|
+
}
|
|
7188
|
+
}
|
|
7189
|
+
return {};
|
|
7190
|
+
}
|
|
7163
7191
|
default:
|
|
7164
7192
|
return {};
|
|
7165
7193
|
}
|
|
@@ -7316,7 +7344,8 @@ var image = {
|
|
|
7316
7344
|
render: "img",
|
|
7317
7345
|
attributes: {
|
|
7318
7346
|
src: { type: String, required: true },
|
|
7319
|
-
alt: { type: String }
|
|
7347
|
+
alt: { type: String },
|
|
7348
|
+
title: { type: String }
|
|
7320
7349
|
}
|
|
7321
7350
|
};
|
|
7322
7351
|
var fence2 = {
|
|
@@ -7759,7 +7788,7 @@ function validateFunction(fn, config) {
|
|
|
7759
7788
|
{
|
|
7760
7789
|
id: "function-undefined",
|
|
7761
7790
|
level: "critical",
|
|
7762
|
-
message: `Undefined function '${fn.name}'`
|
|
7791
|
+
message: `Undefined function: '${fn.name}'`
|
|
7763
7792
|
}
|
|
7764
7793
|
];
|
|
7765
7794
|
if (schema.validate)
|
|
@@ -7771,7 +7800,7 @@ function validateFunction(fn, config) {
|
|
|
7771
7800
|
errors.push({
|
|
7772
7801
|
id: "parameter-undefined",
|
|
7773
7802
|
level: "error",
|
|
7774
|
-
message: `Invalid parameter '${key}'`
|
|
7803
|
+
message: `Invalid parameter: '${key}'`
|
|
7775
7804
|
});
|
|
7776
7805
|
continue;
|
|
7777
7806
|
}
|
|
@@ -7783,7 +7812,7 @@ function validateFunction(fn, config) {
|
|
|
7783
7812
|
errors.push({
|
|
7784
7813
|
id: "parameter-type-invalid",
|
|
7785
7814
|
level: "error",
|
|
7786
|
-
message: `Parameter '${key}' of '${fn.name}' must be type '${typeToString(param.type)}'`
|
|
7815
|
+
message: `Parameter '${key}' of '${fn.name}' must be type of '${typeToString(param.type)}'`
|
|
7787
7816
|
});
|
|
7788
7817
|
} else if (Array.isArray(valid)) {
|
|
7789
7818
|
errors.push(...valid);
|
|
@@ -7796,7 +7825,7 @@ function validateFunction(fn, config) {
|
|
|
7796
7825
|
errors.push({
|
|
7797
7826
|
id: "parameter-missing-required",
|
|
7798
7827
|
level: "error",
|
|
7799
|
-
message: `Missing required parameter '${key}'`
|
|
7828
|
+
message: `Missing required parameter: '${key}'`
|
|
7800
7829
|
});
|
|
7801
7830
|
return errors;
|
|
7802
7831
|
}
|
|
@@ -7807,7 +7836,7 @@ function validate(node, config) {
|
|
|
7807
7836
|
errors.push({
|
|
7808
7837
|
id: node.tag ? "tag-undefined" : "node-undefined",
|
|
7809
7838
|
level: "critical",
|
|
7810
|
-
message: node.tag ? `Undefined tag '${node.tag}'` : `Undefined node '${node.type}'`
|
|
7839
|
+
message: node.tag ? `Undefined tag: '${node.tag}'` : `Undefined node: '${node.type}'`
|
|
7811
7840
|
});
|
|
7812
7841
|
return errors;
|
|
7813
7842
|
}
|
|
@@ -7815,7 +7844,7 @@ function validate(node, config) {
|
|
|
7815
7844
|
errors.push({
|
|
7816
7845
|
id: "tag-selfclosing-has-children",
|
|
7817
7846
|
level: "critical",
|
|
7818
|
-
message: `
|
|
7847
|
+
message: `'${node.tag}' tag should be self-closing`
|
|
7819
7848
|
});
|
|
7820
7849
|
const attributes = {
|
|
7821
7850
|
...globalAttributes,
|
|
@@ -7829,7 +7858,7 @@ function validate(node, config) {
|
|
|
7829
7858
|
errors.push({
|
|
7830
7859
|
id: "attribute-undefined",
|
|
7831
7860
|
level: "error",
|
|
7832
|
-
message: `Invalid attribute '${key}'`
|
|
7861
|
+
message: `Invalid attribute: '${key}'`
|
|
7833
7862
|
});
|
|
7834
7863
|
continue;
|
|
7835
7864
|
}
|
|
@@ -7845,7 +7874,7 @@ function validate(node, config) {
|
|
|
7845
7874
|
errors.push({
|
|
7846
7875
|
id: "attribute-value-invalid",
|
|
7847
7876
|
level: "error",
|
|
7848
|
-
message: "The
|
|
7877
|
+
message: "The id attribute must not start with a number"
|
|
7849
7878
|
});
|
|
7850
7879
|
if (type) {
|
|
7851
7880
|
const valid = validateType(type, value, config);
|
|
@@ -7853,7 +7882,7 @@ function validate(node, config) {
|
|
|
7853
7882
|
errors.push({
|
|
7854
7883
|
id: "attribute-type-invalid",
|
|
7855
7884
|
level: errorLevel || "error",
|
|
7856
|
-
message: `Attribute '${key}' must be type '${typeToString(type)}'`
|
|
7885
|
+
message: `Attribute '${key}' must be type of '${typeToString(type)}'`
|
|
7857
7886
|
});
|
|
7858
7887
|
}
|
|
7859
7888
|
if (Array.isArray(valid)) {
|
|
@@ -7880,7 +7909,7 @@ function validate(node, config) {
|
|
|
7880
7909
|
errors.push({
|
|
7881
7910
|
id: "attribute-missing-required",
|
|
7882
7911
|
level: "error",
|
|
7883
|
-
message: `Missing required attribute '${key}'`
|
|
7912
|
+
message: `Missing required attribute: '${key}'`
|
|
7884
7913
|
});
|
|
7885
7914
|
for (const { type } of node.children) {
|
|
7886
7915
|
if (schema.children && type !== "error" && !schema.children.includes(type))
|