@assistant-ui/react-markdown 0.10.7 → 0.10.8

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.
@@ -11,11 +11,19 @@ export type MarkdownTextPrimitiveProps = Omit<Options, "components" | "children"
11
11
  SyntaxHighlighter?: ComponentType<SyntaxHighlighterProps> | undefined;
12
12
  CodeHeader?: ComponentType<CodeHeaderProps> | undefined;
13
13
  }) | undefined;
14
+ /**
15
+ * Language-specific component overrides.
16
+ * @example { mermaid: { SyntaxHighlighter: MermaidDiagram } }
17
+ */
14
18
  componentsByLanguage?: Record<string, {
15
19
  CodeHeader?: ComponentType<CodeHeaderProps> | undefined;
16
20
  SyntaxHighlighter?: ComponentType<SyntaxHighlighterProps> | undefined;
17
21
  }> | undefined;
18
22
  smooth?: boolean | undefined;
23
+ /**
24
+ * Function to transform text before markdown processing.
25
+ */
26
+ preprocess?: (text: string) => string;
19
27
  };
20
28
  export declare const MarkdownTextPrimitive: ForwardRefExoticComponent<MarkdownTextPrimitiveProps> & RefAttributes<HTMLDivElement>;
21
29
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"MarkdownText.d.ts","sourceRoot":"","sources":["../../src/primitives/MarkdownText.tsx"],"names":[],"mappings":"AAGA,OAAO,EAEL,WAAW,EAGX,yBAAyB,EACzB,aAAa,EAEb,KAAK,wBAAwB,EAC7B,KAAK,aAAa,EACnB,MAAM,OAAO,CAAC;AACf,OAAsB,EAAE,KAAK,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAC7D,OAAO,EAAE,sBAAsB,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAU7E,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAMtD,KAAK,iBAAiB,GAAG,wBAAwB,CAAC,OAAO,SAAS,CAAC,GAAG,CAAC,CAAC;AAExE,MAAM,MAAM,0BAA0B,GAAG,IAAI,CAC3C,OAAO,EACP,YAAY,GAAG,UAAU,CAC1B,G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0B,GAAG,IAAI,CAC3C,OAAO,EACP,YAAY,GAAG,UAAU,CAC1B,GAAG;IACF,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC/B,cAAc,CAAC,EAAE,IAAI,CAAC,iBAAiB,EAAE,UAAU,GAAG,SAAS,CAAC,GAAG,SAAS,CAAC;IAC7E,kBAAkB,CAAC,EAAE,WAAW,GAAG,SAAS,CAAC;IAC7C,UAAU,CAAC,EACP,CAAC,WAAW,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,GAAG;QACpC,iBAAiB,CAAC,EAAE,aAAa,CAAC,sBAAsB,CAAC,GAAG,SAAS,CAAC;QACtE,UAAU,CAAC,EAAE,aAAa,CAAC,eAAe,CAAC,GAAG,SAAS,CAAC;KACzD,CAAC,GACF,SAAS,CAAC;IACd;;;OAGG;IACH,oBAAoB,CAAC,EACjB,MAAM,CACJ,MAAM,EACN;QACE,UAAU,CAAC,EAAE,aAAa,CAAC,eAAe,CAAC,GAAG,SAAS,CAAC;QACxD,iBAAiB,CAAC,EAAE,aAAa,CAAC,sBAAsB,CAAC,GAAG,SAAS,CAAC;KACvE,CACF,GACD,SAAS,CAAC;IACd,MAAM,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAC7B;;OAEG;IACH,UAAU,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC;CACvC,CAAC;AA2FF,eAAO,MAAM,qBAAqB,uFAEjC,CAAC"}
@@ -23,9 +23,18 @@ var MarkdownTextInner = ({
23
23
  components: userComponents,
24
24
  componentsByLanguage,
25
25
  smooth = true,
26
+ preprocess,
26
27
  ...rest
27
28
  }) => {
28
- const { text } = useSmooth(useMessagePartText(), smooth);
29
+ const messagePartText = useMessagePartText();
30
+ const processedMessagePart = useMemo(() => {
31
+ if (!preprocess) return messagePartText;
32
+ return {
33
+ ...messagePartText,
34
+ text: preprocess(messagePartText.text)
35
+ };
36
+ }, [messagePartText, preprocess]);
37
+ const { text } = useSmooth(processedMessagePart, smooth);
29
38
  const {
30
39
  pre = DefaultPre,
31
40
  code = DefaultCode,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/primitives/MarkdownText.tsx"],"sourcesContent":["\"use client\";\n\nimport { INTERNAL, useMessagePartText } from \"@assistant-ui/react\";\nimport {\n ComponentRef,\n ElementType,\n FC,\n forwardRef,\n ForwardRefExoticComponent,\n RefAttributes,\n useMemo,\n type ComponentPropsWithoutRef,\n type ComponentType,\n} from \"react\";\nimport ReactMarkdown, { type Options } from \"react-markdown\";\nimport { SyntaxHighlighterProps, CodeHeaderProps } from \"../overrides/types\";\nimport { PreOverride } from \"../overrides/PreOverride\";\nimport {\n DefaultPre,\n DefaultCode,\n DefaultCodeBlockContent,\n DefaultCodeHeader,\n} from \"../overrides/defaultComponents\";\nimport { useCallbackRef } from \"@radix-ui/react-use-callback-ref\";\nimport { CodeOverride } from \"../overrides/CodeOverride\";\nimport { Primitive } from \"@radix-ui/react-primitive\";\nimport classNames from \"classnames\";\n\nconst { useSmooth, useSmoothStatus, withSmoothContextProvider } = INTERNAL;\n\ntype MarkdownTextPrimitiveElement = ComponentRef<typeof Primitive.div>;\ntype PrimitiveDivProps = ComponentPropsWithoutRef<typeof Primitive.div>;\n\nexport type MarkdownTextPrimitiveProps = Omit<\n Options,\n \"components\" | \"children\"\n> & {\n className?: string | undefined;\n containerProps?: Omit<PrimitiveDivProps, \"children\" | \"asChild\"> | undefined;\n containerComponent?: ElementType | undefined;\n components?:\n | (NonNullable<Options[\"components\"]> & {\n SyntaxHighlighter?: ComponentType<SyntaxHighlighterProps> | undefined;\n CodeHeader?: ComponentType<CodeHeaderProps> | undefined;\n })\n | undefined;\n componentsByLanguage?:\n | Record<\n string,\n {\n CodeHeader?: ComponentType<CodeHeaderProps> | undefined;\n SyntaxHighlighter?: ComponentType<SyntaxHighlighterProps> | undefined;\n }\n >\n | undefined;\n smooth?: boolean | undefined;\n};\n\nconst MarkdownTextInner: FC<MarkdownTextPrimitiveProps> = ({\n components: userComponents,\n componentsByLanguage,\n smooth = true,\n ...rest\n}) => {\n const { text } = useSmooth(useMessagePartText(), smooth);\n\n const {\n pre = DefaultPre,\n code = DefaultCode,\n SyntaxHighlighter = DefaultCodeBlockContent,\n CodeHeader = DefaultCodeHeader,\n } = userComponents ?? {};\n const useCodeOverrideComponents = useMemo(() => {\n return {\n Pre: pre,\n Code: code,\n SyntaxHighlighter,\n CodeHeader,\n };\n }, [pre, code, SyntaxHighlighter, CodeHeader]);\n const CodeComponent = useCallbackRef((props) => (\n <CodeOverride\n components={useCodeOverrideComponents}\n componentsByLanguage={componentsByLanguage}\n {...props}\n />\n ));\n\n const components: Options[\"components\"] = useMemo(() => {\n const { pre, code, SyntaxHighlighter, CodeHeader, ...componentsRest } =\n userComponents ?? {};\n return {\n ...componentsRest,\n pre: PreOverride,\n code: CodeComponent,\n };\n }, [CodeComponent, userComponents]);\n\n return (\n <ReactMarkdown components={components} {...rest}>\n {text}\n </ReactMarkdown>\n );\n};\n\nconst MarkdownTextPrimitiveImpl: ForwardRefExoticComponent<MarkdownTextPrimitiveProps> &\n RefAttributes<MarkdownTextPrimitiveElement> = forwardRef<\n MarkdownTextPrimitiveElement,\n MarkdownTextPrimitiveProps\n>(\n (\n {\n className,\n containerProps,\n containerComponent: Container = \"div\",\n ...rest\n },\n forwardedRef,\n ) => {\n const status = useSmoothStatus();\n return (\n <Container\n data-status={status.type}\n {...containerProps}\n className={classNames(className, containerProps?.className)}\n ref={forwardedRef}\n >\n <MarkdownTextInner {...rest}></MarkdownTextInner>\n </Container>\n );\n },\n);\n\nMarkdownTextPrimitiveImpl.displayName = \"MarkdownTextPrimitive\";\n\nexport const MarkdownTextPrimitive = withSmoothContextProvider(\n MarkdownTextPrimitiveImpl,\n);\n"],"mappings":";;;AAEA,SAAS,UAAU,0BAA0B;AAC7C;AAAA,EAIE;AAAA,EAGA;AAAA,OAGK;AACP,OAAO,mBAAqC;AAE5C,SAAS,mBAAmB;AAC5B;AAAA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AA,QACC,eAAa,OAAO;AAAA,QACnB,GAAG;AAAA,QACJ,WAAW,WAAW,WAAW,gBAAgB,SAAS;AAAA,QAC1D,KAAK;AAAA,QAEL,8BAAC,qBAAmB,GAAG,MAAM;AAAA;AAAA,IAC/B;AAAA,EAEJ;AACF;AAEA,0BAA0B,cAAc;AAEjC,IAAM,wBAAwB;AAAA,EACnC;AACF;","names":["pre","code","SyntaxHighlighter","CodeHeader"]}
