This commit is contained in:
hackrobot
2024-08-12 13:57:51 +08:00
parent 38767a6b3e
commit 64ee2030ed

View File

@@ -61,7 +61,6 @@ const createDecoratedTitleHTML = (text: any) => {
return `<div>${topBorder}<br/>${middleLine}<br/>${bottomBorder}</div>`; return `<div>${topBorder}<br/>${middleLine}<br/>${bottomBorder}</div>`;
// return `<div>${topBorder}<br/>${middleLine}<br/>${bottomBorder}</div><br/>`; // return `<div>${topBorder}<br/>${middleLine}<br/>${bottomBorder}</div><br/>`;
}; };
marked.setOptions({ marked.setOptions({
@@ -101,49 +100,61 @@ renderer.image = function (href, title, text) {
return `<img width="300px" src="${href}" alt="${text}"/>`; return `<img width="300px" src="${href}" alt="${text}"/>`;
}; };
// let listSinbal="▫️ "
let listSinbal = '🔸'; let listSinbal = '🔸';
// 有序列表 // 有序列表
renderer.list = function (body, ordered, start) { renderer.list = function (body, ordered, start) {
// console.log("body,ordered, start", body, ordered, start);
const type = ordered ? 'ol' : 'ul'; const type = ordered ? 'ol' : 'ul';
// console.log("type===>", type);
const startatt = ordered && start !== 1 ? ' start="' + start + '"' : ''; const startatt = ordered && start !== 1 ? ' start="' + start + '"' : '';
// 正则取值
// const regex = /▫️\s*(.*?)<br\/?>/g;
const regex = /([^<]*)<br\/?>/g;
const input = body;
const matches = [...input.matchAll(regex)];
const texts = matches.map((match) => match[1]);
// 不含▫️的元素数量
// const diffcCount=texts.length-texts.filter(item => item.includes('▫️')).length;
// console.log("texts===>", texts); // 输出: ["测试111", "测试222", "if"]
const newArray = texts.filter((item) => item.includes(listSinbal));
// 0⃣',
const numbers = ['1⃣', '2⃣', '3⃣', '4⃣', '5⃣', '6⃣', '7⃣', '8⃣', '9⃣', '🔟'];
// 移除 `<div>` 和 `</div>` 标签
const cleanedBody = body.replace(/<\/?div>/g, '');
// 正则表达式匹配每个以 <br/> 结尾的列表项
const regex = /([^<]*)<br\/?>/g;
const input = cleanedBody;
// 正则取值
// // const regex = /▫️\s*(.*?)<br\/?>/g;
// const regex = /([^<]*)<br\/?>/g;
// const input = body;
// console.log('input--', input);
const matches = [...input.matchAll(regex)];
console.log('matches--', matches);
const texts = matches.map((match) => match[1]);
console.log('texts===>', texts); // 输出: ["测试111", "测试222", "if"]
const newArray = texts.filter((item) => item.includes(listSinbal));
const numbers = ['1⃣', '2⃣', '3⃣', '4⃣', '5⃣', '6⃣', '7⃣', '8⃣', '9⃣', '🔟'];
// ┊ │ ╏
const string = texts const string = texts
.map((value, index) => { .map((value, index) => {
// console.log("value, index==>", value, index);
// ${ value.indexOf("▫️ ") === -1 ? '<br/><span>111</sapn>' : ""}
return value.indexOf(listSinbal) !== -1 return value.indexOf(listSinbal) !== -1
? `<div>${ ? `<div>${
type === 'ol' ? numbers[newArray.indexOf(value)] : listSinbal type === 'ol' ? numbers[newArray.indexOf(value)] : listSinbal
}${value.replace(listSinbal, '')} </div>` }${value.replace(listSinbal, '')} </div>`
: `<div style="white-space:pre;">\t${value}</div>`; : // : `<div style="white-space:pre;">\t${value}</div>`;
`<div style="white-space:pre;">&#8239;&#8239;&#8239;&#8239;&#8239;&#8239;&#8239;&#8239;&#8239;┊ ${value}</div>`;
}) })
.join(''); .join('');
// return `1⃣`
// console.log("string===>", string);
return `${string}`; return `${string}`;
}; };
// 示例输入
const input = `🔸11<br/>🔸22<br/><br/>🔸33`;
console.log(renderer.list(input, false, 1));
// 无序列表 ▫️ // 无序列表 ▫️
renderer.listitem = function (text, task, checked) { renderer.listitem = function (text, task, checked) {
// return `<li>${text}</li>\n`; // return `<li>${text}</li>\n`;
return `${listSinbal}${text}<br/>`; return `${listSinbal}${text}<br/>`;
return `${listSinbal}${text}\n`;
// return `${listSinbal}${text}\n`;
// return `${text}<br/>`; // return `${text}<br/>`;
}; };
@@ -336,7 +347,7 @@ const Index = () => {
// │ 🆔 hackrobot // │ 🆔 hackrobot
// ╰────────────────╯<br>💬 随时欢迎聊天`; // ╰────────────────╯<br>💬 随时欢迎聊天`;
let contactMe = `\n💬 后台发送关键词: 加群`; let contactMe = `<br><br>💬 欢迎交流<br>后台私信发送关键词: 加群`;
// setmarkText(value); // setmarkText(value);
setmarkText(value + contactMe); setmarkText(value + contactMe);