-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
同样的代码为什么Lute和思源渲染的结果不一致? #14310
Comments
图 3 和 4 好像是一样的……? |
对的,就是 @TCOTC 说的那样,3和4渲染的结果不一样,看输出,别看输入。 且数据库markdown字段查询结果也是这个源码,实际上是Lute渲染的是SQL查询的markdown字段内容。 期望这个Lute渲染结果也是这个,即和思源笔记渲染结果一致 确切的说,思源笔记中渲染的结果是这个,bbbb是在h4的文本 |
我先关闭了,还有问题的话请随时跟帖。 |
试了一下确实可以了: 附上 AI 生成的代码: const setLute = (options) => {
const lute = window.Lute.New();
lute.SetSpellcheck(window.siyuan.config.editor.spellcheck);
lute.SetProtyleMarkNetImg(window.siyuan.config.editor.displayNetImgMark);
lute.SetFileAnnotationRef(true);
lute.SetHTMLTag2TextMark(true);
lute.SetTextMark(true);
lute.SetHeadingID(false);
lute.SetYamlFrontMatter(false);
lute.PutEmojis(options.emojis);
lute.SetEmojiSite(options.emojiSite);
lute.SetHeadingAnchor(options.headingAnchor);
lute.SetInlineMathAllowDigitAfterOpenMarker(true);
lute.SetToC(false);
lute.SetIndentCodeBlock(false);
lute.SetParagraphBeginningSpace(true);
lute.SetSetext(false);
lute.SetFootnotes(false);
lute.SetLinkRef(false);
lute.SetSanitize(options.sanitize);
lute.SetChineseParagraphBeginningSpace(options.paragraphBeginningSpace);
lute.SetRenderListStyle(options.listStyle);
lute.SetImgPathAllowSpace(true);
lute.SetKramdownIAL(true);
lute.SetTag(true);
lute.SetSuperBlock(true);
lute.SetMark(true);
lute.SetInlineAsterisk(window.siyuan.config.editor.markdown.inlineAsterisk);
lute.SetInlineUnderscore(window.siyuan.config.editor.markdown.inlineUnderscore);
lute.SetSup(window.siyuan.config.editor.markdown.inlineSup);
lute.SetSub(window.siyuan.config.editor.markdown.inlineSub);
lute.SetTag(window.siyuan.config.editor.markdown.inlineTag);
lute.SetInlineMath(window.siyuan.config.editor.markdown.inlineMath);
lute.SetGFMStrikethrough1(false);
lute.SetGFMStrikethrough(window.siyuan.config.editor.markdown.inlineStrikethrough);
lute.SetMark(window.siyuan.config.editor.markdown.inlineMark);
lute.SetSpin(true);
lute.SetProtyleWYSIWYG(true);
if (options.lazyLoadImage) {
lute.SetImageLazyLoading(options.lazyLoadImage);
}
lute.SetBlockRef(true);
if (window.siyuan.emojis[0].items.length > 0) {
const emojis = {};
window.siyuan.emojis[0].items.forEach(item => {
emojis[item.keywords] = options.emojiSite + "/" + item.unicode;
});
lute.PutEmojis(emojis);
}
return lute;
};
// 1. 优化查找函数(仅匹配 .editor.protyle 结尾路径)
function findProtylePaths(obj) {
const results = [];
const seen = new Set();
function walk(obj, path = '') {
if (!obj || seen.has(obj)) return;
seen.add(obj);
for (const [key, value] of Object.entries(obj)) {
const currentPath = path ? `${path}.${key}` : key;
// 检查是否以 .editor.protyle 结尾
if (currentPath.endsWith('.editor.protyle')) {
results.push({ path: currentPath, value });
}
if (typeof value === 'object') {
walk(value, currentPath);
}
}
}
walk(obj);
return results;
}
// 2. 获取目标对象
const protylePaths = findProtylePaths(window.siyuan);
const firstProtyle = protylePaths[0]?.value;
if (firstProtyle) {
// 3. 动态设置 lute 并调用
firstProtyle.lute = setLute({
emojiSite: firstProtyle.options?.hint?.emojiPath,
emojis: firstProtyle.options?.hint?.emoji,
headingAnchor: false,
listStyle: firstProtyle.options?.preview?.markdown?.listStyle,
paragraphBeginningSpace: firstProtyle.options?.preview?.markdown?.paragraphBeginningSpace,
sanitize: firstProtyle.options?.preview?.markdown?.sanitize,
});
// 4. 安全调用方法
if (firstProtyle.lute?.Md2BlockDOM) {
console.log(firstProtyle.lute.Md2BlockDOM(
'### b<span data-type="text" style="color: var(--b3-font-color8);">bb</span>b'
));
}
} else {
console.warn('未找到符合条件的 protyle 对象');
} |
我在@TCOTC 大佬的基础上又简单封装了一下,更方便调用。 调用方式: 封装函数如下: function getLute() {
const setLute = (options) => {
const lute = window.Lute.New();
lute.SetSpellcheck(window.siyuan.config.editor.spellcheck);
lute.SetProtyleMarkNetImg(window.siyuan.config.editor.displayNetImgMark);
lute.SetFileAnnotationRef(true);
lute.SetHTMLTag2TextMark(true);
lute.SetTextMark(true);
lute.SetHeadingID(false);
lute.SetYamlFrontMatter(false);
lute.PutEmojis(options.emojis);
lute.SetEmojiSite(options.emojiSite);
lute.SetHeadingAnchor(options.headingAnchor);
lute.SetInlineMathAllowDigitAfterOpenMarker(true);
lute.SetToC(false);
lute.SetIndentCodeBlock(false);
lute.SetParagraphBeginningSpace(true);
lute.SetSetext(false);
lute.SetFootnotes(false);
lute.SetLinkRef(false);
lute.SetSanitize(options.sanitize);
lute.SetChineseParagraphBeginningSpace(options.paragraphBeginningSpace);
lute.SetRenderListStyle(options.listStyle);
lute.SetImgPathAllowSpace(true);
lute.SetKramdownIAL(true);
lute.SetTag(true);
lute.SetSuperBlock(true);
lute.SetMark(true);
lute.SetInlineAsterisk(window.siyuan.config.editor.markdown.inlineAsterisk);
lute.SetInlineUnderscore(window.siyuan.config.editor.markdown.inlineUnderscore);
lute.SetSup(window.siyuan.config.editor.markdown.inlineSup);
lute.SetSub(window.siyuan.config.editor.markdown.inlineSub);
lute.SetTag(window.siyuan.config.editor.markdown.inlineTag);
lute.SetInlineMath(window.siyuan.config.editor.markdown.inlineMath);
lute.SetGFMStrikethrough1(false);
lute.SetGFMStrikethrough(window.siyuan.config.editor.markdown.inlineStrikethrough);
lute.SetMark(window.siyuan.config.editor.markdown.inlineMark);
lute.SetSpin(true);
lute.SetProtyleWYSIWYG(true);
if (options.lazyLoadImage) {
lute.SetImageLazyLoading(options.lazyLoadImage);
}
lute.SetBlockRef(true);
if (window.siyuan.emojis[0].items.length > 0) {
const emojis = {};
window.siyuan.emojis[0].items.forEach(item => {
emojis[item.keywords] = options.emojiSite + "/" + item.unicode;
});
lute.PutEmojis(emojis);
}
return lute;
};
// 1. 优化查找函数(仅匹配 .editor.protyle 结尾路径)
function findProtylePaths(obj) {
const results = [];
const seen = new Set();
function walk(obj, path = '') {
if (!obj || seen.has(obj)) return;
seen.add(obj);
for (const [key, value] of Object.entries(obj)) {
const currentPath = path ? `${path}.${key}` : key;
// 检查是否以 .editor.protyle 结尾
if (currentPath.endsWith('.editor.protyle')) {
results.push({ path: currentPath, value });
}
if (typeof value === 'object') {
walk(value, currentPath);
}
}
}
walk(obj);
return results;
}
// 2. 获取目标对象
const protylePaths = findProtylePaths(window.siyuan);
const firstProtyle = protylePaths[0]?.value;
if (firstProtyle) {
// 3. 动态设置 lute 并调用
firstProtyle.lute = setLute({
emojiSite: firstProtyle.options?.hint?.emojiPath,
emojis: firstProtyle.options?.hint?.emoji,
headingAnchor: false,
listStyle: firstProtyle.options?.preview?.markdown?.listStyle,
paragraphBeginningSpace: firstProtyle.options?.preview?.markdown?.paragraphBeginningSpace,
sanitize: firstProtyle.options?.preview?.markdown?.sanitize,
});
// 4. 获取lute实例
return firstProtyle.lute;
} else {
console.warn('未找到符合条件的 protyle 对象');
return Lute.New();
}
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is there an existing issue for this?
Can the issue be reproduced with the default theme (daylight/midnight)?
Could the issue be due to extensions?
Describe the problem
如上图,在思源中,给文本添加颜色后,同样的源码,思源渲染的HTML结果(见图中的3)为何和Lute渲染的结果(见图中的4)不一致?
这会导致一个问题,当我用Lute渲染SQL 查询到的markdown源码时,结果和思源笔记中的不一致,导致产生意外结果。
请问大佬们,是我用法不对吗?正确该怎么渲染markdown源码?
Expected result
二者渲染结果一致
Screenshot or screen recording presentation
No response
Version environment
Log file
no
More information
No response
The text was updated successfully, but these errors were encountered: