Fixed 267U.pre2
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
// test is located in test/extract-mentions
|
||||
export function extractMentions(nodes) {
|
||||
const mentions = [];
|
||||
collectMentions(nodes, mentions);
|
||||
return mentions;
|
||||
}
|
||||
function collectMentions(nodes, mentions) {
|
||||
for(let i = 0; i < nodes.length; i++){
|
||||
const node = nodes[i];
|
||||
if (node.type === "mention" && !isWrappedUserEmojiMention(nodes, i)) {
|
||||
mentions.push(node.props);
|
||||
}
|
||||
if ("children" in node && Array.isArray(node.children)) {
|
||||
collectMentions(node.children, mentions);
|
||||
}
|
||||
}
|
||||
}
|
||||
function isWrappedUserEmojiMention(nodes, index) {
|
||||
const previous = nodes[index - 1];
|
||||
const next = nodes[index + 1];
|
||||
return previous?.type === "text" && next?.type === "text" && previous.props.text.endsWith(":") && next.props.text.startsWith(":");
|
||||
}
|
||||
Reference in New Issue
Block a user