import React from 'react'; import styled from 'styled-components'; import { RenderTextCallbackType } from '../../types/Util'; import { SizeClassType } from '../../util/emoji'; import { AddNewLines } from '../conversation/AddNewLines'; import { Emojify } from '../conversation/Emojify'; import { MessageBody, renderTextDefault, } from '../conversation/message/message-content/MessageBody'; const renderNewLines: RenderTextCallbackType = ({ text, key, isGroup }) => ( ); const SnippetHighlight = styled.span` font-weight: bold; color: var(--text-primary-color); `; const renderEmoji = ({ text, key, sizeClass, renderNonEmoji, isGroup, }: { text: string; key: number; isGroup: boolean; sizeClass: SizeClassType; renderNonEmoji: RenderTextCallbackType; }) => ( ); export const MessageBodyHighlight = (props: { text: string; isGroup: boolean }) => { const { text, isGroup } = props; const results: Array = []; // this is matching what sqlite fts5 is giving us back const FIND_BEGIN_END = /<>(.+?)<>/g; let match = FIND_BEGIN_END.exec(text); let last = 0; let count = 1; if (!match) { return ( ); } const sizeClass = 'default'; while (match) { if (last < match.index) { const beforeText = text.slice(last, match.index); results.push( renderEmoji({ text: beforeText, sizeClass, key: count++, renderNonEmoji: renderNewLines, isGroup, }) ); } const [, toHighlight] = match; results.push( {renderEmoji({ text: toHighlight, sizeClass, key: count++, renderNonEmoji: renderNewLines, isGroup, })} ); // @ts-ignore last = FIND_BEGIN_END.lastIndex; match = FIND_BEGIN_END.exec(text); } if (last < text.length) { results.push( renderEmoji({ text: text.slice(last), sizeClass, key: count++, renderNonEmoji: renderNewLines, isGroup, }) ); } return <>{results}; };