You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
1.6 KiB

1 week ago
// 针对 richText 字段提取页面文本(Axure data.js 的正文载体)
import fs from 'node:fs';
const raw = fs.readFileSync('e:/code/crm-backend-matt/.scratch/lanhu-latest/team-page-data.js', 'utf8');
const start = raw.indexOf('{');
let depth = 0, end = -1, inStr = false, esc = false;
for (let i = start; i < raw.length; i++) {
const c = raw[i];
if (esc) { esc = false; continue; }
if (c === '\\') { esc = true; continue; }
if (c === '"') inStr = !inStr;
if (inStr) continue;
if (c === '{') depth++;
else if (c === '}') { depth--; if (depth === 0) { end = i; break; } }
}
const data = JSON.parse(raw.slice(start, end + 1));
// 1. 找所有 richText 字段
const rich = [];
function findRich(obj, path) {
if (obj === null || typeof obj !== 'object') return;
if (Array.isArray(obj)) { obj.forEach((v, i) => findRich(v, path)); return; }
for (const [k, v] of Object.entries(obj)) {
if (k === 'richText' && typeof v === 'string') rich.push({ path, html: v });
else findRich(v, path);
}
}
findRich(data, '$');
console.log('richText fields:', rich.length);
// 2. HTML → 纯文本
function html2text(h) {
return h.replace(/<p[^>]*>/g, '\n').replace(/<\/p>/g, '').replace(/<br\s*\/?>/g, '\n')
.replace(/<[^>]+>/g, '').replace(/&nbsp;/g, ' ').replace(/&amp;/g, '&').replace(/&lt;/g, '<').replace(/&gt;/g, '>')
.split('\n').map(s => s.trim()).filter(Boolean).join(' | ');
}
const lines = rich.map(r => html2text(r.html)).filter(Boolean);
const uniq = [...new Set(lines)];
console.log('unique text lines:', uniq.length);
console.log('===== 团队成员页全部文本 =====');
uniq.forEach((l, i) => console.log(String(i + 1).padStart(3), l));