Support code block highlighting template syntax and export code block templates as paragraphs - #15345
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
|
我感觉可以给代码块增加一个内置的 siyuan-template 语言(命名参考 php-template) |
- 渲染.action 块和{{}}块规则
- 渲染Markdown块
- 思源块属性设置语法
|
|
relevance的范围好像是0-10,我去找找相关文档 https://highlightjs.readthedocs.io/en/latest/language-guide.html#relevance |
改了,设置更高其实应该没事 |
补充变量高亮:getHPathByID|getBlock|statBlock|runeCount|wordCount|toPrettyJson|
导出时,增加识别`siyuan-template`代码块为模板
代码块语言新增`siyuan-template`
There was a problem hiding this comment.
Pull Request Overview
This PR enhances template editing experience in SiYuan by allowing users to store template syntax within code blocks, improving the in-app template creation workflow.
- Adds support for template syntax highlighting in code blocks with language set to "template" or "siyuan-template"
- Implements conversion logic to transform template code blocks into plain text when exporting as templates
- Enables WYSIWYG template creation directly within SiYuan without external editors
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| kernel/model/template.go | Adds regex-based processing to convert template code blocks to plain text during template export |
| app/stage/protyle/js/highlight.js/third-languages.js | Implements comprehensive syntax highlighting for SiYuan template language with SQL and Go template support |
| app/src/constants.ts | Adds "siyuan-template" to the list of recognized code language aliases |
|
虽然明显偏题,但是我找到highlightjs-solidity 2.0.5->2.0.6,highlightjs-sap-abap 0.2.0->0.3.0,如果D大和V大觉得有必要的话在合并之后看看吧 |
麻烦提 pr |
辛苦啦,我一开始也是想修改语法树的,但是不熟悉语法树结构,就曲线救国用正则啦 |
|
@Vanessa219 我看是直接把siyuan-template别名都删掉了吗,我觉得highlight.js的aliases可以保留下,代码块可以不支持直接选择siyuan-template,但需要siyuan-template的高亮, 后面可以给highlight.js提交pr,支持siyuan-template的高亮 这样后面如果其他外部网站介绍思源模板语法,可以用siyuan-template为代码块语言(用template为代码语言适合思源自己内部用),用思源笔记剪藏文章下来也能直接高亮 |
… templates as paragraphs (siyuan-note#15345) * ✨ feat: 优化模板编辑体验,支持使用代码块来存储模板语法 * ✨ feat: 支持对template代码块进行高亮 - 渲染.action 块和{{}}块规则 - 渲染Markdown块 - 思源块属性设置语法 * Update third-languages.js * Update third-languages.js * Update third-languages.js * Update third-languages.js * Update third-languages.js:块属性支持高亮.action{}语法,调整relevance * 支持渲染queryBlocks的sql语句和嵌入块sql语句 * Update third-languages.js 补充变量高亮:getHPathByID|getBlock|statBlock|runeCount|wordCount|toPrettyJson| * ✨ feat: 优化模板编辑体验,支持使用代码块来存储模板语法 siyuan-note#15345 导出时,增加识别`siyuan-template`代码块为模板 * ✨ feat: 优化模板编辑体验,支持使用代码块来存储模板语法 siyuan-note#15345 代码块语言新增`siyuan-template` * Update template.go --------- Co-authored-by: D <845765@qq.com>
… templates as paragraphs (siyuan-note#15345) * ✨ feat: 优化模板编辑体验,支持使用代码块来存储模板语法 * ✨ feat: 支持对template代码块进行高亮 - 渲染.action 块和{{}}块规则 - 渲染Markdown块 - 思源块属性设置语法 * Update third-languages.js * Update third-languages.js * Update third-languages.js * Update third-languages.js * Update third-languages.js:块属性支持高亮.action{}语法,调整relevance * 支持渲染queryBlocks的sql语句和嵌入块sql语句 * Update third-languages.js 补充变量高亮:getHPathByID|getBlock|statBlock|runeCount|wordCount|toPrettyJson| * ✨ feat: 优化模板编辑体验,支持使用代码块来存储模板语法 siyuan-note#15345 导出时,增加识别`siyuan-template`代码块为模板 * ✨ feat: 优化模板编辑体验,支持使用代码块来存储模板语法 siyuan-note#15345 代码块语言新增`siyuan-template` * Update template.go --------- Co-authored-by: D <845765@qq.com>
… templates as paragraphs (siyuan-note#15345) * ✨ feat: 优化模板编辑体验,支持使用代码块来存储模板语法 * ✨ feat: 支持对template代码块进行高亮 - 渲染.action 块和{{}}块规则 - 渲染Markdown块 - 思源块属性设置语法 * Update third-languages.js * Update third-languages.js * Update third-languages.js * Update third-languages.js * Update third-languages.js:块属性支持高亮.action{}语法,调整relevance * 支持渲染queryBlocks的sql语句和嵌入块sql语句 * Update third-languages.js 补充变量高亮:getHPathByID|getBlock|statBlock|runeCount|wordCount|toPrettyJson| * ✨ feat: 优化模板编辑体验,支持使用代码块来存储模板语法 siyuan-note#15345 导出时,增加识别`siyuan-template`代码块为模板 * ✨ feat: 优化模板编辑体验,支持使用代码块来存储模板语法 siyuan-note#15345 代码块语言新增`siyuan-template` * Update template.go --------- Co-authored-by: D <845765@qq.com>




✨ feat: 优化模板编辑体验,支持使用代码块来存储模板语法
Feature or bug? 特性或者缺陷?
关联:#15344
痛点
思源笔记原生没有模板编辑器,模板语法直接粘贴到笔记里,容易渲染成数学公式等样式,无法原样导出到模板,即无法在思源笔记里完成包含模板语法的模板制作

而使用外部编辑器,当创作带有背景颜色、自定义属性以及含有大量列表的模板时,会非常不便,过去经常要先在思源笔记弄好样式,然后导出为模板,再在外部编辑器添加模板语法,替换占位文字

改进
支持使用代码块来存储模板语法:
代码块语言设置为template时,认为是存放模板语法的地方,导出为模板,代码块里的模板内容变为纯文本段落,这样就可以直接导出带有模板语法的模板,就能直接调用,创建模板变得所见即所得
例子,在思源笔记创建如下内容的笔记

导出为模板

调用

Multilingual or copywriting? 多语言或者文案?
Please submit directly, we will evaluate.
请直接提交,我们会进行评估。
Dev branch!
Any changes should be submitted to the dev branch.
任何改动,请提交到 dev 分支。