Skip to content

Commit

Permalink
fix(ui): Escape problematic markdown characters
Browse files Browse the repository at this point in the history
Signed-off-by: stevenbjohnson <[email protected]>
  • Loading branch information
stevenbjohnson committed Nov 23, 2024
1 parent e19d707 commit 3b3551e
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions ui/src/workflows/components/workflows-row/workflows-row.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ export function WorkflowsRow(props: WorkflowsRowProps) {
const [hideDrawer, setHideDrawer] = useState(true);
const wf = props.workflow;
// title + description vars
const title = (wf.metadata.annotations?.[ANNOTATION_TITLE] && `${FormatMarkdown(wf.metadata.annotations[ANNOTATION_TITLE])}`) ?? wf.metadata.name;
const description = (wf.metadata.annotations?.[ANNOTATION_DESCRIPTION] && `\n${FormatMarkdown(wf.metadata.annotations[ANNOTATION_DESCRIPTION])}`) || '';
const title = (wf.metadata.annotations?.[ANNOTATION_TITLE] && `${EscapeInvalidMarkdown(wf.metadata.annotations[ANNOTATION_TITLE])}`) ?? wf.metadata.name;
const description = (wf.metadata.annotations?.[ANNOTATION_DESCRIPTION] && `\n${EscapeInvalidMarkdown(wf.metadata.annotations[ANNOTATION_DESCRIPTION])}`) || '';
const hasAnnotation = title !== wf.metadata.name && description !== '';
const markdown = `${title}${description}`;

Expand Down Expand Up @@ -132,6 +132,6 @@ function SuspenseReactMarkdownGfm(props: {markdown: string}) {
);
}

function FormatMarkdown(markdown: string) {
return markdown.replace(/\n|#|`{3}|>/g, ' ').trim();
function EscapeInvalidMarkdown(markdown: string) {
return markdown.replace(/\n/g, ' ').trim().replace(/`{3}/g, '').replace(/^#/g, '\\#').replace(/^>/g, '\\>');
}

0 comments on commit 3b3551e

Please sign in to comment.