Skip to content

Commit

Permalink
fix(#208): display description as markdown
Browse files Browse the repository at this point in the history
Also refactor all other markdown descriptions to use this new component.
  • Loading branch information
marisademeglio committed Apr 16, 2024
1 parent 4ba44cc commit 47cf3c0
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 50 deletions.
5 changes: 4 additions & 1 deletion src/renderer/components/Fields/CustomField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { CustomFieldDocumentation } from './CustomFieldDocumentation'
import { ScriptItemBase, TypeChoice, ValueChoice } from 'shared/types'
import { useEffect, useState } from 'react'
import { ControlledInput } from './ControlledInput'
import { MarkdownDescription } from './MarkdownDescription'

export function CustomField({
item,
Expand Down Expand Up @@ -163,7 +164,9 @@ export function CustomField({
}
style={{ margin: 0 }}
>
{selectedOptionDescription}
<MarkdownDescription>
{selectedOptionDescription}
</MarkdownDescription>
</p>
)
})}
Expand Down
28 changes: 2 additions & 26 deletions src/renderer/components/Fields/CustomFieldDocumentation.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import remarkGfm from 'remark-gfm'
import { externalLinkClick } from 'renderer/utils'
import Markdown from 'react-markdown'
import {MarkdownDescription} from './MarkdownDescription'
const { App } = window

export function CustomFieldDocumentation({ datatypes }) {
Expand All @@ -27,29 +25,7 @@ export function CustomFieldDocumentation({ datatypes }) {
{d.summary}
<div className="details">
{d.details ? (
<Markdown
remarkPlugins={[remarkGfm]}
components={{
// override the rendering of link elements with a link element that opens in an external browser
a: (props) => {
return (
<a
href={props.href}
onClick={(e) =>
externalLinkClick(
e,
App
)
}
>
{props.children}
</a>
)
},
}}
>
{d.details}
</Markdown>
<MarkdownDescription>{d.details}</MarkdownDescription>
) : (
''
)}
Expand Down
27 changes: 27 additions & 0 deletions src/renderer/components/Fields/MarkdownDescription.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import remarkGfm from 'remark-gfm'
import Markdown from 'react-markdown'
import { externalLinkClick } from 'renderer/utils'
const { App } = window

export function MarkdownDescription(props) {
return (
<Markdown
remarkPlugins={[remarkGfm]}
components={{
// override the rendering of link elements with a link element that opens in an external browser
a: (props) => {
return (
<a
href={props.href}
onClick={(e) => externalLinkClick(e, App)}
>
{props.children}
</a>
)
},
}}
>
{props.children}
</Markdown>
)
}
25 changes: 2 additions & 23 deletions src/renderer/components/JobDetailsPane/Results.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { Job } from 'shared/types'
import { FileLink } from '../FileLink'
import remarkGfm from 'remark-gfm'
import { externalLinkClick } from 'renderer/utils'
import Markdown from 'react-markdown'
import { MarkdownDescription } from '../Fields/MarkdownDescription'
const { App } = window

export function Results({ job }: { job: Job }) {
Expand All @@ -14,26 +12,7 @@ export function Results({ job }: { job: Job }) {
<span className="nicename">{item.nicename}</span>
</FileLink>
<div className="description">
<Markdown
remarkPlugins={[remarkGfm]}
components={{
// override the rendering of link elements with a link element that opens in an external browser
a: (props) => {
return (
<a
href={props.href}
onClick={(e) =>
externalLinkClick(e, App)
}
>
{props.children}
</a>
)
},
}}
>
{item.desc}
</Markdown>
<MarkdownDescription>{item.desc}</MarkdownDescription>
</div>
</li>
))}
Expand Down

0 comments on commit 47cf3c0

Please sign in to comment.