@markdoc/markdoc 0.5.7 → 0.5.8
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 +53 -2
- package/dist/index.js.map +4 -4
- package/dist/index.mjs +53 -2
- package/dist/index.mjs.map +4 -4
- package/dist/src/tokenizer/index.d.ts +5 -0
- package/dist/src/tokenizer/index.d.ts.map +1 -1
- package/dist/src/tokenizer/plugins/link.d.ts +4 -0
- package/dist/src/tokenizer/plugins/link.d.ts.map +1 -0
- package/dist/src/utils.d.ts +1 -0
- package/dist/src/utils.d.ts.map +1 -1
- package/package.json +1 -1
- package/spec/marktest/index.ts +136 -0
- package/src/tokenizer/index.ts +15 -0
- package/src/tokenizer/plugins/link.test.ts +96 -0
- package/src/tokenizer/plugins/link.ts +37 -0
- package/src/utils.ts +30 -0
package/dist/index.mjs
CHANGED
|
@@ -6698,9 +6698,9 @@ var require_lib = __commonJS({
|
|
|
6698
6698
|
}
|
|
6699
6699
|
return this;
|
|
6700
6700
|
};
|
|
6701
|
-
MarkdownIt3.prototype.use = function(
|
|
6701
|
+
MarkdownIt3.prototype.use = function(plugin5) {
|
|
6702
6702
|
var args = [this].concat(Array.prototype.slice.call(arguments, 1));
|
|
6703
|
-
|
|
6703
|
+
plugin5.apply(plugin5, args);
|
|
6704
6704
|
return this;
|
|
6705
6705
|
};
|
|
6706
6706
|
MarkdownIt3.prototype.parse = function(src, env) {
|
|
@@ -6886,6 +6886,25 @@ function findTagEnd(content, start = 0) {
|
|
|
6886
6886
|
}
|
|
6887
6887
|
return null;
|
|
6888
6888
|
}
|
|
6889
|
+
function containsMarkdocTagInUrl(content, allowedProtocols) {
|
|
6890
|
+
for (let pos = 0; pos < content.length; pos++) {
|
|
6891
|
+
if (!content.startsWith(OPEN, pos)) continue;
|
|
6892
|
+
const end = findTagEnd(content, pos);
|
|
6893
|
+
if (end === null) {
|
|
6894
|
+
pos += OPEN.length - 1;
|
|
6895
|
+
continue;
|
|
6896
|
+
}
|
|
6897
|
+
let start = pos;
|
|
6898
|
+
while (start > 0 && !/\s/.test(content[start - 1])) start--;
|
|
6899
|
+
for (const protocol of allowedProtocols) {
|
|
6900
|
+
if (content.slice(start, pos).includes(`${protocol}://`)) {
|
|
6901
|
+
return true;
|
|
6902
|
+
}
|
|
6903
|
+
}
|
|
6904
|
+
return false;
|
|
6905
|
+
}
|
|
6906
|
+
return false;
|
|
6907
|
+
}
|
|
6889
6908
|
function parseTag(content, line, contentStart) {
|
|
6890
6909
|
try {
|
|
6891
6910
|
return (0, import_tag.parse)(content, { Variable, Function: Function2 });
|
|
@@ -8399,6 +8418,30 @@ function plugin3(md) {
|
|
|
8399
8418
|
md.inline.ruler.push("comment", inline3);
|
|
8400
8419
|
}
|
|
8401
8420
|
|
|
8421
|
+
// src/tokenizer/plugins/link.ts
|
|
8422
|
+
var INVALID_HREF_MESSAGE = "The 'href' format cannot contain Markdoc tag or variable. URLs must be static strings.";
|
|
8423
|
+
function pushHrefError(token) {
|
|
8424
|
+
const tokenWithErrors = token;
|
|
8425
|
+
if (!tokenWithErrors.errors) tokenWithErrors.errors = [];
|
|
8426
|
+
tokenWithErrors.errors.push({
|
|
8427
|
+
id: "href-format-invalid",
|
|
8428
|
+
level: "error",
|
|
8429
|
+
message: INVALID_HREF_MESSAGE
|
|
8430
|
+
});
|
|
8431
|
+
}
|
|
8432
|
+
function core2(state, options) {
|
|
8433
|
+
let token;
|
|
8434
|
+
for (token of state.tokens) {
|
|
8435
|
+
if (token.type !== "inline" || typeof token.content !== "string") continue;
|
|
8436
|
+
if (containsMarkdocTagInUrl(token.content, options.validatedProtocols)) {
|
|
8437
|
+
pushHrefError(token);
|
|
8438
|
+
}
|
|
8439
|
+
}
|
|
8440
|
+
}
|
|
8441
|
+
function plugin4(md, options) {
|
|
8442
|
+
md.core.ruler.push("link_url_validation", (state) => core2(state, options));
|
|
8443
|
+
}
|
|
8444
|
+
|
|
8402
8445
|
// src/tokenizer/index.ts
|
|
8403
8446
|
var Tokenizer = class {
|
|
8404
8447
|
constructor(config = {}) {
|
|
@@ -8411,6 +8454,14 @@ var Tokenizer = class {
|
|
|
8411
8454
|
"code"
|
|
8412
8455
|
]);
|
|
8413
8456
|
if (config.allowComments) this.parser.use(plugin3, "comments", {});
|
|
8457
|
+
if (config.allowLinkValidation) {
|
|
8458
|
+
this.parser.use(
|
|
8459
|
+
plugin4,
|
|
8460
|
+
config.linkValidationOptions ?? {
|
|
8461
|
+
validatedProtocols: ["http", "https"]
|
|
8462
|
+
}
|
|
8463
|
+
);
|
|
8464
|
+
}
|
|
8414
8465
|
}
|
|
8415
8466
|
tokenize(content) {
|
|
8416
8467
|
return this.parser.parse(content.toString(), {});
|