Skip to content

Commit 402c765

Browse files
committed
Added new examples section for Markdown
1 parent d25d27c commit 402c765

File tree

5 files changed

+104
-134
lines changed

5 files changed

+104
-134
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { FunctionComponent } from 'react';
2+
import Message from '@patternfly/chatbot/dist/dynamic/Message';
3+
import patternflyAvatar from './patternfly_avatar.jpg';
4+
5+
export const MessageWithMarkdownDeepThinkingExample: FunctionComponent = () => (
6+
<Message
7+
name="Bot"
8+
role="bot"
9+
avatar={patternflyAvatar}
10+
content="This example shows how to use Markdown formatting in deep thinking content. Note the use of shouldRetainStyles to maintain proper formatting:"
11+
deepThinking={{
12+
shouldRetainStyles: true,
13+
toggleContent: 'Show thinking',
14+
subheading: '> Thought for 3 seconds',
15+
isSubheadingMarkdown: true,
16+
body: `I considered **multiple approaches** to answer your question:
17+
18+
1. *Direct response* - Quick but less comprehensive
19+
2. *Research-based* - Thorough but time-consuming
20+
3. **Balanced approach** - Combines speed and accuracy
21+
22+
I chose option 3 because it provides the best user experience.`,
23+
isBodyMarkdown: true
24+
}}
25+
/>
26+
);
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { FunctionComponent } from 'react';
2+
import Message from '@patternfly/chatbot/dist/dynamic/Message';
3+
import patternflyAvatar from './patternfly_avatar.jpg';
4+
5+
export const MessageWithMarkdownToolCallExample: FunctionComponent = () => (
6+
<Message
7+
name="Bot"
8+
role="bot"
9+
avatar={patternflyAvatar}
10+
content="This example shows how to use Markdown formatting in tool call content. Note the use of shouldRetainStyles to maintain proper formatting:"
11+
toolCall={{
12+
shouldRetainStyles: true,
13+
titleText: "Calling 'data_processor'",
14+
expandableContent: `**Processing data** from the following sources:
15+
16+
- Database query results
17+
- API responses
18+
- *Local cache*
19+
20+
\`\`\`json
21+
{
22+
"status": "processing",
23+
"items": 42
24+
}
25+
\`\`\``,
26+
isExpandableContentMarkdown: true
27+
}}
28+
/>
29+
);

packages/module/patternfly-docs/content/extensions/chatbot/examples/Messages/MessageWithMarkdownToolResponse.tsx

