-
Notifications
You must be signed in to change notification settings - Fork 531
feat: 优化代码块自动闭合的时机 #1606
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
base: dev
Are you sure you want to change the base?
feat: 优化代码块自动闭合的时机 #1606
Conversation
|
sunsonliu
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
感谢贡献哈,有一些小问题麻烦确认下哈
| // 【关键修改】在流式渲染模式下,不显示代码块,而是显示占位符 | ||
| if ($engine.$cherry.options.engine.global.flowSessionContext) { | ||
| return `<div data-sign="${sign}" data-type="codeBlock" class="mermaid-loading"> | ||
| <div class="mermaid-placeholder">Mermaid 图表渲染中...</div> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| }, | ||
| }); | ||
| return addContainer(placeholder); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
同样的,这段逻辑可以考虑去掉哈,可以在$dealUnclosingCode 函数里实现
| }); | ||
| } | ||
|
|
||
| $dealUnclosingCode(str) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
建议保留这段逻辑哈,我们的目标不是输出占位,而是在确定是代码块的时候输出代码块,在确定是mermaid图的时候输出mermaid图,在不确定的时候什么都不输出
| } else { | ||
| cacheCode = Prism.highlight(cacheCode, Prism.languages[lang], lang); | ||
| cacheCode = this.renderLineNumber(cacheCode); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| class="${needUnExpand ? 'cherry-code-unExpand' : 'cherry-code-expand'}" | ||
| > | ||
| ${this.customWrapperRender(oldLang, cacheCode, codeHtml)} | ||
| `; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| // Logger.debug('[CodeBlock]', '[onCodeMirrorChange]', 'lineContent', lineContent) | ||
| // Logger.debug('[CodeBlock]', '[onCodeMirrorChange]', 'nextLineContent', nextLineContent) | ||
| // 这样可以避免在已展开的代码块内部重复触发 | ||
| //如果相隔超过一行就不要管了,继续重新生成 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
额,可能更鲁棒的做法是判断代码块的闭合情况。。如果存在未闭合的代码块,则只需要联想出 ``` 就可以了。如果不存在未闭合的代码块,就可以联想出语言选择了
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
好的好的,谢谢大佬指导,我这两天研究一下




#1549
主要是在未修改之前,输入```会自动闭合成代码块,然后就是 mermaid 格式下是先生成了代码块
我先造 Suggester 文件下增加了,处理在输入回车时候的操作,如果是```跟任意字符串加空格就能自动闭合,如果不是就不做任何操作。这边这里注意了输入的```的数量和重复生成的问题。。。。更多的重复我没有好的想法解决
并且联想窗存在的时候按回车也能生效,这个要注意一下
关于 mermaid 的渲染,主要改了codeBlock 这个文件
保证了在 mermaid 模式下,只要里面没有/n 之外的东西就是使用一个占位语句,如果有东西就看里面输入的是什么,是合适的语法就渲染图表,不是的话还是代码块。只是保证了一开始不会出现代码块
然后就是这里,关于使用的语言,如果你回车的语言不被 Prism 支持,那就不怎么管了。。。只要保证存在的语言合理显示
然后可能会有一些 bug。。。希望大佬帮我看看