@markdoc/markdoc 0.5.2 → 0.5.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/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 +5 -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.mjs
CHANGED
|
@@ -7173,8 +7173,13 @@ function* formatNode(n, o = {}) {
|
|
|
7173
7173
|
break;
|
|
7174
7174
|
}
|
|
7175
7175
|
case "link": {
|
|
7176
|
+
const children = [...formatChildren(n, no)].join("");
|
|
7177
|
+
if (children === n.attributes.href && !n.attributes.title) {
|
|
7178
|
+
yield `<${n.attributes.href}>`;
|
|
7179
|
+
break;
|
|
7180
|
+
}
|
|
7176
7181
|
yield "[";
|
|
7177
|
-
yield
|
|
7182
|
+
yield children;
|
|
7178
7183
|
yield "]";
|
|
7179
7184
|
yield "(";
|
|
7180
7185
|
yield* typeof n.attributes.href === "string" ? escapeMarkdownCharacters(n.attributes.href, /[()]/g) : formatValue(n.attributes.href, no);
|
|
@@ -7194,7 +7199,7 @@ function* formatNode(n, o = {}) {
|
|
|
7194
7199
|
if (o.parent && WRAPPING_TYPES.includes(o.parent.type)) {
|
|
7195
7200
|
yield* escapeMarkdownCharacters(content, /[*_~]/g);
|
|
7196
7201
|
} else {
|
|
7197
|
-
yield* escapeMarkdownCharacters(content,
|
|
7202
|
+
yield* escapeMarkdownCharacters(content, /^\*|#+\s|>/);
|
|
7198
7203
|
}
|
|
7199
7204
|
}
|
|
7200
7205
|
break;
|
|
@@ -7435,6 +7440,22 @@ function format(v, options) {
|
|
|
7435
7440
|
return doc.trimStart();
|
|
7436
7441
|
}
|
|
7437
7442
|
|
|
7443
|
+
// src/schema-types/conditional.ts
|
|
7444
|
+
var ConditionalAttributeType = class {
|
|
7445
|
+
validate(value, _config, key) {
|
|
7446
|
+
if (typeof value === "boolean" || value === null || value === void 0 || typeof value === "object") {
|
|
7447
|
+
return [];
|
|
7448
|
+
}
|
|
7449
|
+
return [
|
|
7450
|
+
{
|
|
7451
|
+
id: "attribute-type-invalid",
|
|
7452
|
+
level: "error",
|
|
7453
|
+
message: `Attribute '${key}' must be type 'boolean | object' (null or undefined are also allowed)`
|
|
7454
|
+
}
|
|
7455
|
+
];
|
|
7456
|
+
}
|
|
7457
|
+
};
|
|
7458
|
+
|
|
7438
7459
|
// src/tags/conditional.ts
|
|
7439
7460
|
function truthy(value) {
|
|
7440
7461
|
return value !== false && value !== void 0 && value !== null;
|
|
@@ -7456,7 +7477,7 @@ function renderConditions(node2) {
|
|
|
7456
7477
|
}
|
|
7457
7478
|
var tagIf = {
|
|
7458
7479
|
attributes: {
|
|
7459
|
-
primary: { type:
|
|
7480
|
+
primary: { type: ConditionalAttributeType, render: false }
|
|
7460
7481
|
},
|
|
7461
7482
|
transform(node2, config) {
|
|
7462
7483
|
const conditions = renderConditions(node2);
|
|
@@ -7474,7 +7495,7 @@ var tagIf = {
|
|
|
7474
7495
|
var tagElse = {
|
|
7475
7496
|
selfClosing: true,
|
|
7476
7497
|
attributes: {
|
|
7477
|
-
primary: { type:
|
|
7498
|
+
primary: { type: ConditionalAttributeType, render: false }
|
|
7478
7499
|
}
|
|
7479
7500
|
};
|
|
7480
7501
|
|