-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: markdown serializer (CT-000) (#66)
- Loading branch information
1 parent
2f64c83
commit 5522b54
Showing
8 changed files
with
129 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { serializeToMarkdown } from '@voiceflow/slate-serializer/markdown'; | ||
import React from 'react'; | ||
|
||
import Message from '@/components/Message'; | ||
import type { TextMessageProps } from '@/components/SystemResponse/types'; | ||
|
||
import Markdown from './Markdown'; | ||
|
||
export interface DefaultTextProps { | ||
/** | ||
* text whether in string or slate format | ||
*/ | ||
text: TextMessageProps['text']; | ||
} | ||
|
||
const DefaultText: React.FC<DefaultTextProps> = ({ text }) => { | ||
return ( | ||
<Message from="system"> | ||
<Markdown>{typeof text === 'string' ? text : serializeToMarkdown(text)}</Markdown> | ||
</Message> | ||
); | ||
}; | ||
|
||
export default DefaultText; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { ComponentMeta, ComponentStory } from '@storybook/react'; | ||
|
||
import Image from '.'; | ||
|
||
export default { | ||
title: 'Core/Image', | ||
component: Image, | ||
args: { | ||
image: 'https://source.unsplash.com/featured/248x200', | ||
isRounded: true, | ||
}, | ||
} as ComponentMeta<typeof Image>; | ||
|
||
const Template: ComponentStory<typeof Image> = (args) => <Image {...args} />; | ||
|
||
export const RoundCorners = Template.bind({}); | ||
|
||
export const StraightCorners = Template.bind({}); | ||
StraightCorners.args = { | ||
isRounded: false, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import Markdown, { MarkdownToJSX } from 'markdown-to-jsx'; | ||
|
||
import { styled } from '@/styles'; | ||
|
||
const MarkdownText = styled(Markdown, { | ||
'*': { | ||
whiteSpace: 'pre-wrap', | ||
}, | ||
blockquote: { | ||
marginLeft: 0, | ||
paddingLeft: '$4', | ||
borderLeft: '3px solid $medGrey', | ||
}, | ||
code: { | ||
color: '#e83e8c', | ||
}, | ||
p: { | ||
marginTop: 0, | ||
}, | ||
'img,video': { | ||
maxWidth: '100%', | ||
borderRadius: '$2', | ||
marginBottom: '$4', | ||
}, | ||
'ol,ul': { | ||
paddingInlineStart: '$4', | ||
}, | ||
'> *:last-child': { | ||
marginBottom: 0, | ||
}, | ||
'> *:first-child': { | ||
marginTop: 0, | ||
}, | ||
}); | ||
|
||
const options: MarkdownToJSX.Options = { | ||
forceWrapper: true, | ||
overrides: { | ||
a: ({ children, ...props }) => ( | ||
<a {...props} target="_blank" rel="noopener noreferrer"> | ||
{children} | ||
</a> | ||
), | ||
}, | ||
}; | ||
|
||
MarkdownText.defaultProps = { | ||
options, | ||
}; | ||
|
||
export default MarkdownText; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import Default from './Default'; | ||
|
||
export { default as Markdown } from './Markdown'; | ||
|
||
export default Default; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters