- Tag HTML sugli annunci non vengono visualizzati correttamente... <div>...</div>
This commit is contained in:
@@ -11,12 +11,14 @@ AUTH_MONGODB=1
|
||||
MONGODB_USER=admin
|
||||
MONGODB_PWD=mypwadmin@1A
|
||||
ENABLE_PUSHNOTIFICATION=1
|
||||
URLBASE_APP1=https://localhost
|
||||
PORT_APP1=8080
|
||||
SIGNCODE=SU2134hncaskjdbo231oihJSDNHEI$1@AB
|
||||
HTTPS_LOCALHOST=true
|
||||
DEBUG=0
|
||||
DEBUG=0
|
||||
TESTING_ON=1
|
||||
LOCALE=1
|
||||
PROD=0
|
||||
DELAY_SENDEMAIL=2000
|
||||
VAPI_KEY_SUBJECT=mailto:paolo@freeplanet.app
|
||||
PUBLIC_VAPI_KEY=BDncvMiUZmjaCG2Kr1V9N0_33hOG-AuNSbHSvL24y2dzBiUjAxKm02emx5SeJvz2IGmtRf6YqCgopeQwCwUmZw8
|
||||
@@ -26,6 +28,7 @@ PATH_SERVER_CRT=localhost.crt
|
||||
PATH_SSL_ROOT_PEM=root.pem
|
||||
PATH_SSL_CHAIN_PEM=chain.pem
|
||||
GCM_API_KEY=""
|
||||
PROD=0
|
||||
PROJECT_DESCR_MAIN='__PROJECTS'
|
||||
SECRK=Askb38v23jjDFaoskBOWj92axXCQ
|
||||
SECRTK=prova123prova567ASDADASDAS
|
||||
@@ -36,9 +39,5 @@ FTPSERVER_PORT=21
|
||||
FTPSERVER_USER=ftpusrsrv_
|
||||
FTPSERVER_PWD=ftpmypwd@1A_
|
||||
AUTH_NEW_SITES=123123123
|
||||
DOMAINS=[{"hostname":"riso.app","port":"3000"}]
|
||||
SCRIPTS_DIR=admin_scripts
|
||||
CLOUDFLARE_TOKENS=[{"label":"Paolo.arena77@gmail.com","value":"M9EM309v8WFquJKpYgZCw-TViM2wX6vB3wlK6GD0"},{"label":"gruppomacro.com","value":"bqmzGShoX7WqOBzkXocoECyBkPq3GfqcM5t6VFd8"}]
|
||||
MIAB_HOST=box.lamiaposta.org
|
||||
MIAB_ADMIN_EMAIL=admin@lamiaposta.org
|
||||
MIAB_ADMIN_PASSWORD=passpao1pabox@1A
|
||||
CLOUDFLARE_TOKENS=[{"label":"Paolo.arena77@gmail.com","value":"M9EM309v8WFquJKpYgZCw-TViM2wX6vB3wlK6GD0"},{"label":"gruppomacro.com","value":"bqmzGShoX7WqOBzkXocoECyBkPq3GfqcM5t6VFd8"}]
|
||||
@@ -4735,26 +4735,6 @@ module.exports = {
|
||||
}
|
||||
},
|
||||
|
||||
convertHTMLTagsForTelegram(text) {
|
||||
const htmlTagsMap = {
|
||||
'<font': '<span',
|
||||
'</font>': '</span>',
|
||||
'<i>': '',
|
||||
'</i>': '',
|
||||
'<u>': '',
|
||||
'</u>': '',
|
||||
};
|
||||
|
||||
// Sostituzione dei tag HTML con quelli Markdown supportati da Telegram
|
||||
let convertedText = text;
|
||||
for (const htmlTag in htmlTagsMap) {
|
||||
const regex = new RegExp(htmlTag, 'g');
|
||||
convertedText = convertedText.replace(regex, htmlTagsMap[htmlTag]);
|
||||
}
|
||||
|
||||
return convertedText;
|
||||
},
|
||||
|
||||
removeFontTags(text) {
|
||||
// Rimozione dei tag <font> e </font> dalla stringa di testo
|
||||
const regex = /<font[^>]*>|<\/font>/gi;
|
||||
@@ -5042,22 +5022,92 @@ module.exports = {
|
||||
}
|
||||
},
|
||||
|
||||
convertHTMLTagsToText(input) {
|
||||
convertAndTruncateHTMLForTelegram(text, maxLength = 200, link = '') {
|
||||
const tagMap = {
|
||||
"<ul>": "",
|
||||
"<ol>": "1. ",
|
||||
"<li>": "\n- ",
|
||||
"</ul>": "",
|
||||
"</ol>": "",
|
||||
"</li>": ""
|
||||
"<ul>": "", "<ol>": "", "<li>": "\n• ", "</ul>": "", "</ol>": "", "</li>": "",
|
||||
"<br>": "\n", "<div>": "", "</div>": "\n"
|
||||
};
|
||||
|
||||
// Replace supported HTML tags with their corresponding text representations
|
||||
let output = input.replace(/<ul>|<ol>|<li>|<\/ul>|<\/ol>|<\/li>/g, (match) => {
|
||||
return tagMap[match];
|
||||
// Rimuoviamo specificamente <b>\n</b>
|
||||
text = text.replace(/<b>\n<\/b>/g, '');
|
||||
|
||||
Object.keys(tagMap).forEach(tag => {
|
||||
const replacement = tagMap[tag];
|
||||
text = text.replaceAll(tag, replacement);
|
||||
});
|
||||
|
||||
return output;
|
||||
text = text.split('\n').map(line => line.trim()).join('\n');
|
||||
text = text.replace(/\n{3,}/g, '\n\n').replace(/\n+$/, '').trim();
|
||||
|
||||
if (text.length <= maxLength) {
|
||||
return text;
|
||||
}
|
||||
|
||||
// Tronchiamo il testo
|
||||
let truncated = text.slice(0, maxLength);
|
||||
let openTags = [];
|
||||
|
||||
// Troviamo tutti i tag aperti
|
||||
const regex = /<(\w+)[^>]*>/g;
|
||||
let match;
|
||||
while ((match = regex.exec(truncated)) !== null) {
|
||||
if (!truncated.includes(`</${match[1]}>`, match.index)) {
|
||||
openTags.push(match[1]);
|
||||
}
|
||||
}
|
||||
|
||||
// Rimuoviamo l'ultima parola parziale
|
||||
truncated = truncated.replace(/\S+$/, '');
|
||||
|
||||
let strcontinua = '';
|
||||
if (link) {
|
||||
strcontinua = `<em> (... <a href="${link}">continua sulla App</a>)</em>`;
|
||||
} else {
|
||||
strcontinua = `<em> (... continua sulla App)</em>`;
|
||||
}
|
||||
|
||||
// Aggiungiamo '...' e chiudiamo i tag aperti
|
||||
truncated += strcontinua;
|
||||
while (openTags.length > 0) {
|
||||
truncated += `</${openTags.pop()}>`;
|
||||
}
|
||||
|
||||
return truncated;
|
||||
},
|
||||
|
||||
convertHTMLTagsForTelegram(text) {
|
||||
const tagMap = {
|
||||
"<ul>": "",
|
||||
"<ol>": "",
|
||||
"<li>": "\n• ",
|
||||
"</ul>": "",
|
||||
"</ol>": "",
|
||||
"</li>": "",
|
||||
"<br>": "\n",
|
||||
"<div>": "",
|
||||
"</div>": "\n"
|
||||
};
|
||||
|
||||
// Rimuoviamo i tag vuoti o contenenti solo spazi bianchi o newline
|
||||
text = text.replace(/<(b|i|strong|em)>(\s|\n)*<\/\1>/g, '');
|
||||
|
||||
Object.keys(tagMap).forEach(tag => {
|
||||
const replacement = tagMap[tag];
|
||||
text = text.replaceAll(tag, replacement);
|
||||
});
|
||||
|
||||
// Rimuoviamo gli spazi bianchi all'inizio e alla fine di ogni riga
|
||||
text = text.split('\n').map(line => line.trim()).join('\n');
|
||||
|
||||
// Rimuoviamo le righe vuote consecutive, lasciandone solo una
|
||||
text = text.replace(/\n{3,}/g, '\n\n');
|
||||
|
||||
// Rimuoviamo le righe vuote alla fine del testo
|
||||
text = text.replace(/\n+$/, '');
|
||||
|
||||
text = text.replace(/<b>\n<\/b>/g, '');
|
||||
|
||||
return text.trim();
|
||||
},
|
||||
|
||||
async getAnnuncioForTelegram(myrec, tablerec, mydescr, userorig, nuovo) {
|
||||
@@ -5155,9 +5205,9 @@ module.exports = {
|
||||
if (cat)
|
||||
out += this.addRowTelegram('⭐️', 'Categoria', cat, true);
|
||||
|
||||
let note = this.convertHTMLTagsToText(myrec.note)
|
||||
let descrcontent = this.convertAndTruncateHTMLForTelegram(myrec.note, 500, url)
|
||||
|
||||
let descrcontent = this.firstchars(this.removeLastSpaceAndACapo(note), 500, true, url);
|
||||
// let descrcontent = this.firstchars(this.removeLastSpaceAndACapo(note), 200, true, url);
|
||||
|
||||
descrcontent = this.cleanHtmlForTelegram(descrcontent);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user