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 html = RichTextProcessor.wrapRichText(webpage.url);
|
||||||
const a: HTMLAnchorElement = htmlToDocumentFragment(html).firstElementChild as any;
|
const a: HTMLAnchorElement = htmlToDocumentFragment(html).firstElementChild as any;
|
||||||
a.classList.add('webpage-name');
|
a.classList.add('webpage-name');
|
||||||
// const b = document.createElement('b');
|
const strong = document.createElement('strong');
|
||||||
setInnerHTML(a, RichTextProcessor.wrapEmojiText(webpage.site_name));
|
setInnerHTML(strong, RichTextProcessor.wrapEmojiText(webpage.site_name));
|
||||||
// a.textContent = '';
|
a.textContent = '';
|
||||||
// a.append(b);
|
a.append(strong);
|
||||||
quoteTextDiv.append(a);
|
quoteTextDiv.append(a);
|
||||||
t = a;
|
t = a;
|
||||||
}
|
}
|
||||||
@ -2929,9 +2929,9 @@ export default class ChatBubbles {
|
|||||||
if(webpage.rTitle) {
|
if(webpage.rTitle) {
|
||||||
let titleDiv = document.createElement('div');
|
let titleDiv = document.createElement('div');
|
||||||
titleDiv.classList.add('title');
|
titleDiv.classList.add('title');
|
||||||
// const b = document.createElement('b');
|
const strong = document.createElement('strong');
|
||||||
// titleDiv.append(b);
|
setInnerHTML(strong, webpage.rTitle);
|
||||||
setInnerHTML(titleDiv, webpage.rTitle);
|
titleDiv.append(strong);
|
||||||
quoteTextDiv.append(titleDiv);
|
quoteTextDiv.append(titleDiv);
|
||||||
t = titleDiv;
|
t = titleDiv;
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@ export const markdownTags: {[type in MarkdownType]: MarkdownTag} = {
|
|||||||
entityName: 'messageEntityUnderline'
|
entityName: 'messageEntityUnderline'
|
||||||
},
|
},
|
||||||
italic: {
|
italic: {
|
||||||
match: '[style*="italic"], i',
|
match: '[style*="italic"], i, em',
|
||||||
entityName: 'messageEntityItalic'
|
entityName: 'messageEntityItalic'
|
||||||
},
|
},
|
||||||
monospace: {
|
monospace: {
|
||||||
@ -34,7 +34,7 @@ export const markdownTags: {[type in MarkdownType]: MarkdownTag} = {
|
|||||||
entityName: 'messageEntityPre'
|
entityName: 'messageEntityPre'
|
||||||
},
|
},
|
||||||
strikethrough: {
|
strikethrough: {
|
||||||
match: '[style*="line-through"], strike',
|
match: '[style*="line-through"], strike, del',
|
||||||
entityName: 'messageEntityStrike'
|
entityName: 'messageEntityStrike'
|
||||||
},
|
},
|
||||||
link: {
|
link: {
|
||||||
|
@ -37,6 +37,7 @@ export default function getRichValue(field: HTMLElement, withEntities = true) {
|
|||||||
} */
|
} */
|
||||||
|
|
||||||
RichTextProcessor.combineSameEntities(entities);
|
RichTextProcessor.combineSameEntities(entities);
|
||||||
|
RichTextProcessor.sortEntities(entities);
|
||||||
}
|
}
|
||||||
|
|
||||||
//console.log('getRichValue:', value, entities);
|
//console.log('getRichValue:', value, entities);
|
||||||
|
@ -403,7 +403,8 @@ namespace RichTextProcessor {
|
|||||||
});
|
});
|
||||||
|
|
||||||
currentEntities.push(...filtered);
|
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));
|
// 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)
|
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;
|
//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<{
|
export function wrapRichText(text: string, options: Partial<{
|
||||||
entities: MessageEntity[],
|
entities: MessageEntity[],
|
||||||
contextSite: string,
|
contextSite: string,
|
||||||
|
@ -951,8 +951,6 @@ $bubble-beside-button-width: 38px;
|
|||||||
}
|
}
|
||||||
|
|
||||||
.title {
|
.title {
|
||||||
font-weight: 500 !important;
|
|
||||||
|
|
||||||
&:not(:first-child) {
|
&:not(:first-child) {
|
||||||
margin-top: 1px;
|
margin-top: 1px;
|
||||||
}
|
}
|
||||||
@ -960,7 +958,6 @@ $bubble-beside-button-width: 38px;
|
|||||||
|
|
||||||
.webpage-name {
|
.webpage-name {
|
||||||
font-size: var(--messages-secondary-text-size);
|
font-size: var(--messages-secondary-text-size);
|
||||||
font-weight: 500 !important;
|
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
|
|
||||||
@include hover() {
|
@include hover() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user