Skip to content

Commit fd1ccd5

Browse files
authored
feat: add blockquote support for preview in message (#2929)
* feat: add blockquote support for preview in message * fix: lint issues * fix: lint issues * fix: lint issues
1 parent 10b8de6 commit fd1ccd5

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

package/src/components/Message/MessageSimple/utils/generateMarkdownText.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ describe('generateMarkdownText', () => {
1515
1616
],
1717
['Hi @getstream.io getstream.io', 'Hi @getstream.io [getstream.io](http://getstream.io)'],
18-
['Hi <Stream>', 'Hi \\<Stream\\>'],
18+
['Hi <Stream>', 'Hi \\<Stream>'],
1919
])('Returns the generated markdown text for %p and %p', (text, expected) => {
2020
const result = generateMarkdownText(text);
2121
expect(result).toBe(expected);

package/src/components/Message/MessageSimple/utils/generateMarkdownText.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export const generateMarkdownText = (text?: string) => {
3434
}
3535

3636
// Escape the " and ' characters, except in code blocks where we deem this allowed.
37-
resultText = resultText.replace(/(```[\s\S]*?```|`.*?`)|[<"'>]/g, (match, code) => {
37+
resultText = resultText.replace(/(```[\s\S]*?```|`.*?`)|[<"']/g, (match, code) => {
3838
if (code) return code;
3939
return `\\${match}`;
4040
});

package/src/components/Message/MessageSimple/utils/renderText.tsx

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,23 @@ export const renderText = <
200200
color: colors.accent_blue,
201201
...markdownStyles?.autolink,
202202
},
203+
blockQuoteSection: {
204+
...defaultMarkdownStyles.blockQuoteSection,
205+
flexDirection: 'row',
206+
padding: 8,
207+
...markdownStyles?.blockQuoteSection,
208+
},
209+
blockQuoteSectionBar: {
210+
...defaultMarkdownStyles.blockQuoteSectionBar,
211+
backgroundColor: colors.grey_gainsboro,
212+
marginRight: 8,
213+
width: 2,
214+
...markdownStyles?.blockQuoteSectionBar,
215+
},
216+
blockQuoteText: {
217+
...defaultMarkdownStyles.blockQuoteText,
218+
...markdownStyles?.blockQuoteText,
219+
},
203220
codeBlock: {
204221
...defaultMarkdownStyles.codeBlock,
205222
backgroundColor: colors.code_block,
@@ -398,7 +415,18 @@ export const renderText = <
398415
</MarkdownReactiveScrollView>
399416
);
400417

418+
const blockQuoteReact: ReactNodeOutput = (node, output, state) => (
419+
<View key={state.key} style={styles.blockQuoteSection}>
420+
<View style={styles.blockQuoteSectionBar} />
421+
<View style={styles.blockQuoteText}>{output(node.content, state)}</View>
422+
</View>
423+
);
424+
401425
const customRules = {
426+
blockQuote: {
427+
react: blockQuoteReact,
428+
},
429+
codeBlock: { react: codeBlockReact },
402430
// do not render images, we will scrape them out of the message and show on attachment card component
403431
image: { match: () => null },
404432
link: { react: linkReact },
@@ -418,7 +446,6 @@ export const renderText = <
418446
},
419447
}
420448
: {}),
421-
codeBlock: { react: codeBlockReact },
422449
table: { react: tableReact },
423450
};
424451

0 commit comments

Comments
 (0)