Skip to content

Commit c61f2f7

Browse files
authored
task: implement DisplayMarkdown (#279)
1 parent 4b7c103 commit c61f2f7

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

demo/tables.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,12 @@ class User(BaseModel):
9696
name: str = Field(title='Name')
9797
dob: date = Field(title='Date of Birth')
9898
enabled: bool | None = None
99+
status_markdown: str | None = Field(default=None, title='Status')
99100

100101

101102
users: list[User] = [
102-
User(id=1, name='John', dob=date(1990, 1, 1), enabled=True),
103-
User(id=2, name='Jane', dob=date(1991, 1, 1), enabled=False),
103+
User(id=1, name='John', dob=date(1990, 1, 1), enabled=True, status_markdown='**Active**'),
104+
User(id=2, name='Jane', dob=date(1991, 1, 1), enabled=False, status_markdown='*Inactive*'),
104105
User(id=3, name='Jack', dob=date(1992, 1, 1)),
105106
]
106107

@@ -115,6 +116,7 @@ def users_view() -> list[AnyComponent]:
115116
DisplayLookup(field='name', on_click=GoToEvent(url='/table/users/{id}/')),
116117
DisplayLookup(field='dob', mode=DisplayMode.date),
117118
DisplayLookup(field='enabled'),
119+
DisplayLookup(field='status_markdown', mode=DisplayMode.markdown),
118120
],
119121
),
120122
title='Users',

src/npm-fastui/src/components/display.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { AnyComp } from '.'
99

1010
import { JsonComp } from './Json'
1111
import { LinkRender } from './link'
12+
import MarkdownComp from './MarkdownLazy'
1213

1314
export const DisplayComp: FC<Display> = (props) => {
1415
const CustomRenderComp = useCustomRender(props)
@@ -206,8 +207,7 @@ const DisplayMarkdown: FC<{ value: JSONPrimitive }> = ({ value }) => {
206207
if (value === null) {
207208
return <DisplayNull />
208209
} else {
209-
// TODO
210-
return <>{value.toString()}</>
210+
return <MarkdownComp text={value.toString()} type="Markdown" />
211211
}
212212
}
213213

0 commit comments

Comments
 (0)