Fix order of nested entities
This commit is contained in:
parent
a9c70efda6
commit
eed849929b
@ -2918,10 +2918,10 @@ export default class ChatBubbles {
|
||||
const html = RichTextProcessor.wrapRichText(webpage.url);
|
||||
const a: HTMLAnchorElement = htmlToDocumentFragment(html).firstElementChild as any;
|
||||
a.classList.add('webpage-name');
|
||||
// const b = document.createElement('b');
|
||||
setInnerHTML(a, RichTextProcessor.wrapEmojiText(webpage.site_name));
|
||||
// a.textContent = '';
|
||||
// a.append(b);
|
||||
const strong = document.createElement('strong');
|
||||
setInnerHTML(strong, RichTextProcessor.wrapEmojiText(webpage.site_name));
|
||||
a.textContent = '';
|
||||
a.append(strong);
|
||||
quoteTextDiv.append(a);
|
||||
t = a;
|
||||
}
|
||||
@ -2929,9 +2929,9 @@ export default class ChatBubbles {
|
||||
if(webpage.rTitle) {
|
||||
let titleDiv = document.createElement('div');
|
||||
titleDiv.classList.add('title');
|
||||
// const b = document.createElement('b');
|
||||
// titleDiv.append(b);
|
||||
setInnerHTML(titleDiv, webpage.rTitle);
|
||||
const strong = document.createElement('strong');
|
||||
setInnerHTML(strong, webpage.rTitle);
|
||||
titleDiv.append(strong);
|
||||
quoteTextDiv.append(titleDiv);
|
||||
t = titleDiv;
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ export const markdownTags: {[type in MarkdownType]: MarkdownTag} = {
|
||||
entityName: 'messageEntityUnderline'
|
||||
},
|
||||
italic: {
|
||||
match: '[style*="italic"], i',
|
||||
match: '[style*="italic"], i, em',
|
||||
entityName: 'messageEntityItalic'
|
||||
},
|
||||
monospace: {
|
||||
@ -34,7 +34,7 @@ export const markdownTags: {[type in MarkdownType]: MarkdownTag} = {
|
||||
entityName: 'messageEntityPre'
|
||||
},
|
||||
strikethrough: {
|
||||
match: '[style*="line-through"], strike',
|
||||
match: '[style*="line-through"], strike, del',
|
||||
entityName: 'messageEntityStrike'
|
||||
},
|
||||
link: {
|
||||
|
@ -37,6 +37,7 @@ export default function getRichValue(field: HTMLElement, withEntities = true) {
|
||||
} */
|
||||
|
||||
RichTextProcessor.combineSameEntities(entities);
|
||||
RichTextProcessor.sortEntities(entities);
|
||||
}
|
||||
|
||||
//console.log('getRichValue:', value, entities);
|
||||
|
@ -403,7 +403,8 @@ namespace RichTextProcessor {
|
||||
});
|
||||
|
||||
currentEntities.push(...filtered);
|
||||
currentEntities.sort((a, b) => a.offset - b.offset);
|
||||
sortEntities(currentEntities);
|
||||
// currentEntities.sort((a, b) => a.offset - b.offset);
|
||||
// currentEntities.sort((a, b) => (a.offset - b.offset) || (a._ === 'messageEntityCaret' && -1));
|
||||
|
||||
if(!IS_EMOJI_SUPPORTED) { // fix splitted emoji. messageEntityTextUrl can split the emoji if starts before its end (e.g. on fe0f)
|
||||
@ -439,6 +440,15 @@ namespace RichTextProcessor {
|
||||
//return entities;
|
||||
}
|
||||
|
||||
export function sortEntities(entities: MessageEntity[]) {
|
||||
entities.sort((a, b) => {
|
||||
return (a.offset - b.offset) || (b.length - a.length);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* * Expecting correctly sorted nested entities (RichTextProcessor.sortEntities)
|
||||
*/
|
||||
export function wrapRichText(text: string, options: Partial<{
|
||||
entities: MessageEntity[],
|
||||
contextSite: string,
|
||||
|
@ -951,8 +951,6 @@ $bubble-beside-button-width: 38px;
|
||||
}
|
||||
|
||||
.title {
|
||||
font-weight: 500 !important;
|
||||
|
||||
&:not(:first-child) {
|
||||
margin-top: 1px;
|
||||
}
|
||||
@ -960,7 +958,6 @@ $bubble-beside-button-width: 38px;
|
||||
|
||||
.webpage-name {
|
||||
font-size: var(--messages-secondary-text-size);
|
||||
font-weight: 500 !important;
|
||||
text-decoration: none;
|
||||
|
||||
@include hover() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user