Код вставлен в ноду: очищает от тегов, готовит text_for_rewrite.
title
{{
String($json.title || '')
.replace(/(^|\s)@[\w_]+/g, ' ') // @каналы
.replace(/\s*[-—–:|]\s*(telegram|телеграм)\b.*$/i, '')// «… | Telegram …»
.replace(/\s+/g, ' ')
.trim()
}}
raw
{{ String($json.raw || $json.content || $json.description || $json.title || '')
.replace(/<style[^>]*>.*?<\/style>|<script[^>]*>.*?<\/script>|<[^>]+>/gis,' ')
.replace(/\s+/g,' ')
.trim() }}
const htmlToText = (s='') => String(s)
.replace(/<br\s*\/?>/gi, '\n')
.replace(/<\/(p|li|div|h\d|tr)>/gi, '\n')
.replace(/<li[^>]*>/gi, '• ')
.replace(/<style[^>]*>.*?<\/style>/gis, ' ')
.replace(/<script[^>]*>.*?<\/script>/gis, ' ')
.replace(/<[^>]+>/g, ' ')
.replace(/\u00A0/g, ' ')
.replace(/[ \t]+\n/g, '\n')
.replace(/\n{3,}/g, '\n\n')
.replace(/[ \t]{2,}/g, ' ')
.trim();
const stripTgHeader = (s='') => {
const lines = String(s).split(/\r?\n/);
let i = 0;
while (i < Math.min(lines.length, 6)) {
const L = lines[i].trim();
if (L === '') { i++; continue; }
const hdr = /https?:\/\/t\.me\/\S+/i.test(L)
|| /^@[\w_]+/.test(L)
|| /\b(telegram|телеграм)\b/i.test(L)
|| (/^[\w\s\/|:—–\-+&_.,()]+$/u.test(L) && !/[.!?…]$/.test(L));
if (hdr) { i++; continue; }
break;
}
return lines.slice(i).join('\n');
};
const src = prefer(
self.raw, self.content, self.description, self.summary, self['content:encoded'],
fromPick.raw, fromPick.content, fromPick.description, fromPick.summary,
self.title
);
let body = stripTgHeader(src);
body = htmlToText(body)
.replace(/https?:\/\/t\.me\/\S+/gi, '')
.replace(/(^|\s)@[\w_]+/g, ' ')
.trim();
return body || (self.title || fromPick.title || '');
})() }}
link
{{$json.link || $json.guid || ''}}
text_for_rewrite
{{
(() => {
const s = ($json.raw || $json.content || $json.description || $json.title || '').toString();
return s
.replace(/<style[^>]*>.*?<\/style>/gis, ' ')
.replace(/<script[^>]*>.*?<\/script>/gis, ' ')
.replace(/<[^>]+>/g, ' ') // HTML → текст
.replace(/https?:\/\/t\.me\/\S+/gi, ' ') // только телеграм-ссылки
.replace(/(^|\s)@[\w_]+/g, ' ') // @каналы
.replace(/\s+/g, ' ')
.trim();
})()
}}
__test_mode
{{ false }}