@mintlify/common 1.0.430 → 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 CHANGED
@@ -18,3 +18,4 @@ export * from './camelToSentenceCase.js';
18
18
  export * from './asyncapi/index.js';
19
19
  export * from './isAbsoluteUrl.js';
20
20
  export * from './rss/index.js';
21
+ export * from './slugify.js';
package/dist/index.js CHANGED
@@ -18,3 +18,4 @@ export * from './camelToSentenceCase.js';
18
18
  export * from './asyncapi/index.js';
19
19
  export * from './isAbsoluteUrl.js';
20
20
  export * from './rss/index.js';
21
+ export * from './slugify.js';
@@ -1,11 +1,12 @@
1
1
  import { slugifyWithCounter } from '@sindresorhus/slugify';
2
- import { createMdxJsxAttribute, getTableOfContentsTitle, getUnicodeId, } from '../../lib/remark-utils.js';
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 slugify = slugifyWithCounter();
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 encodedTitle = getUnicodeId(title);
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 { createMdxJsxAttribute, getUnicodeId } from '../../lib/remark-utils.js';
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 slugify = slugifyWithCounter();
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 encodedTitle = getUnicodeId(title);
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),
@@ -0,0 +1,2 @@
1
+ import { CountableSlugify } from '@sindresorhus/slugify';
2
+ export declare function slugify(string: string, slugify?: CountableSlugify): string;
@@ -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
+ }