Skip to content

Commit 695851c

Browse files
committed
fix: exclude custom emoji as copy content but include default emoji
1 parent ab11c5f commit 695851c

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

src/containers/TopicDetail.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,8 @@ class TopicDetail extends Component {
303303
// Only copy text and link.
304304
return content.map(item => {
305305
if (item.type === 0 || item.type === 4) {
306-
// Exclude emoji which type is also `0`.
306+
// The second parameter is used to exclude custom emoji
307+
// as copied content which type is also `0`.
307308
return parseContentWithEmoji(item.infor, false).join('');
308309
}
309310
}).join('');

src/utils/contentParser.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ import {
66
import { DEFAULT_EMOJIS } from '../constants/emojis';
77
import { DEFAULT_EMOJI_ROOT } from '../config';
88

9-
export function parseContentWithEmoji(content, replaceWithImage = true) {
9+
// This method is also used to copy topic content and comment content,
10+
// the second parameter here is used to exclude custom emoji as paste
11+
// content.
12+
export function parseContentWithEmoji(content, includeEmoji = true) {
1013
if (!content) { return ''; }
1114

1215
// var regex = new RegExp(/xyz/, 'i');
@@ -16,10 +19,12 @@ export function parseContentWithEmoji(content, replaceWithImage = true) {
1619
let contentEmojiArray = contentWithEmoji.split('___emojiBoundary___');
1720

1821
return contentEmojiArray.filter(item => item.trim()).map((item, index) => {
19-
if (!replaceWithImage) { return ''; }
20-
2122
// Handle custom emojis.
2223
if (/https?:\/\/.+(?:jpg|png|gif)/.test(item)) {
24+
// Exclude custom emoji because copy something like [mobcent_phiz=..]
25+
// is useless as paste content.
26+
if (!includeEmoji) { return ''; }
27+
2328
return (
2429
<Image
2530
key={index}
@@ -32,6 +37,11 @@ export function parseContentWithEmoji(content, replaceWithImage = true) {
3237
//
3338
// Why use hash map here instead of array? O(1).
3439
if (DEFAULT_EMOJIS.hasOwnProperty(item)) {
40+
// Return custom emoji content directly because emoji content like [阴险]
41+
// could be pasted in text input directly which will also be read in same
42+
// format.
43+
if (!includeEmoji) { return item; }
44+
3545
return (
3646
<Image
3747
key={index}

0 commit comments

Comments
 (0)