@markdoc/markdoc 0.5.2 → 0.5.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/dist/index.js +25 -4
- package/dist/index.js.map +3 -3
- package/dist/index.mjs +25 -4
- package/dist/index.mjs.map +3 -3
- package/dist/src/formatter.d.ts.map +1 -1
- package/dist/src/schema-types/conditional.d.ts +13 -0
- package/dist/src/schema-types/conditional.d.ts.map +1 -0
- package/dist/src/tags/conditional.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/formatter.test.ts +7 -0
- package/src/formatter.ts +10 -2
- package/src/schema-types/conditional.ts +34 -0
- package/src/tags/conditional.ts +3 -2
package/dist/index.js
CHANGED
|
@@ -7198,8 +7198,13 @@ function* formatNode(n, o = {}) {
|
|
|
7198
7198
|
break;
|
|
7199
7199
|
}
|
|
7200
7200
|
case "link": {
|
|
7201
|
+
const children = [...formatChildren(n, no)].join("");
|
|
7202
|
+
if (children === n.attributes.href && !n.attributes.title) {
|
|
7203
|
+
yield `<${n.attributes.href}>`;
|
|
7204
|
+
break;
|
|
7205
|
+
}
|
|
7201
7206
|
yield "[";
|
|
7202
|
-
yield
|
|
7207
|
+
yield children;
|
|
7203
7208
|
yield "]";
|
|
7204
7209
|
yield "(";
|
|
7205
7210
|
yield* typeof n.attributes.href === "string" ? escapeMarkdownCharacters(n.attributes.href, /[()]/g) : formatValue(n.attributes.href, no);
|
|
@@ -7219,7 +7224,7 @@ function* formatNode(n, o = {}) {
|
|
|
7219
7224
|
if (o.parent && WRAPPING_TYPES.includes(o.parent.type)) {
|
|
7220
7225
|
yield* escapeMarkdownCharacters(content, /[*_~]/g);
|
|
7221
7226
|
} else {
|
|
7222
|
-
yield* escapeMarkdownCharacters(content,
|
|
7227
|
+
yield* escapeMarkdownCharacters(content, /^\*|#+\s|^>/);
|
|
7223
7228
|
}
|
|
7224
7229
|
}
|
|
7225
7230
|
break;
|
|
@@ -7460,6 +7465,22 @@ function format(v, options) {
|
|
|
7460
7465
|
return doc.trimStart();
|
|
7461
7466
|
}
|
|
7462
7467
|
|
|
7468
|
+
// src/schema-types/conditional.ts
|
|
7469
|
+
var ConditionalAttributeType = class {
|
|
7470
|
+
validate(value, _config, key) {
|
|
7471
|
+
if (typeof value === "boolean" || value === null || value === void 0 || typeof value === "object") {
|
|
7472
|
+
return [];
|
|
7473
|
+
}
|
|
7474
|
+
return [
|
|
7475
|
+
{
|
|
7476
|
+
id: "attribute-type-invalid",
|
|
7477
|
+
level: "error",
|
|
7478
|
+
message: `Attribute '${key}' must be type 'boolean | object' (null or undefined are also allowed)`
|
|
7479
|
+
}
|
|
7480
|
+
];
|
|
7481
|
+
}
|
|
7482
|
+
};
|
|
7483
|
+
|
|
7463
7484
|
// src/tags/conditional.ts
|
|
7464
7485
|
function truthy(value) {
|
|
7465
7486
|
return value !== false && value !== void 0 && value !== null;
|
|
@@ -7481,7 +7502,7 @@ function renderConditions(node2) {
|
|
|
7481
7502
|
}
|
|
7482
7503
|
var tagIf = {
|
|
7483
7504
|
attributes: {
|
|
7484
|
-
primary: { type:
|
|
7505
|
+
primary: { type: ConditionalAttributeType, render: false }
|
|
7485
7506
|
},
|
|
7486
7507
|
transform(node2, config) {
|
|
7487
7508
|
const conditions = renderConditions(node2);
|
|
@@ -7499,7 +7520,7 @@ var tagIf = {
|
|
|
7499
7520
|
var tagElse = {
|
|
7500
7521
|
selfClosing: true,
|
|
7501
7522
|
attributes: {
|
|
7502
|
-
primary: { type:
|
|
7523
|
+
primary: { type: ConditionalAttributeType, render: false }
|
|
7503
7524
|
}
|
|
7504
7525
|
};
|
|
7505
7526
|
|