@markdoc/markdoc 0.5.7 → 0.5.9
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/types.d.ts +2 -1
- package/dist/src/types.d.ts.map +1 -1
- 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/types.ts +3 -1
- package/src/utils.ts +30 -0
package/dist/index.js
CHANGED
|
@@ -6700,9 +6700,9 @@ var require_lib = __commonJS({
|
|
|
6700
6700
|
}
|
|
6701
6701
|
return this;
|
|
6702
6702
|
};
|
|
6703
|
-
MarkdownIt3.prototype.use = function(
|
|
6703
|
+
MarkdownIt3.prototype.use = function(plugin5) {
|
|
6704
6704
|
var args = [this].concat(Array.prototype.slice.call(arguments, 1));
|
|
6705
|
-
|
|
6705
|
+
plugin5.apply(plugin5, args);
|
|
6706
6706
|
return this;
|
|
6707
6707
|
};
|
|
6708
6708
|
MarkdownIt3.prototype.parse = function(src, env) {
|
|
@@ -6915,6 +6915,25 @@ function findTagEnd(content, start = 0) {
|
|
|
6915
6915
|
}
|
|
6916
6916
|
return null;
|
|
6917
6917
|
}
|
|
6918
|
+
function containsMarkdocTagInUrl(content, allowedProtocols) {
|
|
6919
|
+
for (let pos = 0; pos < content.length; pos++) {
|
|
6920
|
+
if (!content.startsWith(OPEN, pos)) continue;
|
|
6921
|
+
const end = findTagEnd(content, pos);
|
|
6922
|
+
if (end === null) {
|
|
6923
|
+
pos += OPEN.length - 1;
|
|
6924
|
+
continue;
|
|
6925
|
+
}
|
|
6926
|
+
let start = pos;
|
|
6927
|
+
while (start > 0 && !/\s/.test(content[start - 1])) start--;
|
|
6928
|
+
for (const protocol of allowedProtocols) {
|
|
6929
|
+
if (content.slice(start, pos).includes(`${protocol}://`)) {
|
|
6930
|
+
return true;
|
|
6931
|
+
}
|
|
6932
|
+
}
|
|
6933
|
+
return false;
|
|
6934
|
+
}
|
|
6935
|
+
return false;
|
|
6936
|
+
}
|
|
6918
6937
|
function parseTag(content, line, contentStart) {
|
|
6919
6938
|
try {
|
|
6920
6939
|
return (0, import_tag.parse)(content, { Variable, Function: Function2 });
|
|
@@ -8428,6 +8447,30 @@ function plugin3(md) {
|
|
|
8428
8447
|
md.inline.ruler.push("comment", inline3);
|
|
8429
8448
|
}
|
|
8430
8449
|
|
|
8450
|
+
// src/tokenizer/plugins/link.ts
|
|
8451
|
+
var INVALID_HREF_MESSAGE = "The 'href' format cannot contain Markdoc tag or variable. URLs must be static strings.";
|
|
8452
|
+
function pushHrefError(token) {
|
|
8453
|
+
const tokenWithErrors = token;
|
|
8454
|
+
if (!tokenWithErrors.errors) tokenWithErrors.errors = [];
|
|
8455
|
+
tokenWithErrors.errors.push({
|
|
8456
|
+
id: "href-format-invalid",
|
|
8457
|
+
level: "error",
|
|
8458
|
+
message: INVALID_HREF_MESSAGE
|
|
8459
|
+
});
|
|
8460
|
+
}
|
|
8461
|
+
function core2(state, options) {
|
|
8462
|
+
let token;
|
|
8463
|
+
for (token of state.tokens) {
|
|
8464
|
+
if (token.type !== "inline" || typeof token.content !== "string") continue;
|
|
8465
|
+
if (containsMarkdocTagInUrl(token.content, options.validatedProtocols)) {
|
|
8466
|
+
pushHrefError(token);
|
|
8467
|
+
}
|
|
8468
|
+
}
|
|
8469
|
+
}
|
|
8470
|
+
function plugin4(md, options) {
|
|
8471
|
+
md.core.ruler.push("link_url_validation", (state) => core2(state, options));
|
|
8472
|
+
}
|
|
8473
|
+
|
|
8431
8474
|
// src/tokenizer/index.ts
|
|
8432
8475
|
var Tokenizer = class {
|
|
8433
8476
|
constructor(config = {}) {
|
|
@@ -8440,6 +8483,14 @@ var Tokenizer = class {
|
|
|
8440
8483
|
"code"
|
|
8441
8484
|
]);
|
|
8442
8485
|
if (config.allowComments) this.parser.use(plugin3, "comments", {});
|
|
8486
|
+
if (config.allowLinkValidation) {
|
|
8487
|
+
this.parser.use(
|
|
8488
|
+
plugin4,
|
|
8489
|
+
config.linkValidationOptions ?? {
|
|
8490
|
+
validatedProtocols: ["http", "https"]
|
|
8491
|
+
}
|
|
8492
|
+
);
|
|
8493
|
+
}
|
|
8443
8494
|
}
|
|
8444
8495
|
tokenize(content) {
|
|
8445
8496
|
return this.parser.parse(content.toString(), {});
|