You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: packages/module/patternfly-docs/content/extensions/chatbot/examples/Customizing Messages/Customizing Messages.md
# If you use typescript, the name of the interface to display props for
12
12
# These are found through the sourceProps function provided in patternfly-docs.source.js
13
13
sortValue: 60
14
14
---
15
15
16
-
# Modifying static content
16
+
##Modifying static content
17
17
18
-
The ChatBot extension `<Message>` component transforms Markdown to PatternFly React components. We use [react-markdown](https://github.com/remarkjs/react-markdown) to handle this mapping. This library supports both [rehype](https://unifiedjs.com/explore/package/rehype/) and [remark](https://unifiedjs.com/explore/package/remark/) plugins for further customization of the output.
18
+
The ChatBot extension `<Message>` component transforms Markdown to PatternFly React components via [react-markdown](https://github.com/remarkjs/react-markdown), which supports both [rehype](https://unifiedjs.com/explore/package/rehype/) and [remark](https://unifiedjs.com/explore/package/remark/) plugins for further output customization.
19
19
20
-
Remark handles parsing Markdown as input and serializing Markdown as output, while rehype does the same for HTML. This allows you to target and make transformations at specific checkpoints in the transformation process: while the text tree is still in Markdown, or while the text tree is in HTML format. For more detailed information on the architecture of this library, see the [react-markdown documentation](https://github.com/remarkjs/react-markdown?tab=readme-ov-file#architecture).
20
+
remark parses Markdown as input and serializes Markdown as output, while rehype does the same for HTML. This allows you to target and make transformations at specific checkpoints in the transformation process: either while the text tree is still in Markdown, or while the text tree is in HTML format. For more detailed information on the architecture of this library, see the [react-markdown documentation](https://github.com/remarkjs/react-markdown?tab=readme-ov-file#architecture).
21
21
22
-
You may need these plugins if, for example, you wanted to change the `href` on a link depending on the link text. The `<Message>` prop `rehypePlugins` will take any custom rehype plugins for the Message component. We use these plugins already within the extension for [rendering images a certain way](https://www.npmjs.com/package/rehype-unwrap-images) and [handling external links](https://www.npmjs.com/package/rehype-external-links). There are many open-source libraries available for other common use cases as well.
22
+
You may need these plugins if, for example, you wanted to change the `href` on a link based on the link text. The `<Message>` prop `rehypePlugins` will accept any custom rehype plugins. We use already use these plugins in ChatBot to [render images a certain way](https://www.npmjs.com/package/rehype-unwrap-images) and [handle external links](https://www.npmjs.com/package/rehype-external-links).
23
23
24
-
If you can't find one for your use case, [Unified](https://unifiedjs.com/) has [a helpful guide](https://unifiedjs.com/learn/guide/create-a-rehype-plugin/) on how to create custom plugins. For a more direct example, if we wanted to change the `href` on links that included the text string `react`, we could write a very basic plugin like this:
24
+
There are many open source libraries available for other common customization needs. If you can't find one for your use case, [Unified](https://unifiedjs.com/) has a helpful [guide on creating custom plugins](https://unifiedjs.com/learn/guide/create-a-rehype-plugin/).
25
+
For a more direct example, if we wanted to change the `href` on links that included the text string `react`, we could write a very basic plugin like this:
You could then pass `[rehypeLinkHrefUpdater]` to the `additionalRehypePlugins` prop on `<Message>` to have this applied to all relevant links read by that `<Message>` component.
42
43
43
-
# Modifying dynamic content
44
+
##Modifying dynamic content
44
45
45
-
Continuing with our link modification example, let's say you also wanted to add custom onClick events. In this case, you would not use `remark` or `rehype`. These libraries are for static tree manipulation - JavaScript is done through the extension itself.
46
+
Props can also be used to modify dynamic content in messages.
46
47
47
-
We offer many props on `<Message>` to allow for passing in custom behavior. As an example, you can use `linkProps` to pass onClick events and other PatternFly `<Button>` props down to links. A very basic example would be `linkProps={{onClick: (event) => console.log(event}}`. This would apply to every link in the Message, but you should be able to grab the event.target and add your own custom onClick logic based on the innerText, innerHTML, or other attributes of the event.target.
48
+
Continuing with our link modification example, let's say you also wanted to add custom `onClick` events. In this case, you would not use `remark` or `rehype`, since they're for static tree manipulation.
49
+
50
+
Instead, you can utilize ChatBot features to customize dynamic content. We offer many `<Message>` props that allow you to implement custom behavior.
51
+
For example, you can use `linkProps` to pass `onClick` events and other PatternFly `<Button>` props down to links. A very basic example would be `linkProps={{onClick: (event) => console.log(event}}`, which would apply to every link in the `<Message>`. Or, you could use the `event.target`, adding your own custom `onClick` logic based on the `innerText`, `innerHTML`, or other attributes of the `event.target`.
0 commit comments