@mintlify/common 1.0.429 → 1.0.431
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.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/mdx/plugins/remark/remarkExtractTableOfContents.js +4 -16
- package/dist/mdx/plugins/remark/remarkHeadingIds.js +4 -16
- package/dist/mdx/snippets/resolveImport/index.js +0 -5
- package/dist/mdx/snippets/resolveImport/resolveComponentWithContent.js +0 -8
- package/dist/slugify.d.ts +2 -0
- package/dist/slugify.js +17 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { slugifyWithCounter } from '@sindresorhus/slugify';
|
|
2
|
-
import {
|
|
2
|
+
import { slugify } from '../../../slugify.js';
|
|
3
|
+
import { createMdxJsxAttribute, getTableOfContentsTitle } from '../../lib/remark-utils.js';
|
|
3
4
|
import { HEADING_LEVELS } from './remarkHeadingIds.js';
|
|
4
5
|
const HEADING_NAMES = ['h1', 'h2', 'h3', 'h4'];
|
|
5
6
|
export const remarkExtractTableOfContents = (mdxExtracts) => {
|
|
6
7
|
// slugifyWithCounter adds a counter (eg. slug, slug-2, slug-3) to the end of the slug if the header
|
|
7
8
|
// already exists. No counter is added for the first occurence.
|
|
8
|
-
const
|
|
9
|
+
const slugifyFn = slugifyWithCounter();
|
|
9
10
|
return (tree) => {
|
|
10
11
|
var _a, _b, _c, _d;
|
|
11
12
|
const contents = [];
|
|
@@ -36,20 +37,7 @@ export const remarkExtractTableOfContents = (mdxExtracts) => {
|
|
|
36
37
|
level = !isNaN(num) ? num : undefined;
|
|
37
38
|
}
|
|
38
39
|
const title = getTableOfContentsTitle(node);
|
|
39
|
-
const
|
|
40
|
-
let slug;
|
|
41
|
-
// if encoded title is already percent-encoded, return it as is
|
|
42
|
-
// slugify doesn't support percent-encoded characters, like Chinese, Korean, etc.
|
|
43
|
-
if (/%[0-9A-F]{2}/.test(encodedTitle)) {
|
|
44
|
-
slug = slugify(encodedTitle, {
|
|
45
|
-
decamelize: false,
|
|
46
|
-
preserveCharacters: ['%'],
|
|
47
|
-
lowercase: false,
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
else {
|
|
51
|
-
slug = slugify(encodedTitle, { decamelize: false });
|
|
52
|
-
}
|
|
40
|
+
const slug = slugify(title, slugifyFn);
|
|
53
41
|
let mdxJsxAttributes;
|
|
54
42
|
if ('name' in node && node.name === 'Update') {
|
|
55
43
|
mdxJsxAttributes = [...node.attributes, createMdxJsxAttribute('id', slug)];
|
|
@@ -1,27 +1,15 @@
|
|
|
1
1
|
import { slugifyWithCounter } from '@sindresorhus/slugify';
|
|
2
2
|
import { visit } from 'unist-util-visit';
|
|
3
|
-
import {
|
|
3
|
+
import { slugify } from '../../../slugify.js';
|
|
4
|
+
import { createMdxJsxAttribute } from '../../lib/remark-utils.js';
|
|
4
5
|
import { getTableOfContentsTitle } from '../../lib/remark-utils.js';
|
|
5
6
|
export const HEADING_LEVELS = [1, 2, 3, 4];
|
|
6
7
|
export const remarkHeadingIds = () => (tree) => {
|
|
7
|
-
const
|
|
8
|
+
const slugifyFn = slugifyWithCounter();
|
|
8
9
|
visit(tree, 'heading', (node, _, parent) => {
|
|
9
10
|
if (HEADING_LEVELS.includes(node.depth)) {
|
|
10
11
|
const title = getTableOfContentsTitle(node);
|
|
11
|
-
const
|
|
12
|
-
let slug;
|
|
13
|
-
// if encoded title is already percent-encoded, return it as is
|
|
14
|
-
// slugify doesn't support percent-encoded characters, like Chinese, Korean, etc.
|
|
15
|
-
if (/%[0-9A-F]{2}/.test(encodedTitle)) {
|
|
16
|
-
slug = slugify(encodedTitle, {
|
|
17
|
-
decamelize: false,
|
|
18
|
-
preserveCharacters: ['%'],
|
|
19
|
-
lowercase: false,
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
else {
|
|
23
|
-
slug = slugify(encodedTitle, { decamelize: false });
|
|
24
|
-
}
|
|
12
|
+
const slug = slugify(title, slugifyFn);
|
|
25
13
|
const mdxJsxAttributes = [
|
|
26
14
|
createMdxJsxAttribute('level', node.depth),
|
|
27
15
|
createMdxJsxAttribute('id', slug),
|
|
@@ -9,7 +9,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import { MdxImportSpecifier } from '../../../types/mdx/snippets/import.js';
|
|
11
11
|
import { getAST } from '../../remark.js';
|
|
12
|
-
import { containsRegularFunction } from './containsRegularFunction.js';
|
|
13
12
|
import { findExport } from './findExport.js';
|
|
14
13
|
import { injectToTopOfFileOfTree } from './injectToTopOfFile.js';
|
|
15
14
|
import { resolveComponentWithContent } from './resolveComponentWithContent.js';
|
|
@@ -40,10 +39,6 @@ export const resolveImport = (importSpecifier, destinationPageContent, importedF
|
|
|
40
39
|
const exportContent = findExport(importSpecifier.name, importedFileContent, importSpecifier.renamedName);
|
|
41
40
|
if (exportContent == undefined)
|
|
42
41
|
throw new Error(`Could not find export ${importSpecifier.name} in snippet`);
|
|
43
|
-
if (containsRegularFunction(exportContent)) {
|
|
44
|
-
console.warn(`Skipping snippet with regular function declaration. MDX parser only supports arrow functions.`);
|
|
45
|
-
return destinationPageContent;
|
|
46
|
-
}
|
|
47
42
|
// Inject "export const Component = `...`" into the top of the destination page
|
|
48
43
|
injectToTopOfFileOfTree(destinationPageContent, getAST(exportContent).children);
|
|
49
44
|
return destinationPageContent;
|
|
@@ -13,7 +13,6 @@ import { removeFrontmatterFromAST } from '../../astUtils.js';
|
|
|
13
13
|
import { getAST } from '../../remark.js';
|
|
14
14
|
import { createUniqueVariableName, isMdxJsxFlowElement } from '../../utils.js';
|
|
15
15
|
import { findAndRemoveExports } from '../findAndRemoveExports.js';
|
|
16
|
-
import { containsRegularFunction } from './containsRegularFunction.js';
|
|
17
16
|
import { injectToTopOfFileOfTree } from './injectToTopOfFile.js';
|
|
18
17
|
/**
|
|
19
18
|
*
|
|
@@ -35,13 +34,6 @@ export const resolveComponentWithContent = (tree, componentName, snippet, export
|
|
|
35
34
|
const isDefaultExport = snippetExportMap['default'] &&
|
|
36
35
|
(snippetExportMap[componentName] === undefined ||
|
|
37
36
|
Object.keys(snippetExportMap).length === 1);
|
|
38
|
-
// Check if the default export uses a regular function - if so, skip processing
|
|
39
|
-
if (isDefaultExport &&
|
|
40
|
-
snippetExportMap['default'] &&
|
|
41
|
-
containsRegularFunction(snippetExportMap['default'])) {
|
|
42
|
-
console.warn(`Skipping snippet with regular function declaration. MDX parser only supports arrow functions.`);
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
37
|
let snippetNodesToInject;
|
|
46
38
|
let variableDeclarationNodes = [];
|
|
47
39
|
// for named exports, replace the variables with the props
|
package/dist/slugify.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { slugifyWithCounter } from '@sindresorhus/slugify';
|
|
2
|
+
import { getUnicodeId } from './mdx/lib/remark-utils.js';
|
|
3
|
+
export function slugify(string, slugify = slugifyWithCounter()) {
|
|
4
|
+
const encodedString = getUnicodeId(string);
|
|
5
|
+
// if encoded title is already percent-encoded, return it as is
|
|
6
|
+
// slugify doesn't support percent-encoded characters, like Chinese, Korean, etc.
|
|
7
|
+
if (/%[0-9A-F]{2}/.test(encodedString)) {
|
|
8
|
+
return slugify(encodedString, {
|
|
9
|
+
decamelize: false,
|
|
10
|
+
preserveCharacters: ['%'],
|
|
11
|
+
lowercase: false,
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
return slugify(encodedString, { decamelize: false });
|
|
16
|
+
}
|
|
17
|
+
}
|