Run prettier

This commit is contained in:
Stefano Pigozzi 2024-10-04 23:28:29 +02:00
parent 321b60649f
commit 1a71917986
No known key found for this signature in database
GPG key ID: 5ADA3868646C3FC0

View file

@ -39,45 +39,39 @@ function _countEntities(p) {
let count = 0;
for (const node of p.childNodes) {
if(node.nodeType === Node.TEXT_NODE) {
if (node.nodeType === Node.TEXT_NODE) {
// Check if there's text between the entities
const text = node.textContent.trim();
if(text !== '') {
if (text !== '') {
// End if there's text
throw false;
}
}
else if(node.tagName === 'BR') {
} else if (node.tagName === 'BR') {
// Ignore <br />
}
else if(node.tagName === 'A') {
} else if (node.tagName === 'A') {
// Check if the link has text
const linkText = node.textContent.trim();
if(!linkText) {
if (!linkText) {
// End if there's a link without text
throw false;
}
else if(!(
linkText.startsWith('#') || linkText.startsWith('@')
)) {
} else if (!(linkText.startsWith('#') || linkText.startsWith('@'))) {
// End if there's a link that's not a mention or an hashtag
throw false;
}
else {
} else {
// This is an entity
count++;
}
} else if(node.tagName === 'SPAN') {
} else if (node.tagName === 'SPAN') {
// If this is a span, we might need to go deeper
count += _countEntities(node)
count += _countEntities(node);
} else {
// There's something else here we should not touch
throw false;
}
}
return count
return count;
}
function _enhanceContent(content, opts = {}) {
@ -277,10 +271,10 @@ function _enhanceContent(content, opts = {}) {
let entitiesCount = 0;
try {
entitiesCount = _countEntities(p)
} catch(e) {
if(e === false) {
return false
entitiesCount = _countEntities(p);
} catch (e) {
if (e === false) {
return false;
}
throw e;
}