@mintlify/common 1.0.836 → 1.0.838

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,5 +1,12 @@
1
1
  import type { RootContent } from 'mdast';
2
2
  import { MdxJsxFlowElement } from 'mdast-util-mdx-jsx';
3
+ export interface PreprocessCustomHeadingIdsOptions {
4
+ /**
5
+ * When true, preserves the original ID as-is (only removing characters unsafe
6
+ * in HTML attributes). When false (default), applies slugify for normalized IDs.
7
+ */
8
+ preserveOriginal?: boolean;
9
+ }
3
10
  /**
4
11
  * Converts markdown headings with custom ID syntax into JSX heading elements.
5
12
  *
@@ -10,7 +17,7 @@ import { MdxJsxFlowElement } from 'mdast-util-mdx-jsx';
10
17
  * Uses a line-by-line scan with fence state tracking to skip headings inside
11
18
  * code blocks, avoiding backtracking over large documents.
12
19
  */
13
- export declare function preprocessCustomHeadingIds(content: string): string;
20
+ export declare function preprocessCustomHeadingIds(content: string, options?: PreprocessCustomHeadingIdsOptions): string;
14
21
  export interface JsxHeadingElement extends MdxJsxFlowElement {
15
22
  readonly __jsxHeading: true;
16
23
  }
@@ -1,5 +1,9 @@
1
1
  import slugify from '@sindresorhus/slugify';
2
2
  const HEADING_ID_RE = /^(#{1,6})\s+(.+?)\s*\{\s*#([^}]+?)\s*\}\s*$/;
3
+ const UNSAFE_HTML_ATTR_CHARS = /[<>"]/g;
4
+ function sanitizeHtmlAttr(id) {
5
+ return id.trim().replace(UNSAFE_HTML_ATTR_CHARS, '');
6
+ }
3
7
  /**
4
8
  * Converts markdown headings with custom ID syntax into JSX heading elements.
5
9
  *
@@ -10,7 +14,7 @@ const HEADING_ID_RE = /^(#{1,6})\s+(.+?)\s*\{\s*#([^}]+?)\s*\}\s*$/;
10
14
  * Uses a line-by-line scan with fence state tracking to skip headings inside
11
15
  * code blocks, avoiding backtracking over large documents.
12
16
  */
13
- export function preprocessCustomHeadingIds(content) {
17
+ export function preprocessCustomHeadingIds(content, options) {
14
18
  const lines = content.split('\n');
15
19
  const result = [];
16
20
  let fenceChar;
@@ -34,7 +38,9 @@ export function preprocessCustomHeadingIds(content) {
34
38
  const heading = HEADING_ID_RE.exec(line);
35
39
  if ((heading === null || heading === void 0 ? void 0 : heading[1]) && heading[2] && heading[3]) {
36
40
  const level = heading[1].length;
37
- const sanitizedId = slugify(heading[3].trim(), { preserveCharacters: ['_'] });
41
+ const sanitizedId = (options === null || options === void 0 ? void 0 : options.preserveOriginal)
42
+ ? sanitizeHtmlAttr(heading[3])
43
+ : slugify(heading[3].trim(), { preserveCharacters: ['_'] });
38
44
  result.push(`<h${level} id="${sanitizedId}">`, heading[2], `</h${level}>`);
39
45
  continue;
40
46
  }
package/dist/mdx/utils.js CHANGED
@@ -109,6 +109,7 @@ export const allowedComponents = [
109
109
  'h3',
110
110
  'h4',
111
111
  'head',
112
+ 'hr',
112
113
  'iframe',
113
114
  'img',
114
115
  'input',
@@ -0,0 +1,2 @@
1
+ import { DecoratedNavigationConfig } from '@mintlify/validation';
2
+ export declare function getAllPathsInDecoratedNav(nav: DecoratedNavigationConfig, paths?: string[]): string[];
@@ -0,0 +1,36 @@
1
+ import { divisions, } from '@mintlify/validation';
2
+ import { isAbsoluteUrl } from '../isAbsoluteUrl.js';
3
+ import { optionallyRemoveLeadingSlash } from '../optionallyRemoveLeadingSlash.js';
4
+ import { isPage } from './isPage.js';
5
+ export function getAllPathsInDecoratedNav(nav, paths = []) {
6
+ getPaths(nav, paths);
7
+ return paths;
8
+ }
9
+ function getPaths(entry, paths) {
10
+ if (isPage(entry)) {
11
+ const internalPath = toInternalPath(entry.href);
12
+ if (internalPath !== undefined) {
13
+ paths.push(internalPath);
14
+ }
15
+ return;
16
+ }
17
+ if (entry.root != null && typeof entry.root === 'object') {
18
+ getPaths(entry.root, paths);
19
+ }
20
+ if (Array.isArray(entry.pages)) {
21
+ entry.pages.forEach((page) => getPaths(page, paths));
22
+ return;
23
+ }
24
+ for (const division of ['groups', ...divisions]) {
25
+ const items = entry[division];
26
+ if (!Array.isArray(items))
27
+ continue;
28
+ items.forEach((item) => getPaths(item, paths));
29
+ }
30
+ }
31
+ function toInternalPath(href) {
32
+ if (!href || href.startsWith('#') || href.startsWith('//') || isAbsoluteUrl(href)) {
33
+ return undefined;
34
+ }
35
+ return optionallyRemoveLeadingSlash(href);
36
+ }
@@ -4,6 +4,7 @@ export * from './generatePathToBreadcrumbsMap.js';
4
4
  export * from './getFirstPageFromNavigation.js';
5
5
  export * from './generatePathToBreadcrumbsMapForDocsConfig.js';
6
6
  export * from './getAllPathsInDocsNav.js';
7
+ export * from './getAllPathsInDecoratedNav.js';
7
8
  export * from './checkNavAccess.js';
8
9
  export * from './getFirstPageFromNavConfig.js';
9
10
  export * from './prioritize-default-division-item.js';
@@ -4,6 +4,7 @@ export * from './generatePathToBreadcrumbsMap.js';
4
4
  export * from './getFirstPageFromNavigation.js';
5
5
  export * from './generatePathToBreadcrumbsMapForDocsConfig.js';
6
6
  export * from './getAllPathsInDocsNav.js';
7
+ export * from './getAllPathsInDecoratedNav.js';
7
8
  export * from './checkNavAccess.js';
8
9
  export * from './getFirstPageFromNavConfig.js';
9
10
  export * from './prioritize-default-division-item.js';