Skip to content

Commit 7a0a9ab

Browse files
committed
Restore old-style preformatted block handling for non-Markdown users.
1 parent f02da98 commit 7a0a9ab

File tree

1 file changed

+36
-20
lines changed

1 file changed

+36
-20
lines changed

ts/components/conversation/message/message-content/MessageBody.tsx

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ import { AddNewLines } from '../../AddNewLines';
99
import { Emojify } from '../../Emojify';
1010
import { LinkPreviews } from '../../../../util/linkPreviews';
1111
import { showLinkVisitWarningDialog } from '../../../dialog/SessionConfirm';
12+
import styled from 'styled-components';
13+
import { PubKey } from '../../../../session/types';
14+
import { isUsAnySogsFromCache } from '../../../../session/apis/open_group_api/sogsv3/knownBlindedkeys';
15+
import { getConversationController } from '../../../../session/conversations';
1216

1317
const linkify = LinkifyIt();
1418

@@ -184,6 +188,12 @@ const Linkify = (props: LinkifyProps): JSX.Element => {
184188
return <>{results}</>;
185189
};
186190

191+
const StyledPre = styled.pre`
192+
backdrop-filter: brightness(0.8);
193+
padding: var(--margins-xs);
194+
user-select: text;
195+
`;
196+
187197
export const MessageBody = (props: Props) => {
188198
const { text, disableJumbomoji, disableLinks, isGroup } = props;
189199
const sizeClass: SizeClassType = disableJumbomoji ? 'default' : getEmojiSizeClass(text);
@@ -200,29 +210,35 @@ export const MessageBody = (props: Props) => {
200210
);
201211
}
202212

203-
const onlyEmoji = text.match(/^((\ud83c[\udde6-\uddff]){2}|([\#\*0-9]\u20e3)|(\u00a9|\u00ae|[\u2000-\u3300]|[\u/d83c-\ud83e][\ud000-\udfff])((\ud83c[\udffb-\udfff])?(\ud83e[\uddb0-\uddb3])?(\ufe0f?\u200d([\u2000-\u3300]|[\ud83c-\ud83e][\ud000-\udfff])\ufe0f?)?)*)$/)
213+
if (window.getSettingValue('message-formatting')) {
214+
const onlyEmoji = text.match(/^((\ud83c[\udde6-\uddff]){2}|([\#\*0-9]\u20e3)|(\u00a9|\u00ae|[\u2000-\u3300]|[\u/d83c-\ud83e][\ud000-\udfff])((\ud83c[\udffb-\udfff])?(\ud83e[\uddb0-\uddb3])?(\ufe0f?\u200d([\u2000-\u3300]|[\ud83c-\ud83e][\ud000-\udfff])\ufe0f?)?)*)$/)
204215

205-
if (window.getSettingValue('message-formatting') && !onlyEmoji) {
206-
/* Resolve mentioned ids to user names and mark them up in bold */
207-
const mention = new RegExp(`@${PubKey.regexForPubkeys}`, 'g');
208-
const textWithMentions = text.trim().replace(mention,
209-
(_match, capture) => {
210-
if (isUsAnySogsFromCache(capture)) {
211-
/* It's me. Italicise also. */
212-
return `***@${window.i18n('you')}***`;
213-
}
216+
if (!onlyEmoji) {
217+
/* Resolve mentioned ids to user names and mark them up in bold */
218+
const mention = new RegExp(`@${PubKey.regexForPubkeys}`, 'g');
219+
const textWithMentions = text.trim().replace(mention,
220+
(_match, capture) => {
221+
if (isUsAnySogsFromCache(capture)) {
222+
/* It's me. Italicise also. */
223+
return `***@${window.i18n('you')}***`;
224+
}
214225

215-
/* It's someone else. */
216-
return `**@${getConversationController().get(capture)?.getContactProfileNameOrShortenedPubKey() || PubKey.shorten(capture)}**`;
217-
}
218-
);
226+
/* It's someone else. */
227+
return `**@${getConversationController().get(capture)?.getContactProfileNameOrShortenedPubKey() || PubKey.shorten(capture)}**`;
228+
}
229+
);
219230

220-
/* tslint:disable:react-no-dangerous-html */
221-
return (
222-
<div className="text-selectable"
223-
dangerouslySetInnerHTML={{__html: `<span style="font-size: 1.1em;">${markdown.render(textWithMentions)}</span>`}}
224-
/>
225-
);
231+
/* tslint:disable:react-no-dangerous-html */
232+
return (
233+
<div className="text-selectable"
234+
dangerouslySetInnerHTML={{__html: `<span style="font-size: 1.1em;">${markdown.render(textWithMentions)}</span>`}}
235+
/>
236+
);
237+
}
238+
}
239+
240+
if (text && text.startsWith('```') && text.endsWith('```') && text.length > 6) {
241+
return <StyledPre className="text-selectable">{text.substring(4, text.length - 3)}</StyledPre>;
226242
}
227243

228244
return JsxSelectable(

0 commit comments

Comments
 (0)