@mintlify/common 1.0.1092 → 1.0.1094

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,4 @@
1
- const HEADING_ID_RE = /^(#{1,6})\s+(.+?)\s*\{\s*#([^}]+?)\s*\}\s*$/;
1
+ const HEADING_ID_RE = /^( {0,3})(#{1,6})\s+(.+?)\s*\{\s*#([^}]+?)\s*\}\s*$/;
2
2
  const UNSAFE_HTML_ATTR_CHARS = /[<>"]/g;
3
3
  /**
4
4
  * Characters to strip from custom heading IDs in the default (non-editor) path.
@@ -25,6 +25,7 @@ function normalizeCustomId(raw) {
25
25
  * code blocks, avoiding backtracking over large documents.
26
26
  */
27
27
  export function preprocessCustomHeadingIds(content, options) {
28
+ var _a;
28
29
  const lines = content.split('\n');
29
30
  const result = [];
30
31
  let fenceChar;
@@ -46,12 +47,13 @@ export function preprocessCustomHeadingIds(content, options) {
46
47
  continue;
47
48
  }
48
49
  const heading = HEADING_ID_RE.exec(line);
49
- if ((heading === null || heading === void 0 ? void 0 : heading[1]) && heading[2] && heading[3]) {
50
- const level = heading[1].length;
50
+ if ((heading === null || heading === void 0 ? void 0 : heading[2]) && heading[3] && heading[4]) {
51
+ const indent = (_a = heading[1]) !== null && _a !== void 0 ? _a : '';
52
+ const level = heading[2].length;
51
53
  const sanitizedId = (options === null || options === void 0 ? void 0 : options.preserveOriginal)
52
- ? sanitizeHtmlAttr(heading[3])
53
- : normalizeCustomId(heading[3]);
54
- result.push(`<h${level} id="${sanitizedId}">`, heading[2], `</h${level}>`);
54
+ ? sanitizeHtmlAttr(heading[4])
55
+ : normalizeCustomId(heading[4]);
56
+ result.push(`${indent}<h${level} id="${sanitizedId}">`, `${indent}${heading[3]}`, `${indent}</h${level}>`);
55
57
  continue;
56
58
  }
57
59
  result.push(line);
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,48 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { preprocessCustomHeadingIds } from './preprocessCustomHeadingIds.js';
3
+ describe('preprocessCustomHeadingIds', () => {
4
+ it('converts top-level headings with custom ids', () => {
5
+ expect(preprocessCustomHeadingIds('## Heading {#custom-id}')).toBe('<h2 id="custom-id">\nHeading\n</h2>');
6
+ });
7
+ it('converts headings indented by up to 3 spaces and preserves indentation', () => {
8
+ expect(preprocessCustomHeadingIds(' ## Heading {#custom_id}')).toBe(' <h2 id="custom_id">\n Heading\n </h2>');
9
+ expect(preprocessCustomHeadingIds(' # A {#a}')).toBe(' <h1 id="a">\n A\n </h1>');
10
+ expect(preprocessCustomHeadingIds(' ### B {#b}')).toBe(' <h3 id="b">\n B\n </h3>');
11
+ });
12
+ it('converts indented headings inside JSX components', () => {
13
+ const input = `<Update label="March 2026">
14
+ ## Release Notes {#release_notes}
15
+
16
+ Content
17
+ </Update>`;
18
+ const output = preprocessCustomHeadingIds(input);
19
+ expect(output).toContain(' <h2 id="release_notes">\n Release Notes\n </h2>');
20
+ expect(output).not.toContain('{#');
21
+ });
22
+ it('leaves headings indented by 4 or more spaces alone', () => {
23
+ const input = ' ## Heading {#custom-id}';
24
+ expect(preprocessCustomHeadingIds(input)).toBe(input);
25
+ });
26
+ it('leaves tab-indented headings alone', () => {
27
+ const input = '\t## Heading {#custom-id}';
28
+ expect(preprocessCustomHeadingIds(input)).toBe(input);
29
+ });
30
+ it('leaves indented headings inside code fences alone', () => {
31
+ const input = `\`\`\`md
32
+ ## Heading {#custom-id}
33
+ \`\`\``;
34
+ expect(preprocessCustomHeadingIds(input)).toBe(input);
35
+ });
36
+ it('leaves headings inside indented code fences alone', () => {
37
+ const input = ` \`\`\`md
38
+ ## Heading {#custom-id}
39
+ \`\`\``;
40
+ expect(preprocessCustomHeadingIds(input)).toBe(input);
41
+ });
42
+ it('normalizes ids by default', () => {
43
+ expect(preprocessCustomHeadingIds(' ## Heading {#my id!}')).toBe(' <h2 id="my-id">\n Heading\n </h2>');
44
+ });
45
+ it('preserves original ids when preserveOriginal is set', () => {
46
+ expect(preprocessCustomHeadingIds(' ## Heading {#my_id}', { preserveOriginal: true })).toBe(' <h2 id="my_id">\n Heading\n </h2>');
47
+ });
48
+ });