Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: enhance markdown parsing to support bold text with spaces\n #8200

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading