This commit is contained in:
hackrobot
2024-05-13 17:54:47 +08:00
parent fa5c696c53
commit 05e3dbb678

View File

@@ -49,19 +49,27 @@ renderer.image = function (href, title, text) {
renderer.list = function (body, ordered, start) {
console.log("body,ordered, start", body, ordered, start);
const type = ordered ? "ol" : "ul";
console.log("type===>",type)
console.log("type===>", type);
const startatt = ordered && start !== 1 ? ' start="' + start + '"' : "";
// 正则取值
const regex = /▫️\s*(.*?)<br\/?>/g;
// const regex = /▫️\s*(.*?)<br\/?>/g;
const regex = /([^<]*)<br\/?>/g;
const input = body;
const matches = [...input.matchAll(regex)];
const texts = matches.map((match) => match[1]);
console.log(texts); // 输出: ["测试111", "测试222", "if"]
console.log("texts===>", texts); // 输出: ["测试111", "测试222", "if"]
// 0⃣',
const numbers = [ '1', '2', '3', '4', '5', '6', '7', '8', '9', '🔟'];
const string= texts.map((value,index) => `<div>${type==='ol'?numbers[index]:'▫️ '}${value}</div>`).join('');
const numbers = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "🔟"];
const string = texts
.map((value, index) => {
console.log("value, index==>", value, index);
// ${ value.indexOf("▫️ ") === -1 ? '<br/><span>111</sapn>' : ""}
return value.indexOf("▫️ ") !== -1 ?`<div>${type === "ol" ? numbers[index] : "▫️ "}${value.replace('▫️ ','')} </div>`:`<div style="white-space:pre;">\t${value}</div>`;
})
.join("");
// return `1⃣`
return `${string}`
console.log("string===>", string);
return `${string}`;
};
// 无序列表 ▫️
@@ -92,6 +100,11 @@ renderer.hr = function () {
return "<br/><br/>";
};
// 内联样式,使用直角引号「」
renderer.codespan = function (text) {
return `${text}`;
};
// 引用符号
renderer.blockquote = function (quote) {
console.log("quote", quote);
@@ -102,7 +115,8 @@ renderer.blockquote = function (quote) {
var content = match[1]; // 获取第一个捕获组的内容
console.log(content);
}
return `👉<span class="blockquote">${content}</span>`;
// <pre></pre>
return `<span style="white-space:pre;" class="blockquote">\t👉${content}</span> `;
};
marked.use({ renderer });
@@ -111,17 +125,18 @@ marked.use({ renderer });
const markTextStr = marked(
`
## 标题
>测试
随便测试普通的文本,要不要来个内敛的字符串
> 测试引用桔子的样子
随便测试普通的文本,要不要来个\`内敛\`的字符串
---
- 无序列表1
- 无序列表2
- [ ] 任务列表
- [x] 完成任务
个人有看看
- 无序列表2
- [ ] 任务列表
- [x] 完成任务
1. 测试111
2. 测试222
恶魔女哪里的请
2. 你好啊
3. iefw4t43t43t
`
);
// export default class Index extends Component {