@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/dist/index.mjs
CHANGED
|
@@ -6707,6 +6707,7 @@ function findTagEnd(content, start = 0) {
|
|
|
6707
6707
|
return pos;
|
|
6708
6708
|
}
|
|
6709
6709
|
}
|
|
6710
|
+
return null;
|
|
6710
6711
|
}
|
|
6711
6712
|
function parseTag(content, line, contentStart) {
|
|
6712
6713
|
try {
|
|
@@ -6736,7 +6737,11 @@ function parseTags(content, firstLine = 0) {
|
|
|
6736
6737
|
}
|
|
6737
6738
|
if (!content.startsWith(OPEN, pos))
|
|
6738
6739
|
continue;
|
|
6739
|
-
const end = findTagEnd(content, pos)
|
|
6740
|
+
const end = findTagEnd(content, pos);
|
|
6741
|
+
if (end == null) {
|
|
6742
|
+
pos = pos + OPEN.length;
|
|
6743
|
+
continue;
|
|
6744
|
+
}
|
|
6740
6745
|
const text2 = content.slice(pos, end + CLOSE.length);
|
|
6741
6746
|
const inner = content.slice(pos + OPEN.length, end);
|
|
6742
6747
|
const lineStart = content.lastIndexOf("\n", pos);
|
|
@@ -6782,6 +6787,9 @@ function createToken(state, content, contentStart) {
|
|
|
6782
6787
|
const token = state.push(type, "", nesting);
|
|
6783
6788
|
token.info = content;
|
|
6784
6789
|
token.meta = meta;
|
|
6790
|
+
if (!state.delimiters) {
|
|
6791
|
+
state.delimiters = [];
|
|
6792
|
+
}
|
|
6785
6793
|
return token;
|
|
6786
6794
|
} catch (error2) {
|
|
6787
6795
|
if (!(error2 instanceof import_tag2.SyntaxError))
|
|
@@ -7078,7 +7086,7 @@ function transform(document2) {
|
|
|
7078
7086
|
for (const row of rest) {
|
|
7079
7087
|
if (row.type === "list")
|
|
7080
7088
|
convertToRow(row);
|
|
7081
|
-
else if (row.type === "tag" && row.tag
|
|
7089
|
+
else if (row.type === "tag" && row.tag === "if") {
|
|
7082
7090
|
const children = [];
|
|
7083
7091
|
for (const child of row.children) {
|
|
7084
7092
|
if (child.type === "hr")
|
|
@@ -7125,11 +7133,11 @@ function handleAttrs(token, type) {
|
|
|
7125
7133
|
return { ordered: token.type.startsWith("ordered") };
|
|
7126
7134
|
case "link": {
|
|
7127
7135
|
const attrs = Object.fromEntries(token.attrs);
|
|
7128
|
-
return { href: attrs.href };
|
|
7136
|
+
return attrs.title ? { href: attrs.href, title: attrs.title } : { href: attrs.href };
|
|
7129
7137
|
}
|
|
7130
7138
|
case "image": {
|
|
7131
7139
|
const attrs = Object.fromEntries(token.attrs);
|
|
7132
|
-
return { alt: token.content, src: attrs.src };
|
|
7140
|
+
return attrs.title ? { alt: token.content, src: attrs.src, title: attrs.title } : { alt: token.content, src: attrs.src };
|
|
7133
7141
|
}
|
|
7134
7142
|
case "text":
|
|
7135
7143
|
case "code":
|
|
@@ -7138,6 +7146,26 @@ function handleAttrs(token, type) {
|
|
|
7138
7146
|
const [language] = token.info.split(" ", 1);
|
|
7139
7147
|
return language === "" ? { content: token.content } : { content: token.content, language };
|
|
7140
7148
|
}
|
|
7149
|
+
case "td":
|
|
7150
|
+
case "th": {
|
|
7151
|
+
if (token.attrs) {
|
|
7152
|
+
const attrs = Object.fromEntries(token.attrs);
|
|
7153
|
+
let align;
|
|
7154
|
+
if (attrs.style) {
|
|
7155
|
+
if (attrs.style.includes("left")) {
|
|
7156
|
+
align = "left";
|
|
7157
|
+
} else if (attrs.style.includes("center")) {
|
|
7158
|
+
align = "center";
|
|
7159
|
+
} else if (attrs.style.includes("right")) {
|
|
7160
|
+
align = "right";
|
|
7161
|
+
}
|
|
7162
|
+
}
|
|
7163
|
+
if (align) {
|
|
7164
|
+
return { align };
|
|
7165
|
+
}
|
|
7166
|
+
}
|
|
7167
|
+
return {};
|
|
7168
|
+
}
|
|
7141
7169
|
default:
|
|
7142
7170
|
return {};
|
|
7143
7171
|
}
|
|
@@ -7294,7 +7322,8 @@ var image = {
|
|
|
7294
7322
|
render: "img",
|
|
7295
7323
|
attributes: {
|
|
7296
7324
|
src: { type: String, required: true },
|
|
7297
|
-
alt: { type: String }
|
|
7325
|
+
alt: { type: String },
|
|
7326
|
+
title: { type: String }
|
|
7298
7327
|
}
|
|
7299
7328
|
};
|
|
7300
7329
|
var fence2 = {
|
|
@@ -7737,7 +7766,7 @@ function validateFunction(fn, config) {
|
|
|
7737
7766
|
{
|
|
7738
7767
|
id: "function-undefined",
|
|
7739
7768
|
level: "critical",
|
|
7740
|
-
message: `Undefined function '${fn.name}'`
|
|
7769
|
+
message: `Undefined function: '${fn.name}'`
|
|
7741
7770
|
}
|
|
7742
7771
|
];
|
|
7743
7772
|
if (schema.validate)
|
|
@@ -7749,7 +7778,7 @@ function validateFunction(fn, config) {
|
|
|
7749
7778
|
errors.push({
|
|
7750
7779
|
id: "parameter-undefined",
|
|
7751
7780
|
level: "error",
|
|
7752
|
-
message: `Invalid parameter '${key}'`
|
|
7781
|
+
message: `Invalid parameter: '${key}'`
|
|
7753
7782
|
});
|
|
7754
7783
|
continue;
|
|
7755
7784
|
}
|
|
@@ -7761,7 +7790,7 @@ function validateFunction(fn, config) {
|
|
|
7761
7790
|
errors.push({
|
|
7762
7791
|
id: "parameter-type-invalid",
|
|
7763
7792
|
level: "error",
|
|
7764
|
-
message: `Parameter '${key}' of '${fn.name}' must be type '${typeToString(param.type)}'`
|
|
7793
|
+
message: `Parameter '${key}' of '${fn.name}' must be type of '${typeToString(param.type)}'`
|
|
7765
7794
|
});
|
|
7766
7795
|
} else if (Array.isArray(valid)) {
|
|
7767
7796
|
errors.push(...valid);
|
|
@@ -7774,7 +7803,7 @@ function validateFunction(fn, config) {
|
|
|
7774
7803
|
errors.push({
|
|
7775
7804
|
id: "parameter-missing-required",
|
|
7776
7805
|
level: "error",
|
|
7777
|
-
message: `Missing required parameter '${key}'`
|
|
7806
|
+
message: `Missing required parameter: '${key}'`
|
|
7778
7807
|
});
|
|
7779
7808
|
return errors;
|
|
7780
7809
|
}
|
|
@@ -7785,7 +7814,7 @@ function validate(node, config) {
|
|
|
7785
7814
|
errors.push({
|
|
7786
7815
|
id: node.tag ? "tag-undefined" : "node-undefined",
|
|
7787
7816
|
level: "critical",
|
|
7788
|
-
message: node.tag ? `Undefined tag '${node.tag}'` : `Undefined node '${node.type}'`
|
|
7817
|
+
message: node.tag ? `Undefined tag: '${node.tag}'` : `Undefined node: '${node.type}'`
|
|
7789
7818
|
});
|
|
7790
7819
|
return errors;
|
|
7791
7820
|
}
|
|
@@ -7793,7 +7822,7 @@ function validate(node, config) {
|
|
|
7793
7822
|
errors.push({
|
|
7794
7823
|
id: "tag-selfclosing-has-children",
|
|
7795
7824
|
level: "critical",
|
|
7796
|
-
message: `
|
|
7825
|
+
message: `'${node.tag}' tag should be self-closing`
|
|
7797
7826
|
});
|
|
7798
7827
|
const attributes = {
|
|
7799
7828
|
...globalAttributes,
|
|
@@ -7807,7 +7836,7 @@ function validate(node, config) {
|
|
|
7807
7836
|
errors.push({
|
|
7808
7837
|
id: "attribute-undefined",
|
|
7809
7838
|
level: "error",
|
|
7810
|
-
message: `Invalid attribute '${key}'`
|
|
7839
|
+
message: `Invalid attribute: '${key}'`
|
|
7811
7840
|
});
|
|
7812
7841
|
continue;
|
|
7813
7842
|
}
|
|
@@ -7823,7 +7852,7 @@ function validate(node, config) {
|
|
|
7823
7852
|
errors.push({
|
|
7824
7853
|
id: "attribute-value-invalid",
|
|
7825
7854
|
level: "error",
|
|
7826
|
-
message: "The
|
|
7855
|
+
message: "The id attribute must not start with a number"
|
|
7827
7856
|
});
|
|
7828
7857
|
if (type) {
|
|
7829
7858
|
const valid = validateType(type, value, config);
|
|
@@ -7831,7 +7860,7 @@ function validate(node, config) {
|
|
|
7831
7860
|
errors.push({
|
|
7832
7861
|
id: "attribute-type-invalid",
|
|
7833
7862
|
level: errorLevel || "error",
|
|
7834
|
-
message: `Attribute '${key}' must be type '${typeToString(type)}'`
|
|
7863
|
+
message: `Attribute '${key}' must be type of '${typeToString(type)}'`
|
|
7835
7864
|
});
|
|
7836
7865
|
}
|
|
7837
7866
|
if (Array.isArray(valid)) {
|
|
@@ -7858,7 +7887,7 @@ function validate(node, config) {
|
|
|
7858
7887
|
errors.push({
|
|
7859
7888
|
id: "attribute-missing-required",
|
|
7860
7889
|
level: "error",
|
|
7861
|
-
message: `Missing required attribute '${key}'`
|
|
7890
|
+
message: `Missing required attribute: '${key}'`
|
|
7862
7891
|
});
|
|
7863
7892
|
for (const { type } of node.children) {
|
|
7864
7893
|
if (schema.children && type !== "error" && !schema.children.includes(type))
|