Add extension point for changeset short links.

This commit is contained in:
René Pfeuffer
2020-07-01 10:43:17 +02:00
parent 53993cfee7
commit 8a0e0a3cc5
6 changed files with 90 additions and 31 deletions

View File

@@ -35,14 +35,20 @@ type Props = {
replacements: Replacement[];
};
type PartToReplace = {
start: number;
length: number;
replacement: ReactNode;
const textWrapper = (s: string) => {
const first = s.startsWith(" ") ? <>&nbsp;</> : "";
const last = s.endsWith(" ") ? <>&nbsp;</> : "";
return (
<div>
{first}
{s}
{last}
</div>
);
};
const SplitAndReplace: FC<Props> = ({ text, replacements }) => {
const parts = textSplitAndReplace<ReactNode>(text, replacements, s => <div>{s}</div>);
const parts = textSplitAndReplace<ReactNode>(text, replacements, textWrapper);
if (parts.length === 0) {
return <>{parts[0]}</>;
}