Lines changed: 16 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -19,142 +19,31 @@ export const MessageWithToolResponseExample: FunctionComponent = () => {
1919
const onToggle = (_event: ReactMouseEvent, isExpanded: boolean) => {
2020
setIsExpanded(isExpanded);
2121
};
22-
const comprehensiveMarkdownBody = `Here's a comprehensive markdown example with various formatting options:
23-
24-
# h1 Heading
25-
26-
## h2 Heading
27-
28-
### h3 Heading
29-
30-
#### h4 Heading
31-
32-
##### h5 Heading
33-
34-
###### h6 Heading
35-
36-
## Text Emphasis
37-
38-
**Bold text, formatted with double asterisks**
39-
40-
__Bold text, formatted with double underscores__
41-
42-
*Italic text, formatted with single asterisks*
43-
44-
_Italic text, formatted with single underscores_
45-
46-
~~Strikethrough~~
47-
48-
## Inline Code
49-
50-
Here is an inline code example - \`() => void\`
51-
52-
## Code Blocks
53-
54-
Here is some YAML code:
55-
56-
~~~yaml
57-
apiVersion: helm.openshift.io/v1beta1/
58-
kind: HelmChartRepository
59-
metadata:
60-
name: azure-sample-repo0oooo00ooo
61-
spec:
62-
connectionConfig:
63-
url: https://raw.githubusercontent.com/Azure-Samples/helm-charts/master/docs
64-
~~~
65-
66-
Here is some JavaScript code:
67-
68-
~~~js
69-
const MessageLoading = () => (
70-
<div className="pf-chatbot__message-loading">
71-
<span className="pf-chatbot__message-loading-dots">
72-
<span className="pf-v6-screen-reader">Loading message</span>
73-
</span>
74-
</div>
75-
);
76-
77-
export default MessageLoading;
78-
~~~
79-
80-
## Block Quotes
81-
82-
> Blockquotes can also be nested...
83-
>> ...by using additional greater-than signs (>) right next to each other...
84-
> > > ...or with spaces between each sign.
85-
86-
## Lists
87-
88-
### Ordered List
89-
90-
1. Item 1
91-
2. Item 2
92-
3. Item 3
93-
94-
### Unordered List
95-
96-
* Item 1
97-
* Item 2
98-
* Item 3
99-
100-
### More Complex List
101-
102-
You may be wondering whether you can display more complex lists with formatting. In response to your question, I will explain how to spread butter on toast.
103-
104-
1. **Using a \`toaster\`:**
105-
106-
- Place \`bread\` in a \`toaster\`
107-
- Once \`bread\` is lightly browned, remove from \`toaster\`
108-
109-
2. **Using a \`knife\`:**
110-
111-
- Acquire 1 tablespoon of room temperature \`butter\`. Use \`knife\` to spread butter on \`toast\`. Bon appétit!
112-
113-
## Links
114-
115-
A paragraph with a URL: https://reactjs.org.
116-
117-
## Tables
118-
119-
To customize your table, you can use [PatternFly TableProps](/components/table#table)
120-
121-
| Version | GA date | User role
122-
|-|-|-|
123-
| 2.5 | September 30, 2024 | Administrator |
124-
| 2.5 | June 27, 2023 | Editor |
125-
| 3.0 | April 1, 2025 | Administrator
126-
127-
## Images
128-
129-
![Multi-colored wavy lines on a black background](https://cdn.dribbble.com/userupload/10651749/file/original-8a07b8e39d9e8bf002358c66fce1223e.gif)
130-
131-
## Footnotes
132-
133-
This is some text that has a short footnote[^1] and this is text with a longer footnote.[^bignote]
134-
135-
[^1]: This is a short footnote. To return the highlight to the original message, click the arrow.
136-
137-
[^bignote]: This is a long footnote with multiple paragraphs and formatting.
138-
139-
To break long footnotes into paragraphs, indent the text.
140-
141-
Add as many paragraphs as you like. You can include *italic text*, **bold text**, and \`code\`.
142-
143-
> You can even include blockquotes in footnotes!
144-
`;
22+
const toolResponseBody = `The tool processed **3 database queries** and returned the following results:
23+
24+
1. User data - *42 records*
25+
2. Transaction history - *128 records*
26+
3. Analytics metrics - *15 data points*
27+
28+
\`\`\`json
29+
{
30+
"status": "success",
31+
"execution_time": "0.12s"
32+
}
33+
\`\`\``;
14534
return (
14635
<Message
14736
name="Bot"
14837
role="bot"
14938
avatar={patternflyAvatar}
150-
content="This example demonstrates a tool response with a comprehensive markdown body showing all formatting options:"
39+
content="This example shows how to use Markdown formatting in tool response content. Note the use of shouldRetainStyles to maintain proper formatting:"
15140
toolResponse={{
15241
shouldRetainStyles: true,
15342
isToggleContentMarkdown: true,
154-
toggleContent: '# Tool response: toolName',
43+
toggleContent: '**Tool response:** data_query_tool',
15544
isSubheadingMarkdown: true,
156-
subheading: '> Thought for 3 seconds',
157-
body: comprehensiveMarkdownBody,
45+
subheading: '> Completed in 0.12 seconds',
46+
body: toolResponseBody,
15847
isBodyMarkdown: true,
15948
cardTitle: (
16049
<Flex

packages/module/patternfly-docs/content/extensions/chatbot/examples/Messages/Messages.md

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -221,12 +221,6 @@ If you are using [model context protocol (MCP)](https://www.redhat.com/en/blog/m
221221

222222
```
223223

224-
### Messages with Markdown in tool response
225-
226-
```ts file="./MessageWithMarkdownToolResponse.tsx"
227-
228-
```
229-
230224
### Messages with deep thinking
231225

232226
You can share details about the "thought process" behind an LLM's response, also known as deep thinking. To display a customizable, expandable card with these details, pass `deepThinking` to `<Message>` and provide a subheading (optional) and content body.
@@ -355,3 +349,35 @@ An attachment dropzone allows users to upload files via drag and drop.
355349
```js file="./FileDropZone.tsx"
356350

357351
```
352+
353+
## Examples with Markdown
354+
355+
The ChatBot supports Markdown formatting in several message components, allowing you to display rich, formatted content. This is particularly useful when you need to include code snippets, lists, emphasis, or other formatted text.
356+
357+
To enable Markdown rendering, use the appropriate Markdown flag prop (such as `isBodyMarkdown`, `isSubheadingMarkdown`, or `isExpandableContentMarkdown`) depending on the component and content you're formatting.
358+
359+
**Important:** When using Markdown in these components, set `shouldRetainStyles: true` to retain the styling of the context the Markdown is used in. This ensures that Markdown content maintains the proper font sizes, colors, and other styling properties of its parent component. For example, Markdown passed into a toggle will retain the ChatBot toggle styling, while Markdown in a card body will maintain the appropriate card body styling. Without this prop, the Markdown may override the contextual styles and appear inconsistent with the rest of the ChatBot interface.
360+
361+
### Tool calls with Markdown
362+
363+
When displaying tool call information, you can use Markdown in the expandable content to provide formatted details about what the tool is processing. This is useful for showing structured data, code snippets, or formatted lists.
364+
365+
```ts file="./MessageWithMarkdownToolCall.tsx"
366+
367+
```
368+
369+
### Deep thinking with Markdown
370+
371+
Deep thinking content can include Markdown formatting in both the subheading and body to better communicate the LLM's reasoning process. This allows you to emphasize key points, structure thought processes with lists, or include other formatting.
372+
373+
```ts file="./MessageWithMarkdownDeepThinking.tsx"
374+
375+
```
376+
377+
### Tool responses with Markdown
378+
379+
Tool response cards support Markdown in multiple areas including the toggle content, subheading, and body. Use `shouldRetainStyles: true` along with the appropriate Markdown flag props to ensure proper formatting and spacing:
380+
381+
```ts file="./MessageWithMarkdownToolResponse.tsx"
382+
383+
```

packages/module/src/MarkdownContent/MarkdownContent.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// ============================================================================
22
// Markdown Content - Shared component for rendering markdown
3-
// With aid from Jean-Claude Van Code
3+
// This was aided by Claude code
44
// ============================================================================
55
import { type FunctionComponent, ReactNode } from 'react';
66
import Markdown, { Options } from 'react-markdown';

0 commit comments

Comments
 (0)