let processedText = text;
let offsetShift = 0;
entities.forEach(entity => {
const { offset, length, type, url, user } = entity;
const startIndex = offset + offsetShift;
const endIndex = startIndex + length;
switch (type) {
// case 'hashtag':
// processedText = `${processedText.slice(0, startIndex)}<b>${processedText.slice(startIndex, endIndex)}</b>${processedText.slice(endIndex)}`;
// offsetShift += 7; // Length of added HTML tags <b> and </>
// break;
case 'bold':
processedText =h, type, url, user } = entity;
const startIndex = offset + offsetShift;
const endIndex = startIndex + length
offsetShift += 7; // Length of added HTML tags <b> and </>
break;
case 'italic':
processedText =ength, type, url, user } = entity;
const startIndex = offset + offsetShift;
const endIndex = startIndex + le
offsetShift += 7; // Length of added HTML tags <i> and </>
break;
case 'underline':
processedText =th, type, url, user } = entity;
const startIndex = offset + offsetShift;
const endIndex = startIndex + lengt
offsetShift += 7; // Length of added HTML tags <u> and </>
break;
case 'strikethrough':
processedText =type, url, user } = entity;
const startIndex = offset + offsetShift;
const endIndex = startIndex + length;
offsetShift += 7; // Length of added HTML tags <s> and </>
break;
case 'text_link':
processedText =th, type, url, user } = entity;
const startIndex = offset + offsetShift;
const endIndex = startIndex + length;
sw
offsetShift += 16 + url.length; // Length of added HTML tags <a href=""></a>
break;
case 'text_mention':
processedText = = entity;
const startIndex = offset + offsetShift;
const endIndex = startIndex + length;
switch (type) {
// case 'has
offsetShift += 25 + user.id.toString().length; // Length of added HTML tags <a href="tg://user?id="></a>
break;
case 'phone_number':
processedText =rtIndex = offset + offsetShift;
const endIndex = startIndex + length;
switch (type) {
// case 'hashtag':
// processedText = `${processe
offsetShift += 18 + processedText.slice(startIndex, endIndex).length; // Length of added HTML tags <a href="tel:"></a>
break;
default:
break;
}
});
return processedText;
}
Вот что он дают)
Обсуждают сегодня