-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
发布到知乎加粗消失 #1144
Labels
Comments
function replaceNonCodeBlocks(text, sign, className, style) {
const regex = new RegExp("``[^`]*``|" + sign + "[^" + sign + "]*?" + sign + "|`[^`]*`", 'g');
let inCodeBlock = false;
let result = '';
let lastIndex = 0;
text.replace(regex, (match, index) => {
if (match.startsWith("``")) {
inCodeBlock = !inCodeBlock;
} else if (!inCodeBlock && (match.startsWith(sign) || match.startsWith("`"))) {
result += text.slice(lastIndex, index) + `<span class="${className}" style="${style}">${match.slice(2, -2)}</span>`;
lastIndex = index + match.length;
}
});
result += text.slice(lastIndex);
return result;
}
const text = `
这是一个==忽略代码块==。里面有==另一个==忽略代码块==。==最里面的==忽略代码块==。
这个是\`\`\`代码块==不应该被匹配==。
\`哈哈哈哈==这个是单行代码不需要匹配==对对对\`
这是一个包含代码块的段落:
\`\`\`
function test() {
console.log("这个是代码块内容");
}
==这也也不应该匹配==
\`\`\`
这个是一个包含==内联代码==的例子。
`;
const replacedText = replaceNonCodeBlocks(text, "=", "mark", "color: red;");
console.log(replacedText); 上面是新的测试用例,已修复,需更新 |
terwer
added a commit
that referenced
this issue
Apr 9, 2024
terwer
added a commit
that referenced
this issue
Apr 9, 2024
terwer
added a commit
that referenced
this issue
Apr 9, 2024
terwer
added a commit
that referenced
this issue
Apr 9, 2024
terwer
added a commit
that referenced
this issue
Apr 9, 2024
terwer
added a commit
that referenced
this issue
Apr 9, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The text was updated successfully, but these errors were encountered: