Skip to content

Commit 0c1d4f3

Browse files
authored
feat: add table support to markdown (#705)
1 parent 5bba9f4 commit 0c1d4f3

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

src/components/Markdown.tsx

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,51 @@ const MdHr = styled.hr.withConfig(commonCfg)(({ theme }) => ({
207207
margin: `${theme.spacing.medium}px ${theme.spacing.large}px 0`,
208208
}))
209209

210+
const MdTable = styled.table(({ theme }) => ({
211+
paddingTop: theme.spacing.medium,
212+
borderCollapse: 'separate',
213+
borderSpacing: 0,
214+
tableLayout: 'fixed',
215+
width: '100%',
216+
}))
217+
218+
const MdTh = styled.th(({ theme }) => ({
219+
padding: theme.spacing.small,
220+
height: 40,
221+
textAlign: 'left',
222+
backgroundColor: theme.colors['fill-one'],
223+
border: theme.borders['fill-two'],
224+
borderBottom: theme.borders.default,
225+
// top rounded table corners
226+
'tr:first-child &': {
227+
'&:first-child': { borderTopLeftRadius: theme.borderRadiuses.large },
228+
'&:last-child': { borderTopRightRadius: theme.borderRadiuses.large },
229+
},
230+
// remove inner borders
231+
'&:not(:last-child)': { borderRight: 'none' },
232+
'&:not(:first-child)': { borderLeft: 'none' },
233+
}))
234+
235+
const MdTd = styled.td(({ theme }) => ({
236+
backgroundColor: theme.colors['fill-zero-selected'],
237+
padding: `${theme.spacing.xsmall}px ${theme.spacing.small}px`,
238+
color: theme.colors['text-light'],
239+
height: 40,
240+
border: theme.borders['fill-two'],
241+
borderBottom: theme.borders.default,
242+
borderTop: 'none',
243+
textAlign: 'left',
244+
// bottom row stronger border, rounded corners
245+
'tr:last-child &': {
246+
borderBottom: theme.borders['fill-two'],
247+
'&:first-child': { borderBottomLeftRadius: theme.borderRadiuses.large },
248+
'&:last-child': { borderBottomRightRadius: theme.borderRadiuses.large },
249+
},
250+
// remove inner borders
251+
'&:not(:last-child)': { borderRight: 'none' },
252+
'&:not(:first-child)': { borderLeft: 'none' },
253+
}))
254+
210255
function MarkdownImage({
211256
src,
212257
gitUrl,
@@ -299,6 +344,9 @@ function Markdown({ text, gitUrl, mainBranch }: MarkdownProps) {
299344
code: render({ component: InlineCode }),
300345
pre: render({ component: MarkdownPreformatted }),
301346
hr: render({ component: MdHr }),
347+
th: render({ component: MdTh }),
348+
td: render({ component: MdTd }),
349+
table: render({ component: MdTable }),
302350
}}
303351
>
304352
{text}

src/stories/Markdown.stories.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,19 @@ Thanks goes to all these [wonderful people](https://www.chatwoot.com/docs/contri
205205
206206
207207
*Chatwoot* © 2017-2023, Chatwoot Inc - Released under the MIT License.
208+
209+
---
210+
211+
## Sample Table
212+
213+
| Feature | Supported | Notes |
214+
|--------------|-----------|------------------------------|
215+
| Markdown | Yes | Full GFM support |
216+
| Tables | Yes | With alignment and formatting|
217+
| Images | Yes | Inline and referenced |
218+
| Code blocks | Yes | With syntax highlighting |
219+
| Task Lists | Yes | [x] and [ ] supported |
220+
| HTML | Partial | Some tags are supported |
208221
`
209222

210223
export default {

0 commit comments

Comments
 (0)