@mintlify/common 1.0.764 → 1.0.765
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.
|
@@ -1,4 +1 @@
|
|
|
1
|
-
export declare const VARIABLE_REGEX: RegExp;
|
|
2
1
|
export declare function replaceVariables(content: string, variables: Record<string, string> | undefined): string;
|
|
3
|
-
export declare function escapeMdxVariables(content: string): string;
|
|
4
|
-
export declare function getUndefinedVariables(content: string, variables: Record<string, string> | undefined): string[];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import filterXSS from 'xss';
|
|
2
|
-
|
|
2
|
+
const VARIABLE_REGEX = /\{\{\s*([\w.\-]+)\s*\}\}/g;
|
|
3
3
|
const EXECUTABLE_TAGS = [
|
|
4
4
|
'script',
|
|
5
5
|
'style',
|
|
@@ -26,23 +26,3 @@ export function replaceVariables(content, variables) {
|
|
|
26
26
|
return value !== undefined ? sanitizeVariableValue(value) : match;
|
|
27
27
|
});
|
|
28
28
|
}
|
|
29
|
-
const FENCED_OR_INLINE_OR_VARIABLE = /(`{3,}|~{3,})[^\n]*[\s\S]*?\1|(`+)[^`\n]*\2|\{\{[^}]*\}\}/g;
|
|
30
|
-
export function escapeMdxVariables(content) {
|
|
31
|
-
if (!content.includes('{{'))
|
|
32
|
-
return content;
|
|
33
|
-
return content.replace(FENCED_OR_INLINE_OR_VARIABLE, (match) => match.startsWith('{{') ? `\`${match}\`` : match);
|
|
34
|
-
}
|
|
35
|
-
export function getUndefinedVariables(content, variables) {
|
|
36
|
-
if (!content.includes('{{'))
|
|
37
|
-
return [];
|
|
38
|
-
const undefinedKeys = new Set();
|
|
39
|
-
let match;
|
|
40
|
-
VARIABLE_REGEX.lastIndex = 0;
|
|
41
|
-
while ((match = VARIABLE_REGEX.exec(content)) !== null) {
|
|
42
|
-
const key = match[1];
|
|
43
|
-
if (key && (!variables || variables[key] === undefined)) {
|
|
44
|
-
undefinedKeys.add(key);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
return Array.from(undefinedKeys);
|
|
48
|
-
}
|