@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
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
import MarkdownIt from 'markdown-it/lib';
|
|
2
2
|
import type Token from 'markdown-it/lib/token';
|
|
3
|
+
export type LinkPluginOptions = {
|
|
4
|
+
validatedProtocols: string[];
|
|
5
|
+
};
|
|
3
6
|
export default class Tokenizer {
|
|
4
7
|
private parser;
|
|
5
8
|
constructor(config?: MarkdownIt.Options & {
|
|
6
9
|
allowIndentation?: boolean;
|
|
7
10
|
allowComments?: boolean;
|
|
11
|
+
allowLinkValidation?: boolean;
|
|
12
|
+
linkValidationOptions?: LinkPluginOptions;
|
|
8
13
|
});
|
|
9
14
|
tokenize(content: string): Token[];
|
|
10
15
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/tokenizer/index.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/tokenizer/index.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,iBAAiB,CAAC;AAKzC,OAAO,KAAK,KAAK,MAAM,uBAAuB,CAAC;AAE/C,MAAM,MAAM,iBAAiB,GAAG;IAAE,kBAAkB,EAAE,MAAM,EAAE,CAAA;CAAE,CAAC;AAEjE,MAAM,CAAC,OAAO,OAAO,SAAS;IAC5B,OAAO,CAAC,MAAM,CAAa;gBAGzB,MAAM,GAAE,UAAU,CAAC,OAAO,GAAG;QAC3B,gBAAgB,CAAC,EAAE,OAAO,CAAC;QAC3B,aAAa,CAAC,EAAE,OAAO,CAAC;QACxB,mBAAmB,CAAC,EAAE,OAAO,CAAC;QAC9B,qBAAqB,CAAC,EAAE,iBAAiB,CAAC;KACtC;IAwBR,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,KAAK,EAAE;CAGnC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"link.d.ts","sourceRoot":"","sources":["../../../../src/tokenizer/plugins/link.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,iBAAiB,CAAC;AAM9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,IAAI,CAAC;AA4BvC,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,EAAE,EAAE,UAAU,EAAE,OAAO,EAAE,iBAAiB,QAExE"}
|
package/dist/src/utils.d.ts
CHANGED
|
@@ -5,5 +5,6 @@ export declare const IDENTIFIER_REGEX: RegExp;
|
|
|
5
5
|
export declare function isIdentifier(s: any): s is string;
|
|
6
6
|
export declare function isPromise(a: any): a is Promise<any>;
|
|
7
7
|
export declare function findTagEnd(content: string, start?: number): number | null;
|
|
8
|
+
export declare function containsMarkdocTagInUrl(content: string, allowedProtocols: string[]): boolean;
|
|
8
9
|
export declare function parseTags(content: string, firstLine?: number): Token[];
|
|
9
10
|
//# sourceMappingURL=utils.d.ts.map
|
package/dist/src/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,KAAK,MAAM,uBAAuB,CAAC;AAQ/C,eAAO,MAAM,IAAI,OAAO,CAAC;AACzB,eAAO,MAAM,KAAK,OAAO,CAAC;AAE1B,eAAO,MAAM,gBAAgB,QAAqB,CAAC;AAEnD,wBAAgB,YAAY,CAAC,CAAC,EAAE,GAAG,GAAG,CAAC,IAAI,MAAM,CAEhD;AAED,wBAAgB,SAAS,CAAC,CAAC,EAAE,GAAG,GAAG,CAAC,IAAI,OAAO,CAAC,GAAG,CAAC,CAEnD;AAED,wBAAgB,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,SAAI,iBA0BpD;AAoBD,wBAAgB,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,SAAI,GAAG,KAAK,EAAE,CA+DjE"}
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,KAAK,MAAM,uBAAuB,CAAC;AAQ/C,eAAO,MAAM,IAAI,OAAO,CAAC;AACzB,eAAO,MAAM,KAAK,OAAO,CAAC;AAE1B,eAAO,MAAM,gBAAgB,QAAqB,CAAC;AAEnD,wBAAgB,YAAY,CAAC,CAAC,EAAE,GAAG,GAAG,CAAC,IAAI,MAAM,CAEhD;AAED,wBAAgB,SAAS,CAAC,CAAC,EAAE,GAAG,GAAG,CAAC,IAAI,OAAO,CAAC,GAAG,CAAC,CAEnD;AAED,wBAAgB,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,SAAI,iBA0BpD;AAED,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,MAAM,EACf,gBAAgB,EAAE,MAAM,EAAE,WA0B3B;AAoBD,wBAAgB,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,SAAI,GAAG,KAAK,EAAE,CA+DjE"}
|
package/package.json
CHANGED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { promises as fs } from 'fs';
|
|
2
|
+
import { resolve } from 'path';
|
|
3
|
+
import { diffJson, diffChars } from 'diff';
|
|
4
|
+
import yaml from 'yaml-js';
|
|
5
|
+
|
|
6
|
+
import markdoc from '../../index';
|
|
7
|
+
import React from './react-shim';
|
|
8
|
+
|
|
9
|
+
class Loader extends yaml.loader.Loader {
|
|
10
|
+
construct_mapping(node) {
|
|
11
|
+
return {
|
|
12
|
+
...super.construct_mapping(node),
|
|
13
|
+
$$lines: {
|
|
14
|
+
start: node.start_mark.line,
|
|
15
|
+
end: node.end_mark.line,
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const tokenizer = new markdoc.Tokenizer({
|
|
22
|
+
allowIndentation: true,
|
|
23
|
+
allowComments: true,
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
function parse(content: string, slots?: boolean, file?: string) {
|
|
27
|
+
const tokens = tokenizer.tokenize(content);
|
|
28
|
+
return markdoc.parse(tokens, { file, slots });
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function stripLines(object) {
|
|
32
|
+
const removeLines = (key, value) => (key === '$$lines' ? undefined : value);
|
|
33
|
+
return JSON.parse(JSON.stringify(object, removeLines));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function render(code, config, dynamic) {
|
|
37
|
+
const partials = {};
|
|
38
|
+
for (const [file, content] of Object.entries(config.partials ?? {}))
|
|
39
|
+
partials[file] = parse(content as string, false, file);
|
|
40
|
+
|
|
41
|
+
const { react, reactStatic } = markdoc.renderers;
|
|
42
|
+
const transformed = markdoc.transform(code, { ...config, partials });
|
|
43
|
+
return dynamic ? react(transformed, React) : eval(reactStatic(transformed));
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function checkMatch(diffs) {
|
|
47
|
+
return diffs.find((diff) => diff.added || diff.removed);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function run(
|
|
51
|
+
{ code = null, renderer = 'react', config = {}, expected = undefined } = {},
|
|
52
|
+
dynamic
|
|
53
|
+
) {
|
|
54
|
+
if (renderer === 'html') {
|
|
55
|
+
const transformed = markdoc.transform(code, config);
|
|
56
|
+
const output = markdoc.renderers.html(transformed);
|
|
57
|
+
const diff = diffChars((expected || '').trim(), (output || '').trim());
|
|
58
|
+
return checkMatch(diff) ? diff : false;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const output = render(code, config, dynamic) || {};
|
|
62
|
+
const diff = diffJson(expected || {}, output.children || []);
|
|
63
|
+
return checkMatch(diff) ? diff : false;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function formatter(filename, { $$lines: lines, name, code }, diff) {
|
|
67
|
+
const prettyDiff = diff
|
|
68
|
+
.flatMap((part) => [
|
|
69
|
+
part.added ? '\x1b[32m' : part.removed ? '\x1b[31m' : '\x1b[0m',
|
|
70
|
+
part.added || part.removed ? part.value.replace(/ /g, '⎵') : part.value,
|
|
71
|
+
])
|
|
72
|
+
.join('');
|
|
73
|
+
|
|
74
|
+
return [
|
|
75
|
+
`\x1b[31mFAILED:\x1b[0m ${filename}:${lines.start}`,
|
|
76
|
+
name,
|
|
77
|
+
code,
|
|
78
|
+
prettyDiff,
|
|
79
|
+
].join('\n\n');
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function formatValidation(filename, test, validation) {
|
|
83
|
+
const { $$lines: lines, name, code } = test;
|
|
84
|
+
|
|
85
|
+
let output = '';
|
|
86
|
+
for (const {
|
|
87
|
+
lines,
|
|
88
|
+
error: { message },
|
|
89
|
+
} of validation)
|
|
90
|
+
output += `${lines ? lines[0] : '?'}:${message}\n`;
|
|
91
|
+
|
|
92
|
+
return [
|
|
93
|
+
`\x1b[31mINVALID:\x1b[0m ${filename}:${lines.start}`,
|
|
94
|
+
name,
|
|
95
|
+
code,
|
|
96
|
+
output,
|
|
97
|
+
].join('\n\n');
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
(async () => {
|
|
101
|
+
const [filename, line] = process.argv.slice(2).join('').split(':');
|
|
102
|
+
const path = resolve(filename);
|
|
103
|
+
const file = await fs.readFile(path);
|
|
104
|
+
const tests = yaml.load(file, Loader);
|
|
105
|
+
|
|
106
|
+
let exitCode = 0;
|
|
107
|
+
for (const test of tests) {
|
|
108
|
+
const code = parse(test.code || '', test.slots);
|
|
109
|
+
|
|
110
|
+
const { start, end } = test.$$lines;
|
|
111
|
+
if (line && (Number(line) - 1 < start || Number(line) - 1 > end)) continue;
|
|
112
|
+
|
|
113
|
+
const validation = markdoc.validate(code, test.config);
|
|
114
|
+
|
|
115
|
+
let result;
|
|
116
|
+
if (test.expectedError) {
|
|
117
|
+
const output = validation.map((v) => v.error.message).join('\n');
|
|
118
|
+
const diff = diffChars(
|
|
119
|
+
(test.expectedError || '').trim(),
|
|
120
|
+
(output || '').trim()
|
|
121
|
+
);
|
|
122
|
+
|
|
123
|
+
result = checkMatch(diff) ? diff : false;
|
|
124
|
+
} else {
|
|
125
|
+
if (validation.length && test.validation != false)
|
|
126
|
+
console.log(formatValidation(path, test, validation));
|
|
127
|
+
|
|
128
|
+
result = run({ ...stripLines(test), code }, true);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
if (!result) continue;
|
|
132
|
+
console.log(formatter(path, test, result));
|
|
133
|
+
exitCode = 1;
|
|
134
|
+
}
|
|
135
|
+
process.exit(exitCode);
|
|
136
|
+
})();
|
package/src/tokenizer/index.ts
CHANGED
|
@@ -2,8 +2,11 @@ import MarkdownIt from 'markdown-it/lib';
|
|
|
2
2
|
import annotations from './plugins/annotations';
|
|
3
3
|
import frontmatter from './plugins/frontmatter';
|
|
4
4
|
import comments from './plugins/comments';
|
|
5
|
+
import link from './plugins/link';
|
|
5
6
|
import type Token from 'markdown-it/lib/token';
|
|
6
7
|
|
|
8
|
+
export type LinkPluginOptions = { validatedProtocols: string[] };
|
|
9
|
+
|
|
7
10
|
export default class Tokenizer {
|
|
8
11
|
private parser: MarkdownIt;
|
|
9
12
|
|
|
@@ -11,11 +14,14 @@ export default class Tokenizer {
|
|
|
11
14
|
config: MarkdownIt.Options & {
|
|
12
15
|
allowIndentation?: boolean;
|
|
13
16
|
allowComments?: boolean;
|
|
17
|
+
allowLinkValidation?: boolean;
|
|
18
|
+
linkValidationOptions?: LinkPluginOptions;
|
|
14
19
|
} = {}
|
|
15
20
|
) {
|
|
16
21
|
this.parser = new MarkdownIt(config);
|
|
17
22
|
this.parser.use(annotations, 'annotations', {});
|
|
18
23
|
this.parser.use(frontmatter, 'frontmatter', {});
|
|
24
|
+
|
|
19
25
|
this.parser.disable([
|
|
20
26
|
'lheading',
|
|
21
27
|
// Disable indented `code_block` support https://spec.commonmark.org/0.30/#indented-code-block
|
|
@@ -23,6 +29,15 @@ export default class Tokenizer {
|
|
|
23
29
|
]);
|
|
24
30
|
|
|
25
31
|
if (config.allowComments) this.parser.use(comments, 'comments', {});
|
|
32
|
+
if (config.allowLinkValidation) {
|
|
33
|
+
// Set http and https as the default protocols to validate
|
|
34
|
+
this.parser.use(
|
|
35
|
+
link,
|
|
36
|
+
config.linkValidationOptions ?? {
|
|
37
|
+
validatedProtocols: ['http', 'https'],
|
|
38
|
+
}
|
|
39
|
+
);
|
|
40
|
+
}
|
|
26
41
|
}
|
|
27
42
|
|
|
28
43
|
tokenize(content: string): Token[] {
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import Tokenizer from '..';
|
|
2
|
+
|
|
3
|
+
describe('MarkdownIt Link plugin', function () {
|
|
4
|
+
function parse(
|
|
5
|
+
example: string,
|
|
6
|
+
tokenizer: Tokenizer = new Tokenizer({ allowLinkValidation: true })
|
|
7
|
+
) {
|
|
8
|
+
const content = example.replace(/\n\s+/gm, '\n').trim();
|
|
9
|
+
return tokenizer.tokenize(content);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function getInlineError(tokens) {
|
|
13
|
+
return tokens.find((token) => token.type === 'inline')?.errors?.[0];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
it('accepts valid link urls and markdoc tag in one paragraph', function () {
|
|
17
|
+
const tokens = parse(`The link is https://example.com. {% tag /%})`);
|
|
18
|
+
expect(getInlineError(tokens)).toBeUndefined();
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it('accepts raw tag content in markdown link format', function () {
|
|
22
|
+
const tokens = parse(`[Link]({% tag %})`);
|
|
23
|
+
expect(getInlineError(tokens)).toBeUndefined();
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('rejects plain link url with tags', function () {
|
|
27
|
+
const tokens = parse(`https://example.com/{% tag %}content{% /tag %})`);
|
|
28
|
+
expect(getInlineError(tokens)).toDeepEqualSubset({
|
|
29
|
+
id: 'href-format-invalid',
|
|
30
|
+
level: 'error',
|
|
31
|
+
message:
|
|
32
|
+
"The 'href' format cannot contain Markdoc tag or variable. URLs must be static strings.",
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('rejects URL with parenthesis in link', function () {
|
|
37
|
+
const tokens = parse(
|
|
38
|
+
`https://en.wikipedia.org/wiki/Exam_(disambiguation){% tag /%}`
|
|
39
|
+
);
|
|
40
|
+
expect(getInlineError(tokens)).toDeepEqualSubset({
|
|
41
|
+
id: 'href-format-invalid',
|
|
42
|
+
level: 'error',
|
|
43
|
+
message:
|
|
44
|
+
"The 'href' format cannot contain Markdoc tag or variable. URLs must be static strings.",
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('rejects variables in markdown link urls', function () {
|
|
49
|
+
const tokens = parse(`[Link](https://{% $variable.custom_value %})`);
|
|
50
|
+
expect(getInlineError(tokens)).toDeepEqualSubset({
|
|
51
|
+
id: 'href-format-invalid',
|
|
52
|
+
level: 'error',
|
|
53
|
+
message:
|
|
54
|
+
"The 'href' format cannot contain Markdoc tag or variable. URLs must be static strings.",
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('rejects self-closing tags in markdown link urls', function () {
|
|
59
|
+
const tokens = parse(`[Link](https://example.com/{% tag /%})`);
|
|
60
|
+
expect(getInlineError(tokens)).toDeepEqualSubset({
|
|
61
|
+
id: 'href-format-invalid',
|
|
62
|
+
level: 'error',
|
|
63
|
+
message:
|
|
64
|
+
"The 'href' format cannot contain Markdoc tag or variable. URLs must be static strings.",
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('rejects non self-closing tags in markdown link urls', function () {
|
|
69
|
+
const tokens = parse(
|
|
70
|
+
`[Link](https://example.com/{% tag %}content{% /tag %})`
|
|
71
|
+
);
|
|
72
|
+
expect(getInlineError(tokens)).toDeepEqualSubset({
|
|
73
|
+
id: 'href-format-invalid',
|
|
74
|
+
level: 'error',
|
|
75
|
+
message:
|
|
76
|
+
"The 'href' format cannot contain Markdoc tag or variable. URLs must be static strings.",
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('rejects custom protocols defined in the config with markdoc variable', function () {
|
|
81
|
+
const tokenizer = new Tokenizer({
|
|
82
|
+
allowLinkValidation: true,
|
|
83
|
+
linkValidationOptions: { validatedProtocols: ['vscode'] },
|
|
84
|
+
});
|
|
85
|
+
const tokens = parse(
|
|
86
|
+
`[Link](vscode://{% $variable.custom_value %})`,
|
|
87
|
+
tokenizer
|
|
88
|
+
);
|
|
89
|
+
expect(getInlineError(tokens)).toDeepEqualSubset({
|
|
90
|
+
id: 'href-format-invalid',
|
|
91
|
+
level: 'error',
|
|
92
|
+
message:
|
|
93
|
+
"The 'href' format cannot contain Markdoc tag or variable. URLs must be static strings.",
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type MarkdownIt from 'markdown-it/lib';
|
|
2
|
+
import type StateCore from 'markdown-it/lib/rules_core/state_core';
|
|
3
|
+
import type Token from 'markdown-it/lib/token';
|
|
4
|
+
import type { ValidationError } from '../../types';
|
|
5
|
+
|
|
6
|
+
import { containsMarkdocTagInUrl } from '../../utils';
|
|
7
|
+
import { LinkPluginOptions } from '..';
|
|
8
|
+
|
|
9
|
+
const INVALID_HREF_MESSAGE =
|
|
10
|
+
"The 'href' format cannot contain Markdoc tag or variable. URLs must be static strings.";
|
|
11
|
+
|
|
12
|
+
type TokenWithErrors = Token & { errors?: ValidationError[] };
|
|
13
|
+
|
|
14
|
+
function pushHrefError(token: Token) {
|
|
15
|
+
const tokenWithErrors = token as TokenWithErrors;
|
|
16
|
+
if (!tokenWithErrors.errors) tokenWithErrors.errors = [];
|
|
17
|
+
tokenWithErrors.errors.push({
|
|
18
|
+
id: 'href-format-invalid',
|
|
19
|
+
level: 'error',
|
|
20
|
+
message: INVALID_HREF_MESSAGE,
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function core(state: StateCore, options: LinkPluginOptions) {
|
|
25
|
+
let token: Token;
|
|
26
|
+
for (token of state.tokens) {
|
|
27
|
+
if (token.type !== 'inline' || typeof token.content !== 'string') continue;
|
|
28
|
+
|
|
29
|
+
if (containsMarkdocTagInUrl(token.content, options.validatedProtocols)) {
|
|
30
|
+
pushHrefError(token);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export default function plugin(md: MarkdownIt, options: LinkPluginOptions) {
|
|
36
|
+
md.core.ruler.push('link_url_validation', (state) => core(state, options));
|
|
37
|
+
}
|
package/src/utils.ts
CHANGED
|
@@ -51,6 +51,36 @@ export function findTagEnd(content: string, start = 0) {
|
|
|
51
51
|
return null;
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
+
export function containsMarkdocTagInUrl(
|
|
55
|
+
content: string,
|
|
56
|
+
allowedProtocols: string[]
|
|
57
|
+
) {
|
|
58
|
+
for (let pos = 0; pos < content.length; pos++) {
|
|
59
|
+
if (!content.startsWith(OPEN, pos)) continue;
|
|
60
|
+
|
|
61
|
+
const end = findTagEnd(content, pos);
|
|
62
|
+
if (end === null) {
|
|
63
|
+
// If we cannot find the closing tag, we skip over it
|
|
64
|
+
pos += OPEN.length - 1;
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Locate the start of the content from the tag start (stop tracing the starting position when it hits the first whitespace)
|
|
69
|
+
let start = pos;
|
|
70
|
+
while (start > 0 && !/\s/.test(content[start - 1])) start--;
|
|
71
|
+
|
|
72
|
+
// Check if the content contains the URL.
|
|
73
|
+
for (const protocol of allowedProtocols) {
|
|
74
|
+
if (content.slice(start, pos).includes(`${protocol}://`)) {
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
|
|
54
84
|
function parseTag(content: string, line: number, contentStart: number) {
|
|
55
85
|
try {
|
|
56
86
|
return parse(content, { Variable, Function });
|