@mintlify/common 1.0.753 → 1.0.755
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,8 +1,28 @@
|
|
|
1
|
+
import filterXSS from 'xss';
|
|
2
|
+
const VARIABLE_REGEX = /\{\{\s*([\w.\-]+)\s*\}\}/g;
|
|
3
|
+
const EXECUTABLE_TAGS = [
|
|
4
|
+
'script',
|
|
5
|
+
'style',
|
|
6
|
+
'iframe',
|
|
7
|
+
'object',
|
|
8
|
+
'embed',
|
|
9
|
+
'form',
|
|
10
|
+
'link',
|
|
11
|
+
'meta',
|
|
12
|
+
'base',
|
|
13
|
+
];
|
|
14
|
+
function sanitizeVariableValue(value) {
|
|
15
|
+
return filterXSS(value, {
|
|
16
|
+
whiteList: {},
|
|
17
|
+
stripIgnoreTag: true,
|
|
18
|
+
stripIgnoreTagBody: EXECUTABLE_TAGS,
|
|
19
|
+
});
|
|
20
|
+
}
|
|
1
21
|
export function replaceVariables(content, variables) {
|
|
2
22
|
if (!variables || Object.keys(variables).length === 0 || !content.includes('{{'))
|
|
3
23
|
return content;
|
|
4
|
-
return content.replace(
|
|
24
|
+
return content.replace(VARIABLE_REGEX, (match, key) => {
|
|
5
25
|
const value = variables[key];
|
|
6
|
-
return value !== undefined ? value : match;
|
|
26
|
+
return value !== undefined ? sanitizeVariableValue(value) : match;
|
|
7
27
|
});
|
|
8
28
|
}
|
|
@@ -26,7 +26,7 @@ export function createSnippetTreeMap(snippets) {
|
|
|
26
26
|
// TODO: Better error handling for cyclical references
|
|
27
27
|
if (((_a = orderedSnippets[0]) === null || _a === void 0 ? void 0 : _a.numSnippetsInContent) === 0) {
|
|
28
28
|
orderedSnippets.forEach((snippet) => {
|
|
29
|
-
treeMap =
|
|
29
|
+
treeMap = parseSnippetContentToMap(snippet, treeMap);
|
|
30
30
|
});
|
|
31
31
|
return treeMap;
|
|
32
32
|
}
|
|
@@ -34,7 +34,7 @@ export function createSnippetTreeMap(snippets) {
|
|
|
34
34
|
orderedSnippets.forEach((snippet) => __awaiter(this, void 0, void 0, function* () {
|
|
35
35
|
if (snippet.numSnippetsInContent === 0) {
|
|
36
36
|
// No need to remove references if none exist
|
|
37
|
-
treeMap =
|
|
37
|
+
treeMap = parseSnippetContentToMap(snippet, treeMap);
|
|
38
38
|
}
|
|
39
39
|
if (failedParseArr.length > 0) {
|
|
40
40
|
let prevArrLength = failedParseArr.length + 1;
|
|
@@ -65,7 +65,7 @@ export function createSnippetTreeMap(snippets) {
|
|
|
65
65
|
return treeMap;
|
|
66
66
|
});
|
|
67
67
|
}
|
|
68
|
-
function
|
|
68
|
+
function parseSnippetContentToMap(snippet, map) {
|
|
69
69
|
try {
|
|
70
70
|
const tree = fromMarkdown(snippet.content, {
|
|
71
71
|
extensions: [gfm(), mdxjs()],
|
|
@@ -82,7 +82,7 @@ function addSnippetTreeToMap(snippet, map) {
|
|
|
82
82
|
function addParsedSnippetTreeToMap(snippet, treeMap) {
|
|
83
83
|
return __awaiter(this, void 0, void 0, function* () {
|
|
84
84
|
const parsedContent = yield preparseSnippet(snippet, treeMap);
|
|
85
|
-
return
|
|
85
|
+
return parseSnippetContentToMap(Object.assign(Object.assign({}, snippet), { content: parsedContent }), treeMap);
|
|
86
86
|
});
|
|
87
87
|
}
|
|
88
88
|
/*
|
|
@@ -11,7 +11,7 @@ export type GetMdxType = {
|
|
|
11
11
|
panelMdxSource?: SerializeSuccess;
|
|
12
12
|
panelMdxSourceWithNoJs?: SerializeSuccess;
|
|
13
13
|
};
|
|
14
|
-
export declare function getMdx({ path, content, metadata, snippets, subdomain, codeStyling, config, tailwindSelectors, pageType, trace, customLanguages, }: {
|
|
14
|
+
export declare function getMdx({ path, content, metadata, snippets, subdomain, codeStyling, config, tailwindSelectors, pageType, trace, customLanguages, variables, }: {
|
|
15
15
|
path: string;
|
|
16
16
|
content: string;
|
|
17
17
|
metadata: PageMetaTags;
|
|
@@ -23,5 +23,6 @@ export declare function getMdx({ path, content, metadata, snippets, subdomain, c
|
|
|
23
23
|
pageType?: PageType;
|
|
24
24
|
trace?: RunWithTracingFn;
|
|
25
25
|
customLanguages?: string[];
|
|
26
|
+
variables?: Record<string, string>;
|
|
26
27
|
}): Promise<GetMdxType>;
|
|
27
28
|
export { createSnippetTreeMap, type Snippet };
|
|
@@ -11,13 +11,16 @@ import { serialize } from '@mintlify/mdx/server';
|
|
|
11
11
|
import { getTailwindSelectors } from '../../css/tailwind.js';
|
|
12
12
|
import { getMDXOptions, remarkMdxRemoveJs, remarkExpandContent, remarkSplitCodeGroup, remarkSplitTabs, remarkValidateSteps, remarkValidateTabs, } from '../../index.js';
|
|
13
13
|
import { codeStylingToThemeOrThemes } from '../getCodeStyling.js';
|
|
14
|
+
import { replaceVariables } from '../replaceVariables.js';
|
|
14
15
|
import { createSnippetTreeMap } from './getMdx/snippets.js';
|
|
15
16
|
export function getMdx(_a) {
|
|
16
|
-
return __awaiter(this, arguments, void 0, function* ({ path, content, metadata, snippets, subdomain, codeStyling, config, tailwindSelectors = undefined, pageType = 'default', trace = undefined, customLanguages = [], }) {
|
|
17
|
+
return __awaiter(this, arguments, void 0, function* ({ path, content, metadata, snippets, subdomain, codeStyling, config, tailwindSelectors = undefined, pageType = 'default', trace = undefined, customLanguages = [], variables = undefined, }) {
|
|
17
18
|
const traceFn = trace !== null && trace !== void 0 ? trace : ((_name, fn) => fn());
|
|
19
|
+
const processedContent = replaceVariables(content, variables);
|
|
20
|
+
const processedSnippets = snippets.map((snippet) => (Object.assign(Object.assign({}, snippet), { content: replaceVariables(snippet.content, variables) })));
|
|
18
21
|
if (!tailwindSelectors)
|
|
19
|
-
tailwindSelectors = yield traceFn('getMdx.getTailwindSelectors', () => __awaiter(this, void 0, void 0, function* () { return getTailwindSelectors({ content }); }));
|
|
20
|
-
const snippetTreeMap = yield traceFn('getMdx.createSnippetTreeMap', () => __awaiter(this, void 0, void 0, function* () { return createSnippetTreeMap(
|
|
22
|
+
tailwindSelectors = yield traceFn('getMdx.getTailwindSelectors', () => __awaiter(this, void 0, void 0, function* () { return getTailwindSelectors({ content: processedContent }); }));
|
|
23
|
+
const snippetTreeMap = yield traceFn('getMdx.createSnippetTreeMap', () => __awaiter(this, void 0, void 0, function* () { return createSnippetTreeMap(processedSnippets); }));
|
|
21
24
|
const mdxOptionsData = {
|
|
22
25
|
subdomain,
|
|
23
26
|
snippetTreeMap,
|
|
@@ -43,7 +46,7 @@ export function getMdx(_a) {
|
|
|
43
46
|
};
|
|
44
47
|
const { mdxSource, mdxSourceWithNoJs } = yield traceFn('getMdx.compileMdx.mainContent', () => __awaiter(this, void 0, void 0, function* () {
|
|
45
48
|
return compileMdx({
|
|
46
|
-
content,
|
|
49
|
+
content: processedContent,
|
|
47
50
|
scope,
|
|
48
51
|
mdxOptions,
|
|
49
52
|
mdxOptionsNoJs,
|