Skip to content

Commit

Permalink
feat: enhance markdown parsing to support bold text with spaces\n
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyril Gromoff committed Sep 3, 2024
1 parent 2e46f6c commit 168586c
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion app/components/markdown/markdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,23 @@ const Markdown = ({
return <MarkdownTableRow {...args}/>;
};

// Transform function to allow **TEXTn** Bold. n = space/spaces.
const transformBoldText = (text: string) => {
const REGEX = /\*\*(\S.*?\S?)\s*\*\*/;
const parts = text.split(REGEX);
return parts.map((part, i) => {
if (i % 2 === 0) {
return part;
}
return (
<Text
key={text}
style={style.bold}
>{part.trim()}</Text>
);
});
};

const renderText = ({context, literal}: MarkdownBaseRenderer) => {
const selectable = (managedConfig.copyAndPasteProtection !== 'true') && context.includes('table_cell');
if (context.indexOf('image') !== -1) {
Expand All @@ -513,13 +530,15 @@ const Markdown = ({
styles = concatStyles(styles, {backgroundColor: theme.mentionHighlightBg});
}

const transformedText = transformBoldText(literal);

return (
<Text
testID='markdown_text'
style={styles}
selectable={selectable}
>
{literal}
{transformedText}
</Text>
);
};
Expand Down

0 comments on commit 168586c

Please sign in to comment.