@mintlify/common 1.0.1208 → 1.0.1209

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
@@ -27,6 +27,7 @@ export * from './services/aws.js';
27
27
  export * from './slugify.js';
28
28
  export * from './services/aws.js';
29
29
  export * from './truncateAtWordBoundary.js';
30
+ export * from './strip-markdown.js';
30
31
  export * from './api-reference/parseApiTargetFromMetadata.js';
31
32
  export * from './mintIgnore.js';
32
33
  export * from './getDisplayDomain.js';
package/dist/index.js CHANGED
@@ -27,6 +27,7 @@ export * from './services/aws.js';
27
27
  export * from './slugify.js';
28
28
  export * from './services/aws.js';
29
29
  export * from './truncateAtWordBoundary.js';
30
+ export * from './strip-markdown.js';
30
31
  export * from './api-reference/parseApiTargetFromMetadata.js';
31
32
  export * from './mintIgnore.js';
32
33
  export * from './getDisplayDomain.js';
@@ -0,0 +1 @@
1
+ export declare const stripMarkdown: (text: string | null | undefined) => string | null;
@@ -0,0 +1,33 @@
1
+ export const stripMarkdown = (text) => {
2
+ if (!text)
3
+ return null;
4
+ return (text
5
+ // Remove images: ![alt](url) → (empty) - handles nested parentheses in URLs
6
+ .replace(/!\[([^\]]*)\]\([^()]*(?:\([^()]*\)[^()]*)*\)/g, '')
7
+ // Remove reference images: ![alt][ref] → (empty)
8
+ .replace(/!\[([^\]]*)\]\[[^\]]*\]/g, '')
9
+ // Remove links: [text](url) → text - handles nested parentheses in URLs and empty text
10
+ .replace(/\[([^\]]*)\]\([^()]*(?:\([^()]*\)[^()]*)*\)/g, '$1')
11
+ // Remove reference links: [text][ref] → text (also handles empty text)
12
+ .replace(/\[([^\]]*)\]\[[^\]]*\]/g, '$1')
13
+ // Remove bold+italic: ***text*** or ___text___ → text
14
+ .replace(/\*{3}([^*]+)\*{3}/g, '$1')
15
+ .replace(/_{3}([^_]+)_{3}/g, '$1')
16
+ // Remove bold: **text** or __text__ → text
17
+ .replace(/\*{2}([^*]+)\*{2}/g, '$1')
18
+ .replace(/_{2}([^_]+)_{2}/g, '$1')
19
+ // Remove italic: *text* or _text_ → text
20
+ .replace(/\*([^*]+)\*/g, '$1')
21
+ .replace(/(?<!\w)_([^_]+)_(?!\w)/g, '$1')
22
+ // Remove code: ```code```, ``code``, `code` → code (order matters)
23
+ .replace(/`{3}([^`]+)`{3}/g, '$1')
24
+ .replace(/`{2}([^`]+)`{2}/g, '$1')
25
+ .replace(/`([^`]+)`/g, '$1')
26
+ // Remove strikethrough: ~~text~~ → text
27
+ .replace(/~~([^~]+)~~/g, '$1')
28
+ // Remove HTML tags (only valid tags starting with letter, not angle brackets in text)
29
+ .replace(/<\/?[a-zA-Z][^>]*>/g, '')
30
+ // Normalize whitespace
31
+ .replace(/\s+/g, ' ')
32
+ .trim());
33
+ };