@mintlify/common 1.0.877 → 1.0.879

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 +1 @@
1
- export declare const encodeContentAsHtml: (content: string) => string;
1
+ export declare const encodeContentAsHtml: (content: string, siteUrl?: string) => string;
@@ -6,6 +6,20 @@ import remarkRehype from 'remark-rehype';
6
6
  import { unified } from 'unified';
7
7
  import { visit } from 'unist-util-visit';
8
8
  const DANGEROUS_TAGS = ['script', 'iframe', 'object', 'embed', 'style'];
9
+ const rehypeResolveRelativeUrls = (siteUrl) => {
10
+ return (tree) => {
11
+ visit(tree, 'element', (node) => {
12
+ var _a;
13
+ for (const attr of ['href', 'src']) {
14
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
15
+ const value = (_a = node.properties) === null || _a === void 0 ? void 0 : _a[attr];
16
+ if (typeof value === 'string' && value.startsWith('/') && !value.startsWith('//')) {
17
+ node.properties[attr] = `${siteUrl}${value}`;
18
+ }
19
+ }
20
+ });
21
+ };
22
+ };
9
23
  const rehypeRaw = () => {
10
24
  return (tree) => {
11
25
  visit(tree, 'raw', (raw, index, parent) => {
@@ -26,13 +40,17 @@ const rehypeSanitizeDangerous = () => {
26
40
  });
27
41
  };
28
42
  };
29
- export const encodeContentAsHtml = (content) => {
30
- const html = unified()
43
+ export const encodeContentAsHtml = (content, siteUrl) => {
44
+ let processor = unified()
31
45
  .use(remarkParse)
32
46
  .use(remarkGfm)
33
47
  .use(remarkRehype, { allowDangerousHtml: true })
34
48
  .use(rehypeRaw)
35
- .use(rehypeSanitizeDangerous)
49
+ .use(rehypeSanitizeDangerous);
50
+ if (siteUrl) {
51
+ processor = processor.use(rehypeResolveRelativeUrls, siteUrl);
52
+ }
53
+ const html = processor
36
54
  .use(rehypeStringify, { allowDangerousHtml: true })
37
55
  .processSync(content)
38
56
  .toString();
package/dist/rss/index.js CHANGED
@@ -47,6 +47,7 @@ const STANDARD_HTML_TAGS = new Set([
47
47
  'figcaption',
48
48
  'blockquote',
49
49
  'pre',
50
+ 'code',
50
51
  ]);
51
52
  export const isNormalMarkdown = (node) => {
52
53
  if (!node) {
@@ -179,7 +180,24 @@ const jsxToHtml = (node) => {
179
180
  .join('');
180
181
  return `<${tagName}${attrsStr}>${childrenStr}</${tagName}>`;
181
182
  };
183
+ const stripCustomInlineJsx = (parent) => {
184
+ let i = 0;
185
+ while (i < parent.children.length) {
186
+ const child = parent.children[i];
187
+ if (child.type === 'mdxJsxTextElement' &&
188
+ !STANDARD_HTML_TAGS.has(child.name || '')) {
189
+ const jsxChildren = child.children;
190
+ parent.children.splice(i, 1, ...jsxChildren);
191
+ continue;
192
+ }
193
+ if ('children' in child) {
194
+ stripCustomInlineJsx(child);
195
+ }
196
+ i++;
197
+ }
198
+ };
182
199
  const stringifyTreeForRSS = (tree) => {
200
+ stripCustomInlineJsx(tree);
183
201
  return tree.children
184
202
  .map((child) => {
185
203
  if (child.type === 'mdxJsxFlowElement' || child.type === 'mdxJsxTextElement') {