1
+ {"version":3,"sources":["../../src/primitives/MarkdownText.tsx"],"sourcesContent":["\"use client\";\n\nimport { INTERNAL, useMessagePartText } from \"@assistant-ui/react\";\nimport {\n ComponentRef,\n ElementType,\n FC,\n forwardRef,\n ForwardRefExoticComponent,\n RefAttributes,\n useMemo,\n type ComponentPropsWithoutRef,\n type ComponentType,\n} from \"react\";\nimport ReactMarkdown, { type Options } from \"react-markdown\";\nimport { SyntaxHighlighterProps, CodeHeaderProps } from \"../overrides/types\";\nimport { PreOverride } from \"../overrides/PreOverride\";\nimport {\n DefaultPre,\n DefaultCode,\n DefaultCodeBlockContent,\n DefaultCodeHeader,\n} from \"../overrides/defaultComponents\";\nimport { useCallbackRef } from \"@radix-ui/react-use-callback-ref\";\nimport { CodeOverride } from \"../overrides/CodeOverride\";\nimport { Primitive } from \"@radix-ui/react-primitive\";\nimport classNames from \"classnames\";\n\nconst { useSmooth, useSmoothStatus, withSmoothContextProvider } = INTERNAL;\n\ntype MarkdownTextPrimitiveElement = ComponentRef<typeof Primitive.div>;\ntype PrimitiveDivProps = ComponentPropsWithoutRef<typeof Primitive.div>;\n\nexport type MarkdownTextPrimitiveProps = Omit<\n Options,\n \"components\" | \"children\"\n> & {\n className?: string | undefined;\n containerProps?: Omit<PrimitiveDivProps, \"children\" | \"asChild\"> | undefined;\n containerComponent?: ElementType | undefined;\n components?:\n | (NonNullable<Options[\"components\"]> & {\n SyntaxHighlighter?: ComponentType<SyntaxHighlighterProps> | undefined;\n CodeHeader?: ComponentType<CodeHeaderProps> | undefined;\n })\n | undefined;\n /**\n * Language-specific component overrides.\n * @example { mermaid: { SyntaxHighlighter: MermaidDiagram } }\n */\n componentsByLanguage?:\n | Record<\n string,\n {\n CodeHeader?: ComponentType<CodeHeaderProps> | undefined;\n SyntaxHighlighter?: ComponentType<SyntaxHighlighterProps> | undefined;\n }\n >\n | undefined;\n smooth?: boolean | undefined;\n /**\n * Function to transform text before markdown processing.\n */\n preprocess?: (text: string) => string;\n};\n\nconst MarkdownTextInner: FC<MarkdownTextPrimitiveProps> = ({\n components: userComponents,\n componentsByLanguage,\n smooth = true,\n preprocess,\n ...rest\n}) => {\n const messagePartText = useMessagePartText();\n\n const processedMessagePart = useMemo(() => {\n if (!preprocess) return messagePartText;\n\n return {\n ...messagePartText,\n text: preprocess(messagePartText.text),\n };\n }, [messagePartText, preprocess]);\n\n const { text } = useSmooth(processedMessagePart, smooth);\n\n const {\n pre = DefaultPre,\n code = DefaultCode,\n SyntaxHighlighter = DefaultCodeBlockContent,\n CodeHeader = DefaultCodeHeader,\n } = userComponents ?? {};\n const useCodeOverrideComponents = useMemo(() => {\n return {\n Pre: pre,\n Code: code,\n SyntaxHighlighter,\n CodeHeader,\n };\n }, [pre, code, SyntaxHighlighter, CodeHeader]);\n const CodeComponent = useCallbackRef((props) => (\n <CodeOverride\n components={useCodeOverrideComponents}\n componentsByLanguage={componentsByLanguage}\n {...props}\n />\n ));\n\n const components: Options[\"components\"] = useMemo(() => {\n const { pre, code, SyntaxHighlighter, CodeHeader, ...componentsRest } =\n userComponents ?? {};\n return {\n ...componentsRest,\n pre: PreOverride,\n code: CodeComponent,\n };\n }, [CodeComponent, userComponents]);\n\n return (\n <ReactMarkdown components={components} {...rest}>\n {text}\n </ReactMarkdown>\n );\n};\n\nconst MarkdownTextPrimitiveImpl: ForwardRefExoticComponent<MarkdownTextPrimitiveProps> &\n RefAttributes<MarkdownTextPrimitiveElement> = forwardRef<\n MarkdownTextPrimitiveElement,\n MarkdownTextPrimitiveProps\n>(\n (\n {\n className,\n containerProps,\n containerComponent: Container = \"div\",\n ...rest\n },\n forwardedRef,\n ) => {\n const status = useSmoothStatus();\n return (\n <Container\n data-status={status.type}\n {...containerProps}\n className={classNames(className, containerProps?.className)}\n ref={forwardedRef}\n >\n <MarkdownTextInner {...rest}></MarkdownTextInner>\n </Container>\n );\n },\n);\n\nMarkdownTextPrimitiveImpl.displayName = \"MarkdownTextPrimitive\";\n\nexport const MarkdownTextPrimitive = withSmoothContextProvider(\n MarkdownTextPrimitiveImpl,\n);\n"],"mappings":";;;AAEA,SAAS,UAAU,0BAA0B;AAC7C;AAAA,EAIE;AAAA,EAGA;AAAA,OAGK;AACP,OAAO,mBAAqC;AAE5C,SAAS,mBAAmB;AAC5B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,sBAAsB;AAC/B,SAAS,oBAAoB;AAE7B,OAAO,gBAAgB;AA2EnB;AAzEJ,IAAM,EAAE,WAAW,iBAAiB,0BAA0B,IAAI;AAsClE,IAAM,oBAAoD,CAAC;AAAA,EACzD,YAAY;AAAA,EACZ;AAAA,EACA,SAAS;AAAA,EACT;AAAA,EACA,GAAG;AACL,MAAM;AACJ,QAAM,kBAAkB,mBAAmB;AAE3C,QAAM,uBAAuB,QAAQ,MAAM;AACzC,QAAI,CAAC,WAAY,QAAO;AAExB,WAAO;AAAA,MACL,GAAG;AAAA,MACH,MAAM,WAAW,gBAAgB,IAAI;AAAA,IACvC;AAAA,EACF,GAAG,CAAC,iBAAiB,UAAU,CAAC;AAEhC,QAAM,EAAE,KAAK,IAAI,UAAU,sBAAsB,MAAM;AAEvD,QAAM;AAAA,IACJ,MAAM;AAAA,IACN,OAAO;AAAA,IACP,oBAAoB;AAAA,IACpB,aAAa;AAAA,EACf,IAAI,kBAAkB,CAAC;AACvB,QAAM,4BAA4B,QAAQ,MAAM;AAC9C,WAAO;AAAA,MACL,KAAK;AAAA,MACL,MAAM;AAAA,MACN;AAAA,MACA;AAAA,IACF;AAAA,EACF,GAAG,CAAC,KAAK,MAAM,mBAAmB,UAAU,CAAC;AAC7C,QAAM,gBAAgB,eAAe,CAAC,UACpC;AAAA,IAAC;AAAA;AAAA,MACC,YAAY;AAAA,MACZ;AAAA,MACC,GAAG;AAAA;AAAA,EACN,CACD;AAED,QAAM,aAAoC,QAAQ,MAAM;AACtD,UAAM,EAAE,KAAAA,MAAK,MAAAC,OAAM,mBAAAC,oBAAmB,YAAAC,aAAY,GAAG,eAAe,IAClE,kBAAkB,CAAC;AACrB,WAAO;AAAA,MACL,GAAG;AAAA,MACH,KAAK;AAAA,MACL,MAAM;AAAA,IACR;AAAA,EACF,GAAG,CAAC,eAAe,cAAc,CAAC;AAElC,SACE,oBAAC,iBAAc,YAAyB,GAAG,MACxC,gBACH;AAEJ;AAEA,IAAM,4BAC0C;AAAA,EAI9C,CACE;AAAA,IACE;AAAA,IACA;AAAA,IACA,oBAAoB,YAAY;AAAA,IAChC,GAAG;AAAA,EACL,GACA,iBACG;AACH,UAAM,SAAS,gBAAgB;AAC/B,WACE;AAAA,MAAC;AAAA;AAAA,QACC,eAAa,OAAO;AAAA,QACnB,GAAG;AAAA,QACJ,WAAW,WAAW,WAAW,gBAAgB,SAAS;AAAA,QAC1D,KAAK;AAAA,QAEL,8BAAC,qBAAmB,GAAG,MAAM;AAAA;AAAA,IAC/B;AAAA,EAEJ;AACF;AAEA,0BAA0B,cAAc;AAEjC,IAAM,wBAAwB;AAAA,EACnC;AACF;","names":["pre","code","SyntaxHighlighter","CodeHeader"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@assistant-ui/react-markdown",
3
- "version": "0.10.7",
3
+ "version": "0.10.8",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "exports": {
@@ -30,7 +30,7 @@
30
30
  "react-markdown": "^10.1.0"
31
31
  },
32
32
  "peerDependencies": {
33
- "@assistant-ui/react": "^0.10.34",
33
+ "@assistant-ui/react": "^0.10.36",
34
34
  "@types/react": "*",
35
35
  "react": "^18 || ^19 || ^19.0.0-rc"
36
36
  },
@@ -47,7 +47,7 @@
47
47
  "react-dom": "19.1.1",
48
48
  "tsx": "^4.20.3",
49
49
  "vitest": "^3.2.4",
50
- "@assistant-ui/react": "0.10.34",
50
+ "@assistant-ui/react": "0.10.36",
51
51
  "@assistant-ui/x-buildutils": "0.0.1"
52
52
  },
53
53
  "publishConfig": {
@@ -44,6 +44,10 @@ export type MarkdownTextPrimitiveProps = Omit<
44
44
  CodeHeader?: ComponentType<CodeHeaderProps> | undefined;
45
45
  })
