@langchain/macaw-components 1.7.3 → 1.7.5
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/catalog.json +730 -713
- package/dist/components/ChatComposer/ChatComposer.js +2 -2
- package/dist/components/ChatComposer/ChatComposer.js.map +1 -1
- package/dist/components/ChatMessage/ChatMessage.js +20 -12
- package/dist/components/ChatMessage/ChatMessage.js.map +1 -1
- package/dist/components/ChatState/ChatState.js +1 -1
- package/dist/components/ChatState/ChatState.js.map +1 -1
- package/dist/components/Code/CodeLite.js +1 -1
- package/dist/components/Code/CodeLite.js.map +1 -1
- package/dist/components/Code/CodeLiteDiff.js +1 -1
- package/dist/components/Code/CodeLiteDiff.js.map +1 -1
- package/dist/components/Code/CodeToolbar.js +1 -1
- package/dist/components/Code/CodeToolbar.js.map +1 -1
- package/dist/components/Code/codeLanguages.js +4 -3
- package/dist/components/Code/codeLanguages.js.map +1 -1
- package/dist/components/Code/index.js +1 -1
- package/dist/components/Code/index.js.map +1 -1
- package/dist/components/MarkdownDisplay/MarkdownCodeBlock.d.ts +8 -0
- package/dist/components/MarkdownDisplay/MarkdownCodeBlock.js +25 -0
- package/dist/components/MarkdownDisplay/MarkdownCodeBlock.js.map +1 -0
- package/dist/components/MarkdownDisplay/MarkdownDisplay.d.ts +72 -0
- package/dist/components/MarkdownDisplay/MarkdownDisplay.js +319 -0
- package/dist/components/MarkdownDisplay/MarkdownDisplay.js.map +1 -0
- package/dist/components/MarkdownDisplay/index.d.ts +3 -0
- package/dist/components/MarkdownDisplay/index.js +3 -0
- package/dist/components/MarkdownDisplay/markdownPlugins.d.ts +18 -0
- package/dist/components/MarkdownDisplay/markdownPlugins.js +93 -0
- package/dist/components/MarkdownDisplay/markdownPlugins.js.map +1 -0
- package/dist/components/MarkdownDisplay/prepareMarkdownXml.d.ts +14 -0
- package/dist/components/MarkdownDisplay/prepareMarkdownXml.js +313 -0
- package/dist/components/MarkdownDisplay/prepareMarkdownXml.js.map +1 -0
- package/dist/icons/LongTailPhosphorIcons.js +1 -1
- package/dist/utilities.css +1 -1
- package/docs/DESIGN.md +73 -0
- package/package.json +13 -2
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
import type { Components } from 'react-markdown';
|
|
3
|
+
import { type TextProps } from '../Text/index.js';
|
|
4
|
+
type TextColor = NonNullable<TextProps['color']>;
|
|
5
|
+
export interface MarkdownDisplayProps {
|
|
6
|
+
/** Markdown source to render. */
|
|
7
|
+
content: string;
|
|
8
|
+
/** Render custom XML wrappers as labeled sections, or keep tags literal (default). */
|
|
9
|
+
xmlTags?: 'literal' | 'sections';
|
|
10
|
+
/** Repair unfinished Markdown while content streams; use the original Markdown when false. */
|
|
11
|
+
isStreaming?: boolean;
|
|
12
|
+
className?: string;
|
|
13
|
+
/**
|
|
14
|
+
* Render oversized content in full as linkified, non-virtualized plain text
|
|
15
|
+
* instead of truncating it behind a Show more toggle. Ignores
|
|
16
|
+
* `containerHeight`.
|
|
17
|
+
*/
|
|
18
|
+
fullLength?: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Viewport height for truncated oversized content. When set, that content
|
|
21
|
+
* renders in a virtualized plain-text viewport whose URLs are not
|
|
22
|
+
* linkified.
|
|
23
|
+
*/
|
|
24
|
+
containerHeight?: string;
|
|
25
|
+
/**
|
|
26
|
+
* Longest content, in characters, rendered as Markdown; longer content
|
|
27
|
+
* renders as plain text. Defaults to the shared text length limit. Raise it,
|
|
28
|
+
* or pass `Infinity`, only for content of bounded size such as chat answers:
|
|
29
|
+
* parsing cost grows with length, and the default keeps views of large
|
|
30
|
+
* untrusted content responsive.
|
|
31
|
+
*/
|
|
32
|
+
maxMarkdownLength?: number;
|
|
33
|
+
/** Preserve single newlines visually without changing Markdown parsing. */
|
|
34
|
+
preserveNewlines?: boolean;
|
|
35
|
+
/** Wrap long fenced code lines by default, or scroll them horizontally. */
|
|
36
|
+
codeOverflow?: 'wrap' | 'scroll';
|
|
37
|
+
/** Color applied to text-bearing Markdown elements. */
|
|
38
|
+
textColor?: TextColor;
|
|
39
|
+
/**
|
|
40
|
+
* Load images referenced by the Markdown. Off by default: loading a remote
|
|
41
|
+
* image from untrusted content sends a request, and anything encoded in its
|
|
42
|
+
* URL, without user action. Images otherwise render as links.
|
|
43
|
+
*/
|
|
44
|
+
loadImages?: boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Override or extend the default react-markdown component mapping. Keep
|
|
47
|
+
* override components stable across renders; a new component function
|
|
48
|
+
* remounts every element it renders.
|
|
49
|
+
*/
|
|
50
|
+
components?: Components;
|
|
51
|
+
/**
|
|
52
|
+
* Content that continues the rendered flow: inline after the final
|
|
53
|
+
* paragraph's text, or after the last block when content ends otherwise.
|
|
54
|
+
*/
|
|
55
|
+
trailingContent?: ReactNode;
|
|
56
|
+
/** Content rendered after the Markdown content container. */
|
|
57
|
+
afterContent?: ReactNode;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Renders untrusted Markdown with GFM support and Macaw presentation.
|
|
61
|
+
*
|
|
62
|
+
* Raw HTML is never interpreted. Tags display as text by default; opt in to
|
|
63
|
+
* XML sections turn custom wrappers into labels and nested blockquotes.
|
|
64
|
+
* Content above `maxMarkdownLength` (by default the shared text length limit)
|
|
65
|
+
* renders as plain text, truncated behind a Show more toggle unless
|
|
66
|
+
* `fullLength` is set.
|
|
67
|
+
*/
|
|
68
|
+
export declare function MarkdownDisplay({ content, isStreaming, xmlTags, className, fullLength, containerHeight, maxMarkdownLength, preserveNewlines, codeOverflow, textColor, loadImages, components, trailingContent, afterContent, }: MarkdownDisplayProps): import("react").JSX.Element;
|
|
69
|
+
export declare namespace MarkdownDisplay {
|
|
70
|
+
var displayName: string;
|
|
71
|
+
}
|
|
72
|
+
export {};
|
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
import { cn } from "../../utils/cn.js";
|
|
2
|
+
import { Text } from "../Text/Text.js";
|
|
3
|
+
import { Icon } from "../Icon/Icon.js";
|
|
4
|
+
import { Link } from "../Link/Link.js";
|
|
5
|
+
import { ErrorBoundary } from "../ErrorBoundary.js";
|
|
6
|
+
import { MAX_TEXT_LENGTH } from "../Code/constants.js";
|
|
7
|
+
import { TextWithLinks } from "../TextWithLinks.js";
|
|
8
|
+
import { Checkbox } from "../Checkbox/Checkbox.js";
|
|
9
|
+
import { MarkdownCodeBlock } from "./MarkdownCodeBlock.js";
|
|
10
|
+
import { makeComponentName } from "../../utils/componentUtils.js";
|
|
11
|
+
import { rehypeMarkdownDisplay, remarkDisableRawHtml } from "./markdownPlugins.js";
|
|
12
|
+
import { prepareMarkdownXml } from "./prepareMarkdownXml.js";
|
|
13
|
+
import { createContext, isValidElement, useContext, useId, useMemo } from "react";
|
|
14
|
+
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
15
|
+
import { WarningCircleIcon } from "@phosphor-icons/react/dist/ssr/WarningCircle";
|
|
16
|
+
import ReactMarkdown from "react-markdown";
|
|
17
|
+
import remarkGfm from "remark-gfm";
|
|
18
|
+
import remend from "remend";
|
|
19
|
+
import { ImageIcon } from "@phosphor-icons/react/dist/ssr/Image";
|
|
20
|
+
//#region packages/components/src/components/MarkdownDisplay/MarkdownDisplay.tsx
|
|
21
|
+
var COMPONENT_NAME = makeComponentName("MarkdownDisplay");
|
|
22
|
+
var PLAIN_TEXT_FALLBACK_MESSAGE = "Shown as plain text because this block is too large for Markdown.";
|
|
23
|
+
var REMARK_PLUGINS = [remarkGfm, remarkDisableRawHtml];
|
|
24
|
+
var REHYPE_PLUGINS = [rehypeMarkdownDisplay];
|
|
25
|
+
var ListTypeContext = createContext("unordered");
|
|
26
|
+
/** The id of the enclosing task list item, which names its checkbox. */
|
|
27
|
+
var TaskItemContext = createContext(void 0);
|
|
28
|
+
var MarkdownDisplayContext = createContext({
|
|
29
|
+
loadImages: false,
|
|
30
|
+
trailingContent: null,
|
|
31
|
+
codeOverflow: "wrap"
|
|
32
|
+
});
|
|
33
|
+
var blockSpacing = "mt-space-4 first:mt-0 [:is(h1,h2,h3,h4,h5,h6)+&]:mt-space-2";
|
|
34
|
+
/** Inline links keep the size and rhythm of the text they sit in. */
|
|
35
|
+
var inlineLinkClassName = "inline text-[length:inherit] leading-[inherit] tracking-[inherit]";
|
|
36
|
+
function MarkdownListItem({ children, className, id, node: _node, ...props }) {
|
|
37
|
+
const listType = useContext(ListTypeContext);
|
|
38
|
+
const generatedId = useId();
|
|
39
|
+
const isTask = className?.split(" ").includes("task-list-item") ?? false;
|
|
40
|
+
const hasBullet = listType === "unordered" && !isTask;
|
|
41
|
+
const itemId = id ?? (isTask ? generatedId : void 0);
|
|
42
|
+
return /* @__PURE__ */ jsx(TaskItemContext.Provider, {
|
|
43
|
+
value: isTask ? itemId : void 0,
|
|
44
|
+
children: /* @__PURE__ */ jsxs("li", {
|
|
45
|
+
...props,
|
|
46
|
+
id: itemId,
|
|
47
|
+
className: cn("text-sm leading-normal tracking-normal", hasBullet && "relative pl-space-3", isTask && "relative list-none pl-space-5 has-[[data-state=checked]]:text-quaternary has-[[data-state=checked]]:line-through", className),
|
|
48
|
+
children: [children, hasBullet && /* @__PURE__ */ jsx("span", {
|
|
49
|
+
"aria-hidden": true,
|
|
50
|
+
className: "absolute left-0 top-[0.65em] size-1 rounded-full bg-current"
|
|
51
|
+
})]
|
|
52
|
+
})
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
function MarkdownTaskCheckbox({ checked, type }) {
|
|
56
|
+
const taskItemId = useContext(TaskItemContext);
|
|
57
|
+
if (type !== "checkbox") return null;
|
|
58
|
+
const checkboxProps = {
|
|
59
|
+
checked: checked ?? false,
|
|
60
|
+
"aria-readonly": true,
|
|
61
|
+
tabIndex: -1,
|
|
62
|
+
onClick: (event) => event.preventDefault(),
|
|
63
|
+
size: "sm",
|
|
64
|
+
className: "pointer-events-none",
|
|
65
|
+
containerClassName: "absolute left-0 top-[calc(0.75em_-_0.5rem)]"
|
|
66
|
+
};
|
|
67
|
+
return taskItemId ? /* @__PURE__ */ jsx(Checkbox, {
|
|
68
|
+
...checkboxProps,
|
|
69
|
+
"aria-labelledby": taskItemId
|
|
70
|
+
}) : /* @__PURE__ */ jsx(Checkbox, {
|
|
71
|
+
...checkboxProps,
|
|
72
|
+
"aria-label": checked ? "Completed task" : "Open task"
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
function MarkdownImage({ alt = "", src, className, node: _node, ...props }) {
|
|
76
|
+
const { loadImages } = useContext(MarkdownDisplayContext);
|
|
77
|
+
if (typeof src !== "string" || !src) return /* @__PURE__ */ jsx("span", {
|
|
78
|
+
className: "text-tertiary",
|
|
79
|
+
children: alt
|
|
80
|
+
});
|
|
81
|
+
if (!loadImages) return /* @__PURE__ */ jsx(Link, {
|
|
82
|
+
href: src,
|
|
83
|
+
variant: "body",
|
|
84
|
+
target: "_blank",
|
|
85
|
+
rel: "noopener noreferrer",
|
|
86
|
+
leftDecorator: ImageIcon,
|
|
87
|
+
className: cn(inlineLinkClassName, "[&>svg]:mr-[2px] [&>svg]:inline [&>svg]:align-[-0.125em]"),
|
|
88
|
+
children: alt || src
|
|
89
|
+
});
|
|
90
|
+
return /* @__PURE__ */ jsx("img", {
|
|
91
|
+
...props,
|
|
92
|
+
src,
|
|
93
|
+
alt,
|
|
94
|
+
loading: "lazy",
|
|
95
|
+
referrerPolicy: "no-referrer",
|
|
96
|
+
className: cn(blockSpacing, "h-auto max-w-full rounded-md border border-subtle", className)
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
function MarkdownSpan({ node: _node, ...props }) {
|
|
100
|
+
const { trailingContent } = useContext(MarkdownDisplayContext);
|
|
101
|
+
if ("data-markdown-trailing" in props) return /* @__PURE__ */ jsx(Fragment$1, { children: trailingContent });
|
|
102
|
+
return /* @__PURE__ */ jsx("span", { ...props });
|
|
103
|
+
}
|
|
104
|
+
var createHeading = (variant, headingClassName, weight = "semibold", color) => function MarkdownHeading({ children, className, color: _color, node: _node, ...props }) {
|
|
105
|
+
return /* @__PURE__ */ jsx(Text, {
|
|
106
|
+
...props,
|
|
107
|
+
as: variant,
|
|
108
|
+
variant,
|
|
109
|
+
weight,
|
|
110
|
+
color,
|
|
111
|
+
className: cn(blockSpacing, headingClassName, className),
|
|
112
|
+
children
|
|
113
|
+
});
|
|
114
|
+
};
|
|
115
|
+
var MARKDOWN_COMPONENTS = {
|
|
116
|
+
pre: function MarkdownPre({ children }) {
|
|
117
|
+
const { codeOverflow } = useContext(MarkdownDisplayContext);
|
|
118
|
+
const child = isValidElement(children) ? children : void 0;
|
|
119
|
+
const language = child?.props.className?.match(/language-([^\s]+)/)?.[1];
|
|
120
|
+
const code = typeof child?.props.children === "string" ? child.props.children : String(child?.props.children ?? "");
|
|
121
|
+
return /* @__PURE__ */ jsx("div", {
|
|
122
|
+
"data-search-block": "",
|
|
123
|
+
"data-search-code": "",
|
|
124
|
+
className: cn("w-full min-w-0", blockSpacing),
|
|
125
|
+
children: /* @__PURE__ */ jsx(MarkdownCodeBlock, {
|
|
126
|
+
code,
|
|
127
|
+
language,
|
|
128
|
+
codeOverflow
|
|
129
|
+
})
|
|
130
|
+
});
|
|
131
|
+
},
|
|
132
|
+
code: ({ children, className, node: _node, ...props }) => /* @__PURE__ */ jsx("code", {
|
|
133
|
+
...props,
|
|
134
|
+
className: cn("rounded-xs bg-surface-level-3 px-space-1 py-px font-mono text-[length:0.9em] leading-[inherit] tracking-normal text-tertiary", className),
|
|
135
|
+
children
|
|
136
|
+
}),
|
|
137
|
+
a: ({ children, href, className, node: _node, ...props }) => {
|
|
138
|
+
if (!href) return /* @__PURE__ */ jsx("span", { children });
|
|
139
|
+
const opensNewTab = !href.startsWith("#");
|
|
140
|
+
return /* @__PURE__ */ jsx(Link, {
|
|
141
|
+
...props,
|
|
142
|
+
href,
|
|
143
|
+
variant: "body",
|
|
144
|
+
target: opensNewTab ? "_blank" : void 0,
|
|
145
|
+
rel: opensNewTab ? "noopener noreferrer" : void 0,
|
|
146
|
+
className: cn(inlineLinkClassName, className),
|
|
147
|
+
children
|
|
148
|
+
});
|
|
149
|
+
},
|
|
150
|
+
h1: createHeading("h1", "text-xl leading-tight"),
|
|
151
|
+
h2: createHeading("h2", "text-lg leading-tight"),
|
|
152
|
+
h3: createHeading("h3", "text-base leading-tight"),
|
|
153
|
+
h4: createHeading("h4", "text-sm leading-tight", "semibold", "quaternary"),
|
|
154
|
+
h5: createHeading("h5", "text-sm leading-tight", "semibold", "secondary"),
|
|
155
|
+
h6: createHeading("h6", "text-sm leading-tight", "medium", "secondary"),
|
|
156
|
+
p: ({ children, className, color: _color, node: _node, ...props }) => /* @__PURE__ */ jsx(Text, {
|
|
157
|
+
...props,
|
|
158
|
+
as: "p",
|
|
159
|
+
variant: "body",
|
|
160
|
+
className: cn("mt-space-3 first:mt-0", className),
|
|
161
|
+
children
|
|
162
|
+
}),
|
|
163
|
+
blockquote: ({ node: _node, ...props }) => /* @__PURE__ */ jsx("blockquote", {
|
|
164
|
+
...props,
|
|
165
|
+
className: cn(blockSpacing, "border-l-4 border-default bg-surface-level-2 py-space-2 pl-space-4 pr-space-3 italic [overflow-wrap:anywhere]")
|
|
166
|
+
}),
|
|
167
|
+
ul: ({ className, node: _node, ...props }) => /* @__PURE__ */ jsx(ListTypeContext.Provider, {
|
|
168
|
+
value: "unordered",
|
|
169
|
+
children: /* @__PURE__ */ jsx("ul", {
|
|
170
|
+
...props,
|
|
171
|
+
className: cn(blockSpacing, "ml-space-3 flex flex-col gap-space-1 [li>&]:mt-space-1", className)
|
|
172
|
+
})
|
|
173
|
+
}),
|
|
174
|
+
ol: ({ className, start, style, node, ...props }) => {
|
|
175
|
+
const itemCount = node?.children.filter((child) => child.type === "element" && child.tagName === "li").length ?? 0;
|
|
176
|
+
const firstNumber = start ?? 1;
|
|
177
|
+
const lastNumber = firstNumber + Math.max(itemCount - 1, 0);
|
|
178
|
+
const markerDigits = Math.max(String(firstNumber).length, String(lastNumber).length);
|
|
179
|
+
return /* @__PURE__ */ jsx(ListTypeContext.Provider, {
|
|
180
|
+
value: "ordered",
|
|
181
|
+
children: /* @__PURE__ */ jsx("ol", {
|
|
182
|
+
...props,
|
|
183
|
+
start,
|
|
184
|
+
style: {
|
|
185
|
+
...style,
|
|
186
|
+
paddingInlineStart: `${markerDigits + 1.5}ch`
|
|
187
|
+
},
|
|
188
|
+
className: cn(blockSpacing, "flex list-outside list-decimal flex-col gap-space-1 [li>&]:mt-space-1", className)
|
|
189
|
+
})
|
|
190
|
+
});
|
|
191
|
+
},
|
|
192
|
+
li: MarkdownListItem,
|
|
193
|
+
input: MarkdownTaskCheckbox,
|
|
194
|
+
table: ({ node: _node, ...props }) => /* @__PURE__ */ jsx("div", {
|
|
195
|
+
"data-search-block": "",
|
|
196
|
+
role: "region",
|
|
197
|
+
"aria-label": "Table",
|
|
198
|
+
tabIndex: 0,
|
|
199
|
+
className: cn(blockSpacing, "w-full overflow-x-auto focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-focus"),
|
|
200
|
+
children: /* @__PURE__ */ jsx("table", {
|
|
201
|
+
...props,
|
|
202
|
+
className: "w-full min-w-max border-collapse text-left text-xs"
|
|
203
|
+
})
|
|
204
|
+
}),
|
|
205
|
+
th: ({ node: _node, ...props }) => /* @__PURE__ */ jsx("th", {
|
|
206
|
+
...props,
|
|
207
|
+
className: "border border-subtle dark:border-muted bg-surface-level-2 px-space-2 py-space-1 font-semibold"
|
|
208
|
+
}),
|
|
209
|
+
td: ({ node: _node, ...props }) => /* @__PURE__ */ jsx("td", {
|
|
210
|
+
...props,
|
|
211
|
+
className: "border border-subtle dark:border-muted px-space-2 py-space-1 align-top"
|
|
212
|
+
}),
|
|
213
|
+
hr: ({ node: _node, ...props }) => /* @__PURE__ */ jsx("hr", {
|
|
214
|
+
...props,
|
|
215
|
+
className: cn(blockSpacing, "border-default")
|
|
216
|
+
}),
|
|
217
|
+
strong: ({ className, node: _node, ...props }) => /* @__PURE__ */ jsx("strong", {
|
|
218
|
+
...props,
|
|
219
|
+
className: cn("font-semibold", className)
|
|
220
|
+
}),
|
|
221
|
+
em: ({ className, node: _node, ...props }) => /* @__PURE__ */ jsx("em", {
|
|
222
|
+
...props,
|
|
223
|
+
className: cn("italic", className)
|
|
224
|
+
}),
|
|
225
|
+
del: ({ node: _node, ...props }) => /* @__PURE__ */ jsx("del", {
|
|
226
|
+
...props,
|
|
227
|
+
className: "text-tertiary"
|
|
228
|
+
}),
|
|
229
|
+
img: MarkdownImage,
|
|
230
|
+
span: MarkdownSpan
|
|
231
|
+
};
|
|
232
|
+
/**
|
|
233
|
+
* Renders untrusted Markdown with GFM support and Macaw presentation.
|
|
234
|
+
*
|
|
235
|
+
* Raw HTML is never interpreted. Tags display as text by default; opt in to
|
|
236
|
+
* XML sections turn custom wrappers into labels and nested blockquotes.
|
|
237
|
+
* Content above `maxMarkdownLength` (by default the shared text length limit)
|
|
238
|
+
* renders as plain text, truncated behind a Show more toggle unless
|
|
239
|
+
* `fullLength` is set.
|
|
240
|
+
*/
|
|
241
|
+
function MarkdownDisplay({ content, isStreaming = false, xmlTags = "literal", className, fullLength = false, containerHeight, maxMarkdownLength = MAX_TEXT_LENGTH, preserveNewlines = false, codeOverflow = "wrap", textColor = "primary", loadImages = false, components, trailingContent, afterContent }) {
|
|
242
|
+
const markdownComponents = useMemo(() => components ? {
|
|
243
|
+
...MARKDOWN_COMPONENTS,
|
|
244
|
+
...components
|
|
245
|
+
} : MARKDOWN_COMPONENTS, [components]);
|
|
246
|
+
const contextValue = useMemo(() => ({
|
|
247
|
+
loadImages,
|
|
248
|
+
trailingContent,
|
|
249
|
+
codeOverflow
|
|
250
|
+
}), [
|
|
251
|
+
loadImages,
|
|
252
|
+
trailingContent,
|
|
253
|
+
codeOverflow
|
|
254
|
+
]);
|
|
255
|
+
const isPlainText = content.length > maxMarkdownLength;
|
|
256
|
+
const markdown = useMemo(() => {
|
|
257
|
+
if (isPlainText) return content;
|
|
258
|
+
const prepared = xmlTags === "sections" ? prepareMarkdownXml(content) : content;
|
|
259
|
+
return isStreaming ? remend(prepared, {
|
|
260
|
+
linkMode: "text-only",
|
|
261
|
+
htmlTags: false,
|
|
262
|
+
katex: false
|
|
263
|
+
}) : prepared;
|
|
264
|
+
}, [
|
|
265
|
+
content,
|
|
266
|
+
isPlainText,
|
|
267
|
+
isStreaming,
|
|
268
|
+
xmlTags
|
|
269
|
+
]);
|
|
270
|
+
const plainText = /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx(TextWithLinks, {
|
|
271
|
+
text: content,
|
|
272
|
+
fullLength,
|
|
273
|
+
containerHeight,
|
|
274
|
+
useRawSpan: true
|
|
275
|
+
}), trailingContent] });
|
|
276
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
277
|
+
"data-component": COMPONENT_NAME,
|
|
278
|
+
"aria-busy": isStreaming || void 0,
|
|
279
|
+
className: cn("min-w-0 text-sm", className),
|
|
280
|
+
children: [/* @__PURE__ */ jsx(Text, {
|
|
281
|
+
as: "div",
|
|
282
|
+
variant: "body",
|
|
283
|
+
color: textColor,
|
|
284
|
+
"data-search-kind": "container",
|
|
285
|
+
className: cn("min-w-0 break-words", preserveNewlines && "whitespace-pre-wrap"),
|
|
286
|
+
children: isPlainText ? /* @__PURE__ */ jsxs("div", {
|
|
287
|
+
className: "relative pr-space-5",
|
|
288
|
+
children: [/* @__PURE__ */ jsx(Icon, {
|
|
289
|
+
"data-search-ignore": "",
|
|
290
|
+
icon: WarningCircleIcon,
|
|
291
|
+
color: "warning",
|
|
292
|
+
size: "xs",
|
|
293
|
+
label: PLAIN_TEXT_FALLBACK_MESSAGE,
|
|
294
|
+
role: "img",
|
|
295
|
+
tabIndex: 0,
|
|
296
|
+
"aria-label": PLAIN_TEXT_FALLBACK_MESSAGE,
|
|
297
|
+
className: "absolute right-0 top-0"
|
|
298
|
+
}), plainText]
|
|
299
|
+
}) : /* @__PURE__ */ jsx(ErrorBoundary, {
|
|
300
|
+
resetKey: content,
|
|
301
|
+
fallback: () => plainText,
|
|
302
|
+
children: /* @__PURE__ */ jsx(MarkdownDisplayContext.Provider, {
|
|
303
|
+
value: contextValue,
|
|
304
|
+
children: /* @__PURE__ */ jsx(ReactMarkdown, {
|
|
305
|
+
remarkPlugins: REMARK_PLUGINS,
|
|
306
|
+
rehypePlugins: REHYPE_PLUGINS,
|
|
307
|
+
components: markdownComponents,
|
|
308
|
+
children: markdown
|
|
309
|
+
})
|
|
310
|
+
})
|
|
311
|
+
})
|
|
312
|
+
}), afterContent]
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
MarkdownDisplay.displayName = COMPONENT_NAME;
|
|
316
|
+
//#endregion
|
|
317
|
+
export { MarkdownDisplay };
|
|
318
|
+
|
|
319
|
+
//# sourceMappingURL=MarkdownDisplay.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MarkdownDisplay.js","names":[],"sources":["../../../src/components/MarkdownDisplay/MarkdownDisplay.tsx"],"sourcesContent":["import {\n createContext,\n isValidElement,\n type ComponentProps,\n type MouseEvent,\n type ReactNode,\n useContext,\n useId,\n useMemo,\n} from 'react';\n\nimport type { Components, ExtraProps } from 'react-markdown';\nimport ReactMarkdown from 'react-markdown';\nimport remarkGfm from 'remark-gfm';\nimport remend from 'remend';\n\nimport { ImageIcon } from '@phosphor-icons/react/dist/ssr/Image';\nimport { WarningCircleIcon } from '@phosphor-icons/react/dist/ssr/WarningCircle';\n\nimport { cn } from '../../utils/cn';\nimport { makeComponentName } from '../../utils/componentUtils';\nimport { Checkbox } from '../Checkbox';\nimport { MAX_TEXT_LENGTH } from '../Code/constants';\nimport { ErrorBoundary } from '../ErrorBoundary';\nimport { Icon } from '../Icon';\nimport { Link } from '../Link';\nimport { Text, type TextProps } from '../Text';\nimport { TextWithLinks } from '../TextWithLinks';\nimport { MarkdownCodeBlock } from './MarkdownCodeBlock';\nimport {\n TRAILING_SLOT_ATTRIBUTE,\n rehypeMarkdownDisplay,\n remarkDisableRawHtml,\n} from './markdownPlugins';\nimport { prepareMarkdownXml } from './prepareMarkdownXml';\n\ntype TextColor = NonNullable<TextProps['color']>;\ntype ListType = 'ordered' | 'unordered';\ntype HeadingVariant = 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6';\ntype HeadingProps = ComponentProps<HeadingVariant> & ExtraProps;\ntype ListItemProps = ComponentProps<'li'> & ExtraProps;\ntype InputProps = ComponentProps<'input'> & ExtraProps;\ntype ImageProps = ComponentProps<'img'> & ExtraProps;\ntype SpanProps = ComponentProps<'span'> & ExtraProps;\n\ninterface MarkdownDisplayContextValue {\n loadImages: boolean;\n trailingContent: ReactNode;\n codeOverflow: 'wrap' | 'scroll';\n}\n\nconst COMPONENT_NAME = makeComponentName('MarkdownDisplay');\nconst PLAIN_TEXT_FALLBACK_MESSAGE =\n 'Shown as plain text because this block is too large for Markdown.';\nconst REMARK_PLUGINS = [remarkGfm, remarkDisableRawHtml];\nconst REHYPE_PLUGINS = [rehypeMarkdownDisplay];\nconst ListTypeContext = createContext<ListType>('unordered');\n/** The id of the enclosing task list item, which names its checkbox. */\nconst TaskItemContext = createContext<string | undefined>(undefined);\nconst MarkdownDisplayContext = createContext<MarkdownDisplayContextValue>({\n loadImages: false,\n trailingContent: null,\n codeOverflow: 'wrap',\n});\n\nconst blockSpacing =\n 'mt-space-4 first:mt-0 [:is(h1,h2,h3,h4,h5,h6)+&]:mt-space-2';\n/** Inline links keep the size and rhythm of the text they sit in. */\nconst inlineLinkClassName =\n 'inline text-[length:inherit] leading-[inherit] tracking-[inherit]';\n\nfunction MarkdownListItem({\n children,\n className,\n id,\n node: _node,\n ...props\n}: ListItemProps) {\n const listType = useContext(ListTypeContext);\n const generatedId = useId();\n const isTask = className?.split(' ').includes('task-list-item') ?? false;\n const hasBullet = listType === 'unordered' && !isTask;\n const itemId = id ?? (isTask ? generatedId : undefined);\n\n return (\n <TaskItemContext.Provider value={isTask ? itemId : undefined}>\n <li\n {...props}\n id={itemId}\n className={cn(\n 'text-sm leading-normal tracking-normal',\n hasBullet && 'relative pl-space-3',\n isTask &&\n 'relative list-none pl-space-5 has-[[data-state=checked]]:text-quaternary has-[[data-state=checked]]:line-through',\n className\n )}\n >\n {children}\n {/* Last so the item's first block keeps its first-child spacing. */}\n {hasBullet && (\n <span\n aria-hidden\n className=\"absolute left-0 top-[0.65em] size-1 rounded-full bg-current\"\n />\n )}\n </li>\n </TaskItemContext.Provider>\n );\n}\n\nfunction MarkdownTaskCheckbox({ checked, type }: InputProps) {\n const taskItemId = useContext(TaskItemContext);\n if (type !== 'checkbox') return null;\n\n const checkboxProps = {\n checked: checked ?? false,\n 'aria-readonly': true,\n tabIndex: -1,\n onClick: (event: MouseEvent<HTMLButtonElement>) => event.preventDefault(),\n size: 'sm',\n className: 'pointer-events-none',\n containerClassName: 'absolute left-0 top-[calc(0.75em_-_0.5rem)]',\n } as const;\n\n return taskItemId ? (\n <Checkbox {...checkboxProps} aria-labelledby={taskItemId} />\n ) : (\n <Checkbox\n {...checkboxProps}\n aria-label={checked ? 'Completed task' : 'Open task'}\n />\n );\n}\n\nfunction MarkdownImage({\n alt = '',\n src,\n className,\n node: _node,\n ...props\n}: ImageProps) {\n const { loadImages } = useContext(MarkdownDisplayContext);\n\n if (typeof src !== 'string' || !src) {\n return <span className=\"text-tertiary\">{alt}</span>;\n }\n\n if (!loadImages) {\n return (\n <Link\n href={src}\n variant=\"body\"\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n leftDecorator={ImageIcon}\n // Preflight makes SVGs block-level; keep the icon on the text line.\n className={cn(\n inlineLinkClassName,\n '[&>svg]:mr-[2px] [&>svg]:inline [&>svg]:align-[-0.125em]'\n )}\n >\n {alt || src}\n </Link>\n );\n }\n\n return (\n <img\n {...props}\n src={src}\n alt={alt}\n loading=\"lazy\"\n referrerPolicy=\"no-referrer\"\n className={cn(\n blockSpacing,\n 'h-auto max-w-full rounded-md border border-subtle',\n className\n )}\n />\n );\n}\n\nfunction MarkdownSpan({ node: _node, ...props }: SpanProps) {\n const { trailingContent } = useContext(MarkdownDisplayContext);\n if (TRAILING_SLOT_ATTRIBUTE in props) return <>{trailingContent}</>;\n return <span {...props} />;\n}\n\nconst createHeading = (\n variant: HeadingVariant,\n headingClassName: string,\n weight: TextProps['weight'] = 'semibold',\n color?: TextColor\n) =>\n function MarkdownHeading({\n children,\n className,\n color: _color,\n node: _node,\n ...props\n }: HeadingProps) {\n return (\n <Text\n {...props}\n as={variant}\n variant={variant}\n weight={weight}\n color={color}\n className={cn(blockSpacing, headingClassName, className)}\n >\n {children}\n </Text>\n );\n };\n\nconst MARKDOWN_COMPONENTS: Components = {\n pre: function MarkdownPre({ children }) {\n const { codeOverflow } = useContext(MarkdownDisplayContext);\n const child = isValidElement<{\n children?: ReactNode;\n className?: string;\n }>(children)\n ? children\n : undefined;\n const language = child?.props.className?.match(/language-([^\\s]+)/)?.[1];\n const code =\n typeof child?.props.children === 'string'\n ? child.props.children\n : String(child?.props.children ?? '');\n\n return (\n <div\n data-search-block=\"\"\n data-search-code=\"\"\n className={cn('w-full min-w-0', blockSpacing)}\n >\n <MarkdownCodeBlock\n code={code}\n language={language}\n codeOverflow={codeOverflow}\n />\n </div>\n );\n },\n code: ({ children, className, node: _node, ...props }) => (\n <code\n {...props}\n className={cn(\n 'rounded-xs bg-surface-level-3 px-space-1 py-px font-mono text-[length:0.9em] leading-[inherit] tracking-normal text-tertiary',\n className\n )}\n >\n {children}\n </code>\n ),\n a: ({ children, href, className, node: _node, ...props }) => {\n if (!href) return <span>{children}</span>;\n // Fragment links (footnote references and back-references) stay in page.\n const opensNewTab = !href.startsWith('#');\n\n return (\n <Link\n {...props}\n href={href}\n variant=\"body\"\n target={opensNewTab ? '_blank' : undefined}\n rel={opensNewTab ? 'noopener noreferrer' : undefined}\n className={cn(inlineLinkClassName, className)}\n >\n {children}\n </Link>\n );\n },\n h1: createHeading('h1', 'text-xl leading-tight'),\n h2: createHeading('h2', 'text-lg leading-tight'),\n h3: createHeading('h3', 'text-base leading-tight'),\n h4: createHeading('h4', 'text-sm leading-tight', 'semibold', 'quaternary'),\n h5: createHeading('h5', 'text-sm leading-tight', 'semibold', 'secondary'),\n h6: createHeading('h6', 'text-sm leading-tight', 'medium', 'secondary'),\n p: ({ children, className, color: _color, node: _node, ...props }) => (\n <Text\n {...props}\n as=\"p\"\n variant=\"body\"\n className={cn('mt-space-3 first:mt-0', className)}\n >\n {children}\n </Text>\n ),\n blockquote: ({ node: _node, ...props }) => (\n <blockquote\n {...props}\n className={cn(\n blockSpacing,\n 'border-l-4 border-default bg-surface-level-2 py-space-2 pl-space-4 pr-space-3 italic [overflow-wrap:anywhere]'\n )}\n />\n ),\n ul: ({ className, node: _node, ...props }) => (\n <ListTypeContext.Provider value=\"unordered\">\n <ul\n {...props}\n className={cn(\n blockSpacing,\n 'ml-space-3 flex flex-col gap-space-1 [li>&]:mt-space-1',\n className\n )}\n />\n </ListTypeContext.Provider>\n ),\n ol: ({ className, start, style, node, ...props }) => {\n const itemCount =\n node?.children.filter(\n (child) => child.type === 'element' && child.tagName === 'li'\n ).length ?? 0;\n const firstNumber = start ?? 1;\n const lastNumber = firstNumber + Math.max(itemCount - 1, 0);\n const markerDigits = Math.max(\n String(firstNumber).length,\n String(lastNumber).length\n );\n\n return (\n <ListTypeContext.Provider value=\"ordered\">\n <ol\n {...props}\n start={start}\n // Outside markers sit in this padding, so it widens with the\n // longest number instead of letting markers overflow and clip.\n style={{ ...style, paddingInlineStart: `${markerDigits + 1.5}ch` }}\n className={cn(\n blockSpacing,\n 'flex list-outside list-decimal flex-col gap-space-1 [li>&]:mt-space-1',\n className\n )}\n />\n </ListTypeContext.Provider>\n );\n },\n li: MarkdownListItem,\n input: MarkdownTaskCheckbox,\n table: ({ node: _node, ...props }) => (\n <div\n data-search-block=\"\"\n role=\"region\"\n aria-label=\"Table\"\n tabIndex={0}\n className={cn(\n blockSpacing,\n 'w-full overflow-x-auto focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-focus'\n )}\n >\n <table\n {...props}\n className=\"w-full min-w-max border-collapse text-left text-xs\"\n />\n </div>\n ),\n th: ({ node: _node, ...props }) => (\n <th\n {...props}\n className=\"border border-subtle dark:border-muted bg-surface-level-2 px-space-2 py-space-1 font-semibold\"\n />\n ),\n td: ({ node: _node, ...props }) => (\n <td\n {...props}\n className=\"border border-subtle dark:border-muted px-space-2 py-space-1 align-top\"\n />\n ),\n hr: ({ node: _node, ...props }) => (\n <hr {...props} className={cn(blockSpacing, 'border-default')} />\n ),\n strong: ({ className, node: _node, ...props }) => (\n <strong {...props} className={cn('font-semibold', className)} />\n ),\n em: ({ className, node: _node, ...props }) => (\n <em {...props} className={cn('italic', className)} />\n ),\n del: ({ node: _node, ...props }) => (\n <del {...props} className=\"text-tertiary\" />\n ),\n img: MarkdownImage,\n span: MarkdownSpan,\n};\n\nexport interface MarkdownDisplayProps {\n /** Markdown source to render. */\n content: string;\n /** Render custom XML wrappers as labeled sections, or keep tags literal (default). */\n xmlTags?: 'literal' | 'sections';\n /** Repair unfinished Markdown while content streams; use the original Markdown when false. */\n isStreaming?: boolean;\n className?: string;\n /**\n * Render oversized content in full as linkified, non-virtualized plain text\n * instead of truncating it behind a Show more toggle. Ignores\n * `containerHeight`.\n */\n fullLength?: boolean;\n /**\n * Viewport height for truncated oversized content. When set, that content\n * renders in a virtualized plain-text viewport whose URLs are not\n * linkified.\n */\n containerHeight?: string;\n /**\n * Longest content, in characters, rendered as Markdown; longer content\n * renders as plain text. Defaults to the shared text length limit. Raise it,\n * or pass `Infinity`, only for content of bounded size such as chat answers:\n * parsing cost grows with length, and the default keeps views of large\n * untrusted content responsive.\n */\n maxMarkdownLength?: number;\n /** Preserve single newlines visually without changing Markdown parsing. */\n preserveNewlines?: boolean;\n /** Wrap long fenced code lines by default, or scroll them horizontally. */\n codeOverflow?: 'wrap' | 'scroll';\n /** Color applied to text-bearing Markdown elements. */\n textColor?: TextColor;\n /**\n * Load images referenced by the Markdown. Off by default: loading a remote\n * image from untrusted content sends a request, and anything encoded in its\n * URL, without user action. Images otherwise render as links.\n */\n loadImages?: boolean;\n /**\n * Override or extend the default react-markdown component mapping. Keep\n * override components stable across renders; a new component function\n * remounts every element it renders.\n */\n components?: Components;\n /**\n * Content that continues the rendered flow: inline after the final\n * paragraph's text, or after the last block when content ends otherwise.\n */\n trailingContent?: ReactNode;\n /** Content rendered after the Markdown content container. */\n afterContent?: ReactNode;\n}\n\n/**\n * Renders untrusted Markdown with GFM support and Macaw presentation.\n *\n * Raw HTML is never interpreted. Tags display as text by default; opt in to\n * XML sections turn custom wrappers into labels and nested blockquotes.\n * Content above `maxMarkdownLength` (by default the shared text length limit)\n * renders as plain text, truncated behind a Show more toggle unless\n * `fullLength` is set.\n */\nexport function MarkdownDisplay({\n content,\n isStreaming = false,\n xmlTags = 'literal',\n className,\n fullLength = false,\n containerHeight,\n maxMarkdownLength = MAX_TEXT_LENGTH,\n preserveNewlines = false,\n codeOverflow = 'wrap',\n textColor = 'primary',\n loadImages = false,\n components,\n trailingContent,\n afterContent,\n}: MarkdownDisplayProps) {\n const markdownComponents = useMemo(\n () =>\n components\n ? { ...MARKDOWN_COMPONENTS, ...components }\n : MARKDOWN_COMPONENTS,\n [components]\n );\n const contextValue = useMemo(\n () => ({ loadImages, trailingContent, codeOverflow }),\n [loadImages, trailingContent, codeOverflow]\n );\n const isPlainText = content.length > maxMarkdownLength;\n const markdown = useMemo(() => {\n if (isPlainText) return content;\n const prepared =\n xmlTags === 'sections' ? prepareMarkdownXml(content) : content;\n return isStreaming\n ? remend(prepared, {\n // Partial destinations must never become clickable links.\n linkMode: 'text-only',\n // HTML is literal text here, and math rendering is unsupported.\n htmlTags: false,\n katex: false,\n })\n : prepared;\n }, [content, isPlainText, isStreaming, xmlTags]);\n\n const plainText = (\n <>\n <TextWithLinks\n text={content}\n fullLength={fullLength}\n containerHeight={containerHeight}\n useRawSpan\n />\n {trailingContent}\n </>\n );\n\n return (\n <div\n data-component={COMPONENT_NAME}\n aria-busy={isStreaming || undefined}\n className={cn('min-w-0 text-sm', className)}\n >\n <Text\n as=\"div\"\n variant=\"body\"\n color={textColor}\n data-search-kind=\"container\"\n className={cn(\n 'min-w-0 break-words',\n preserveNewlines && 'whitespace-pre-wrap'\n )}\n >\n {isPlainText ? (\n <div className=\"relative pr-space-5\">\n <Icon\n data-search-ignore=\"\"\n icon={WarningCircleIcon}\n color=\"warning\"\n size=\"xs\"\n label={PLAIN_TEXT_FALLBACK_MESSAGE}\n role=\"img\"\n tabIndex={0}\n aria-label={PLAIN_TEXT_FALLBACK_MESSAGE}\n className=\"absolute right-0 top-0\"\n />\n {plainText}\n </div>\n ) : (\n <ErrorBoundary resetKey={content} fallback={() => plainText}>\n <MarkdownDisplayContext.Provider value={contextValue}>\n <ReactMarkdown\n remarkPlugins={REMARK_PLUGINS}\n rehypePlugins={REHYPE_PLUGINS}\n components={markdownComponents}\n >\n {markdown}\n </ReactMarkdown>\n </MarkdownDisplayContext.Provider>\n </ErrorBoundary>\n )}\n </Text>\n {afterContent}\n </div>\n );\n}\n\nMarkdownDisplay.displayName = COMPONENT_NAME;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAmDA,IAAM,iBAAiB,kBAAkB,iBAAiB;AAC1D,IAAM,8BACJ;AACF,IAAM,iBAAiB,CAAC,WAAW,oBAAoB;AACvD,IAAM,iBAAiB,CAAC,qBAAqB;AAC7C,IAAM,kBAAkB,cAAwB,WAAW;;AAE3D,IAAM,kBAAkB,cAAkC,KAAA,CAAS;AACnE,IAAM,yBAAyB,cAA2C;CACxE,YAAY;CACZ,iBAAiB;CACjB,cAAc;AAChB,CAAC;AAED,IAAM,eACJ;;AAEF,IAAM,sBACJ;AAEF,SAAS,iBAAiB,EACxB,UACA,WACA,IACA,MAAM,OACN,GAAG,SACa;CAChB,MAAM,WAAW,WAAW,eAAe;CAC3C,MAAM,cAAc,MAAM;CAC1B,MAAM,SAAS,WAAW,MAAM,GAA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from 'react-markdown';
|
|
2
|
+
type HastElement = NonNullable<ExtraProps['node']>;
|
|
3
|
+
type HastChild = HastElement['children'][number];
|
|
4
|
+
type HastParent = {
|
|
5
|
+
children: HastChild[];
|
|
6
|
+
};
|
|
7
|
+
/** Marks where `trailingContent` renders inside the Markdown output. */
|
|
8
|
+
export declare const TRAILING_SLOT_ATTRIBUTE = "data-markdown-trailing";
|
|
9
|
+
export declare function rehypeMarkdownDisplay(): (tree: HastParent) => void;
|
|
10
|
+
/**
|
|
11
|
+
* Turns off CommonMark's raw HTML constructs. Raw HTML is never interpreted,
|
|
12
|
+
* and parsing it would let a non-standard tag such as `<reasoning>` swallow
|
|
13
|
+
* the Markdown that follows it up to the next blank line.
|
|
14
|
+
* XML section mode or application adapters first convert those tags to
|
|
15
|
+
* Markdown labels and blockquotes; disabling HTML does not change that output.
|
|
16
|
+
*/
|
|
17
|
+
export declare function remarkDisableRawHtml(this: unknown): void;
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
//#region packages/components/src/components/MarkdownDisplay/markdownPlugins.ts
|
|
2
|
+
/** Marks where `trailingContent` renders inside the Markdown output. */
|
|
3
|
+
var TRAILING_SLOT_ATTRIBUTE = "data-markdown-trailing";
|
|
4
|
+
var BLOCK_TAG_NAMES = /* @__PURE__ */ new Set([
|
|
5
|
+
"blockquote",
|
|
6
|
+
"div",
|
|
7
|
+
"h1",
|
|
8
|
+
"h2",
|
|
9
|
+
"h3",
|
|
10
|
+
"h4",
|
|
11
|
+
"h5",
|
|
12
|
+
"h6",
|
|
13
|
+
"hr",
|
|
14
|
+
"li",
|
|
15
|
+
"ol",
|
|
16
|
+
"p",
|
|
17
|
+
"pre",
|
|
18
|
+
"section",
|
|
19
|
+
"table",
|
|
20
|
+
"ul"
|
|
21
|
+
]);
|
|
22
|
+
var HTML_WHITESPACE = /^[\t\n\f\r ]*$/;
|
|
23
|
+
var isBlockElement = (node) => node?.type === "element" && BLOCK_TAG_NAMES.has(node.tagName);
|
|
24
|
+
var isInterBlockWhitespace = (node, index, siblings) => node.type === "text" && HTML_WHITESPACE.test(node.value) && (isBlockElement(siblings[index - 1]) || isBlockElement(siblings[index + 1]));
|
|
25
|
+
/**
|
|
26
|
+
* Removes whitespace that only separates markup: the line endings remark
|
|
27
|
+
* inserts between block elements, and the space after a task checkbox. Both
|
|
28
|
+
* are invisible under normal white-space handling, but `whitespace-pre-wrap`
|
|
29
|
+
* would render the line endings as blank lines and indent task text.
|
|
30
|
+
*/
|
|
31
|
+
function removeStructuralWhitespace(parent) {
|
|
32
|
+
parent.children = parent.children.filter((child, index, siblings) => !isInterBlockWhitespace(child, index, siblings));
|
|
33
|
+
parent.children.forEach((child, index, siblings) => {
|
|
34
|
+
const previous = siblings[index - 1];
|
|
35
|
+
if (child.type === "text" && previous?.type === "element" && previous.tagName === "input") child.value = child.value.replace(/^[\t\n\f\r ]+/, "");
|
|
36
|
+
if (child.type === "element") removeStructuralWhitespace(child);
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
/** Keep generated footnote spacing out of consumer text-search offsets. */
|
|
40
|
+
function markFootnoteSpacing(parent) {
|
|
41
|
+
parent.children = parent.children.flatMap((child, index, siblings) => {
|
|
42
|
+
const next = siblings[index + 1];
|
|
43
|
+
if (child.type === "text" && child.value.endsWith(" ") && next?.type === "element" && "dataFootnoteBackref" in next.properties) {
|
|
44
|
+
child.value = child.value.slice(0, -1);
|
|
45
|
+
return [child, {
|
|
46
|
+
type: "element",
|
|
47
|
+
tagName: "span",
|
|
48
|
+
properties: { "data-search-ignore": "" },
|
|
49
|
+
children: [{
|
|
50
|
+
type: "text",
|
|
51
|
+
value: " "
|
|
52
|
+
}]
|
|
53
|
+
}];
|
|
54
|
+
}
|
|
55
|
+
if (child.type === "element") markFootnoteSpacing(child);
|
|
56
|
+
return [child];
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Appends a slot for `trailingContent` to the final paragraph so the content
|
|
61
|
+
* continues that paragraph's text, or after the last block otherwise.
|
|
62
|
+
*/
|
|
63
|
+
function appendTrailingSlot(root) {
|
|
64
|
+
const last = root.children.at(-1);
|
|
65
|
+
(last?.type === "element" && last.tagName === "p" ? last : root).children.push({
|
|
66
|
+
type: "element",
|
|
67
|
+
tagName: "span",
|
|
68
|
+
properties: { [TRAILING_SLOT_ATTRIBUTE]: "" },
|
|
69
|
+
children: []
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
function rehypeMarkdownDisplay() {
|
|
73
|
+
return (tree) => {
|
|
74
|
+
removeStructuralWhitespace(tree);
|
|
75
|
+
markFootnoteSpacing(tree);
|
|
76
|
+
appendTrailingSlot(tree);
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Turns off CommonMark's raw HTML constructs. Raw HTML is never interpreted,
|
|
81
|
+
* and parsing it would let a non-standard tag such as `<reasoning>` swallow
|
|
82
|
+
* the Markdown that follows it up to the next blank line.
|
|
83
|
+
* XML section mode or application adapters first convert those tags to
|
|
84
|
+
* Markdown labels and blockquotes; disabling HTML does not change that output.
|
|
85
|
+
*/
|
|
86
|
+
function remarkDisableRawHtml() {
|
|
87
|
+
const data = this.data();
|
|
88
|
+
(data.micromarkExtensions ??= []).push({ disable: { null: ["htmlFlow", "htmlText"] } });
|
|
89
|
+
}
|
|
90
|
+
//#endregion
|
|
91
|
+
export { TRAILING_SLOT_ATTRIBUTE, rehypeMarkdownDisplay, remarkDisableRawHtml };
|
|
92
|
+
|
|
93
|
+
//# sourceMappingURL=markdownPlugins.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markdownPlugins.js","names":[],"sources":["../../../src/components/MarkdownDisplay/markdownPlugins.ts"],"sourcesContent":["import type { ExtraProps } from 'react-markdown';\n\ntype HastElement = NonNullable<ExtraProps['node']>;\ntype HastChild = HastElement['children'][number];\ntype HastParent = { children: HastChild[] };\n\n/** Marks where `trailingContent` renders inside the Markdown output. */\nexport const TRAILING_SLOT_ATTRIBUTE = 'data-markdown-trailing';\n\nconst BLOCK_TAG_NAMES = new Set([\n 'blockquote',\n 'div',\n 'h1',\n 'h2',\n 'h3',\n 'h4',\n 'h5',\n 'h6',\n 'hr',\n 'li',\n 'ol',\n 'p',\n 'pre',\n 'section',\n 'table',\n 'ul',\n]);\n\nconst HTML_WHITESPACE = /^[\\t\\n\\f\\r ]*$/;\n\nconst isBlockElement = (node: HastChild | undefined) =>\n node?.type === 'element' && BLOCK_TAG_NAMES.has(node.tagName);\n\nconst isInterBlockWhitespace = (\n node: HastChild,\n index: number,\n siblings: HastChild[]\n) =>\n node.type === 'text' &&\n HTML_WHITESPACE.test(node.value) &&\n (isBlockElement(siblings[index - 1]) || isBlockElement(siblings[index + 1]));\n\n/**\n * Removes whitespace that only separates markup: the line endings remark\n * inserts between block elements, and the space after a task checkbox. Both\n * are invisible under normal white-space handling, but `whitespace-pre-wrap`\n * would render the line endings as blank lines and indent task text.\n */\nfunction removeStructuralWhitespace(parent: HastParent) {\n parent.children = parent.children.filter(\n (child, index, siblings) => !isInterBlockWhitespace(child, index, siblings)\n );\n parent.children.forEach((child, index, siblings) => {\n const previous = siblings[index - 1];\n if (\n child.type === 'text' &&\n previous?.type === 'element' &&\n previous.tagName === 'input'\n ) {\n child.value = child.value.replace(/^[\\t\\n\\f\\r ]+/, '');\n }\n if (child.type === 'element') removeStructuralWhitespace(child);\n });\n}\n\n/** Keep generated footnote spacing out of consumer text-search offsets. */\nfunction markFootnoteSpacing(parent: HastParent) {\n parent.children = parent.children.flatMap((child, index, siblings) => {\n const next = siblings[index + 1];\n if (\n child.type === 'text' &&\n child.value.endsWith(' ') &&\n next?.type === 'element' &&\n 'dataFootnoteBackref' in next.properties\n ) {\n // remark appends this separator with the back-reference control.\n child.value = child.value.slice(0, -1);\n return [\n child,\n {\n type: 'element',\n tagName: 'span',\n properties: { 'data-search-ignore': '' },\n children: [{ type: 'text', value: ' ' }],\n } satisfies HastElement,\n ];\n }\n if (child.type === 'element') markFootnoteSpacing(child);\n return [child];\n });\n}\n\n/**\n * Appends a slot for `trailingContent` to the final paragraph so the content\n * continues that paragraph's text, or after the last block otherwise.\n */\nfunction appendTrailingSlot(root: HastParent) {\n const last = root.children.at(-1);\n const target = last?.type === 'element' && last.tagName === 'p' ? last : root;\n target.children.push({\n type: 'element',\n tagName: 'span',\n properties: { [TRAILING_SLOT_ATTRIBUTE]: '' },\n children: [],\n });\n}\n\nexport function rehypeMarkdownDisplay() {\n return (tree: HastParent) => {\n removeStructuralWhitespace(tree);\n markFootnoteSpacing(tree);\n appendTrailingSlot(tree);\n };\n}\n\n/**\n * Turns off CommonMark's raw HTML constructs. Raw HTML is never interpreted,\n * and parsing it would let a non-standard tag such as `<reasoning>` swallow\n * the Markdown that follows it up to the next blank line.\n * XML section mode or application adapters first convert those tags to\n * Markdown labels and blockquotes; disabling HTML does not change that output.\n */\nexport function remarkDisableRawHtml(this: unknown) {\n const data = (this as { data(): { micromarkExtensions?: unknown[] } }).data();\n (data.micromarkExtensions ??= []).push({\n disable: { null: ['htmlFlow', 'htmlText'] },\n });\n}\n"],"mappings":";;AAOA,IAAa,0BAA0B;AAEvC,IAAM,kCAAkB,IAAI,IAAI;CAC9B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AAED,IAAM,kBAAkB;AAExB,IAAM,kBAAkB,SACtB,MAAM,SAAS,aAAa,gBAAgB,IAAI,KAAK,OAAO;AAE9D,IAAM,0BACJ,MACA,OACA,aAEA,KAAK,SAAS,UACd,gBAAgB,KAAK,KAAK,KAAK,MAC9B,eAAe,SAAS,QAAQ,EAAE,KAAK,eAAe,SAAS,QAAQ,EAAE;;;;;;;AAQ5E,SAAS,2BAA2B,QAAoB;CACtD,OAAO,WAAW,OAAO,SAAS,QAC/B,OAAO,OAAO,aAAa,CAAC,uBAAuB,OAAO,OAAO,QAAQ,CAC5E;CACA,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C,YAAY,UAAU,EAAE,EAC5C,CAAC;AACH"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* When the content contains custom XML tags (non-standard HTML), treat ALL
|
|
3
|
+
* block-level tags as XML structure — including standard HTML elements like
|
|
4
|
+
* `<input>` or `<div>` that may appear alongside custom tags.
|
|
5
|
+
*
|
|
6
|
+
* Processes line by line with a tag stack to track nesting depth. Opening
|
|
7
|
+
* tags become bold `**[tagname]**` labels; content lines are prefixed with
|
|
8
|
+
* blockquote markers (`>`) per nesting level. Inline tags are stripped.
|
|
9
|
+
*
|
|
10
|
+
* If no custom XML tags are detected the content is returned unchanged so
|
|
11
|
+
* literal-tag rendering is unaffected. Oversized input is left unchanged for
|
|
12
|
+
* the plain-text fallback. This helper can also prepare text for a search index.
|
|
13
|
+
*/
|
|
14
|
+
export declare function prepareMarkdownXml(content: string): string;
|