46
46
  | undefined;
47
+ /**
48
+ * Language-specific component overrides.
49
+ * @example { mermaid: { SyntaxHighlighter: MermaidDiagram } }
50
+ */
47
51
  componentsByLanguage?:
48
52
  | Record<
49
53
  string,
@@ -54,15 +58,31 @@ export type MarkdownTextPrimitiveProps = Omit<
54
58
  >
55
59
  | undefined;
56
60
  smooth?: boolean | undefined;
61
+ /**
62
+ * Function to transform text before markdown processing.
63
+ */
64
+ preprocess?: (text: string) => string;
57
65
  };
58
66
 
59
67
  const MarkdownTextInner: FC<MarkdownTextPrimitiveProps> = ({
60
68
  components: userComponents,
61
69
  componentsByLanguage,
62
70
  smooth = true,
71
+ preprocess,
63
72
  ...rest
64
73
  }) => {
65
- const { text } = useSmooth(useMessagePartText(), smooth);
74
+ const messagePartText = useMessagePartText();
75
+
76
+ const processedMessagePart = useMemo(() => {
77
+ if (!preprocess) return messagePartText;
78
+
79
+ return {
80
+ ...messagePartText,
81
+ text: preprocess(messagePartText.text),
82
+ };
83
+ }, [messagePartText, preprocess]);
84
+
85
+ const { text } = useSmooth(processedMessagePart, smooth);
66
86
 
67
87
  const {
68
88
  pre = DefaultPre,