diff --git a/.all-contributorsrc b/.all-contributorsrc
index 6baa5c8..835cabc 100644
--- a/.all-contributorsrc
+++ b/.all-contributorsrc
@@ -74,7 +74,7 @@
}
],
"contributorsPerLine": 7,
- "badgeTemplate": "[![All Contributors](https://img.shields.io/badge/all_contributors-<%= contributors.length %>-orange.svg?style=flat-square)](#贡献者--contributor)",
+ "badgeTemplate": "[![All Contributors](https://img.shields.io/badge/all_contributors-<%= contributors.length %>-orange.svg?style=flat-square)](#contributors)",
"projectName": "widget-query",
"projectOwner": "Zuoqiu-Yingyi",
"repoType": "github",
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3e53345..96c7016 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,8 @@
# 更改日志 | CHANGE LOG
+## v0.3.2/2022-04-18
+
+- [v0.3.1 <=> v0.3.2](https:///github.com/Zuoqiu-Yingyi/widget-query/compare/v0.3.1...v0.3.2)
- 配置文件 `config.js` 有变更 | There are changes to the configuration file `config.js`.
- 更新自定义属性视图示例 | Update the example of Custom Properties View.
- 优化模板字段替换方案 | Optimize the replacement scheme of template fields.
diff --git a/README.md b/README.md
index 34a8bd5..ed89d48 100644
--- a/README.md
+++ b/README.md
@@ -9,7 +9,7 @@
![GitHub repo size](https://img.shields.io/github/repo-size/Zuoqiu-Yingyi/widget-query?style=flat-square)
![hits](https://hits.b3log.org/Zuoqiu-Yingyi/widget-query.svg)
[![GitHub all releases](https://img.shields.io/github/downloads/Zuoqiu-Yingyi/widget-query/total?style=flat-square)](https://github.com/Zuoqiu-Yingyi/widget-query/releases)
-[![All Contributors](https://img.shields.io/badge/all_contributors-7-orange.svg?style=flat-square)](#贡献者--contributor)
+[![All Contributors](https://img.shields.io/badge/all_contributors-7-orange.svg?style=flat-square)](#contributors)
[English](./README_en.md)
@@ -48,7 +48,8 @@
## 功能
-1. 符合正则表达式 `^\s*SELECT\s+\*\s+FROM\s+blocks\s+.*` 的 SQL 语句将启用默认块查询模式
+1. 点选自动查询复选框, 下次打开该页面时自动进行一次查询
+2. 符合正则表达式 `^\s*SELECT\s+\*\s+FROM\s+blocks\s+.*` 的 SQL 语句将启用默认块查询模式
* 该正则表达式在 `/src/script/module/config.js` 文件中 `config.query.regs.blocks` 定义
* 示例: `SELECT * FROM blocks WHERE content LIKE '%内容块%'`
@@ -71,7 +72,7 @@
|`config.query.filter.blocks`|定义过滤器序列, 过滤一些查询结果|`{enable: true/flase, handlers: [(row, data) => {}, ...]}`|需要过滤的返回 `true`, 需要保留的返回 `false`|
|`config.query.handler.*`|定义具体字段值的处理函数|`(row, ial) => {}`|`row`: 当前记录
`ial`: 当前查询记录解析后的内联属性列表|
|`config.query.map.*`|查询结果映射表, 将某些查询结果字段值替换为人类可读的字段|||
-2. 不符合默认块查询模式的查询均为普通查询模式
+3. 不符合默认块查询模式的查询均为普通查询模式
* 示例
@@ -314,7 +315,7 @@
```
![字段别名前缀示例](https://cdn.jsdelivr.net/gh/Zuoqiu-Yingyi/widget-query//image/README/1648568044659.png)
-3. 部分模板字段解析支持
+4. 部分模板字段解析支持
* `.{.}`
@@ -341,525 +342,27 @@
#### 配置示例
```js
-export var config = {
- token: '', // API token, 无需填写
- query: { // 查询配置
- width: '128px', // 挂件宽度
- height: '32px', // 挂件高度
- radius: '8px', // 挂件圆角
- color: {
- default: 'rgb(255, 255, 255)', // 默认颜色
- success: 'rgb(183, 223, 185)', // 成功颜色
- info: 'rgb(166, 213, 250)', // 信息颜色
- warning: 'rgb(255, 213, 153)', // 警告颜色
- error: 'rgb(250, 179, 174)', // 错误颜色
- },
- regs: {
- blocks: /^\s*SELECT\s+\*\s+FROM\s+blocks\s+.*/i, // 块查询的正则表达式
- limit: /\s+LIMIT\s+\d+/i, // SQL LIMIT 关键字正则表达式
- sort: /^__(\d+)__(.*)$/i, // 手动排序字段正则表达式
- render: /^__(\w+)__(.*)$/i, // 渲染控制字段正则表达式
- hex: /^[0-9a-fA-F]+$/, // 16 进制正则表达式
- },
- attribute: { // 块属性
- code: 'query-code', // 查询代码块
- widget: 'query-widget', // 查询挂件块
- table: 'query-table', // 查询结果表格块
- },
- sql: {
- // SQL 语句处理
- limit: { // 查询记录数量限制, 若启用且为设置 LIMIT 语句, 则在查询语句末尾添加 "LIMIT begin, end"
- enable: false, // 是否启用限制
- begin: 0, // 开始记录数
- end: 100, // 结束记录数
- },
- },
- template: { // 类似模板字段解析支持, 类似 .prefix{.field}, 目前支持的有 .root{.<挂件所在文档块的字段名>} .parent{.<挂件上级块的字段名>} .block{挂件块的字段名}
- enable: true, // 是否启用模板解析
- handler: async (data) => { // 模板解析处理函数
- return await templateParse(data);
- }
- },
- index: {
- enable: true, // 查询结果是否显示索引序号
- },
+/**
+ * 文件路径
+ * <工作空间>/data/widgets/custom.js
+ * 示例功能 | Example function:
+ * 默认块查询结果中将块属性分列显示
+ */
+
+export const config = {
+ query: {
render: {
- // 块查询部分字段渲染方案
- /**
- * 'ref': 渲染为块引用
- * 'link': 渲染为块超链接
- */
- type: 'link', // 块类型
- hpath: 'link', // 块所在文档路径
- id: 'link', // 块 ID
- parent_id: 'link', // 块的上级块 ID
- root_id: 'link', // 块所在文档 ID
-
- ial: { // 内联属性样式
- /**形状
- * 'rows': 一列中分行显示
- * 'columns': 一行中分列显示
- */
- shape: 'rows',
- /**样式
- * 's': 该字段渲染为删除线
- * 'u': 该字段渲染为下划线
- * 'em': 该字段渲染为斜体
- * 'tag': 该字段渲染为标签
- * 'kbd': 该字段渲染为按键样式
- * 'sub': 该字段渲染为下标样式
- * 'sup': 该字段渲染为上标样式
- * 'code': 该字段渲染为行内代码
- * 'mark': 该字段渲染为标记
- * 'math': 该字段渲染为公式
- * 'strong': 该字段渲染为粗体
- */
- style: {
- rows: {
- key: 'kbd', // 内联属性键样式
- value: 'code', // 内联属性值样式
- null: 'NULL', // 内联属性为空时占位符
- },
- columns: {
- key: 'kbd', // 内联属性键样式
- value: 'kbd', // 内联属性值样式
- null: '', // 内联属性为空时占位符
- },
- },
- fields: { // 内联属性字段
- forced: [], // 强制显示的 IAL 键, 为空则使用黑白名单
- ignore: [ // 需渲染的 IAL 键黑名单
- 'id', // 块 ID
- 'fold', // 是否折叠
- 'style', // 块样式
- 'updated', // 块更新时间
- 'linewrap', // 代码块是否换行
- 'ligatures', // 代码块是否启用连字符
- 'linenumber', // 代码块是否显示行号
- 'colgroup', // 表格块列组
- 'title-img', // 文档块题头图
- 'heading-fold', // 折叠标题块下级块
- ],
- valid: [], // 按照顺序渲染的 IAL 键白名单, 为空则全部渲染
- },
- },
- },
- limit: 'row', // 查询结果字段限制, (null 为不限制, 'len' 为限制长度, 'row' 为限制行数)
- maxlen: 64, // 查询结果每个字段最大长度
- maxrow: 3, // 查询结果每个字段最大行数
- CRLF: '
', // 换行符替换
- space: ' ', // 空白字符替换
- fields: [ // 需渲染的 blocks 表的字段, 顺序分先后
- 'type', // 内容块类型,参考((20210210103523-ombf290 "类型字段"))
- // 'content', // 去除了 Markdown 标记符的文本
- // 'fcontent', // 容器块第一个子块的内容
- 'markdown', // 包含完整 Markdown 标记符的文本
- 'ial', // 内联属性列表,形如 `{: name="value"}`
- 'hpath', // 人类可读的内容块所在文档路径
- 'created', // 创建时间
- 'updated', // 更新时间
-
- // 'id', // 内容块 ID
- // 'parent_id', // 双亲块 ID, 如果内容块是文档块则该字段为空
- // 'root_id', // 文档块 ID
- // 'box', // 笔记本 ID
- // 'path', // 内容块所在文档路径
- // 'name', // 内容块名称
- // 'alias', // 内容块别名
- // 'memo', // 内容块备注
- // 'hash', // content 字段的 SHA256 校验和
- // 'length', // content 字段文本长度
- // 'subtype', // 内容块子类型,参考((20210210103411-tcbcjja "子类型字段"))
- // 'sort', // 排序权重, 数值越小排序越靠前
- ],
- style: {
- // 查询结果样式
- table: {
- // 表格样式
- enable: true, // 是否启用使用块自定义属性设置表格样式
- attributes: [
- {
- // 表格自定义属性, 表格自动折行, 详情请参考 [siyuan-theme-dark-plus/custom-table-width.css at main · Zuoqiu-Yingyi/siyuan-theme-dark-plus](https://github.com/Zuoqiu-Yingyi/siyuan-theme-dark-plus/blob/main/style/module/custom-table-width.css)
- enable: false, // 是否启用该自定义属性
- key: 'custom-table-width', // 属性名
- value: 'auto', // 属性值
- },
- {
- // 块自定义属性, 为块设置滚动条, 详情请参考 [siyuan-theme-dark-plus/custom-render-scroll.css at main · Zuoqiu-Yingyi/siyuan-theme-dark-plus](https://github.com/Zuoqiu-Yingyi/siyuan-theme-dark-plus/blob/main/style/module/custom-render-scroll.css)
- enable: true, // 是否启用该自定义属性
- key: 'custom-render', // 属性名
- value: 'scroll', // 属性值
- },
- ],
- },
- column: {
- // 列样式, 自定义宽度的字段可以设置为 '{: style="width: 512px"}'
- content: '',
- fcontent: '',
- markdown: '',
- created: '',
- updated: '',
- type: '',
- hpath: '',
-
- id: '',
- parent_id: '',
- root_id: '',
- hash: '',
- box: '',
- path: '',
- name: '',
- alias: '',
- memo: '',
- length: '',
- subtype: '',
- ial: '',
- sort: '',
- },
- align: { // 查询结果字段对齐样式(':-' 左对齐, ':-:' 居中, '-:' 右对齐)
- content: ':-',
- fcontent: ':-',
- markdown: ':-',
- created: ':-:',
- updated: ':-:',
- type: ':-:',
- hpath: ':-',
-
- id: ':-:',
- parent_id: ':-:',
- root_id: ':-:',
- hash: ':-:',
- box: ':-:',
- path: ':-',
- name: ':-',
- alias: ':-',
- memo: ':-',
- length: '-:',
- subtype: '-:',
- ial: ':-',
- sort: '-:',
- },
- },
- filter: {
- // 查询结果过滤器
- blocks: { // 块查询的过滤
- enable: true, // 是否启用过滤
- handlers: [ // 过滤处理方法序列
- (row, data) => { // 过滤查询结果中的查询结构(查询代码块, Query 挂件块)
- // row: 查询结果一条记录
- // data: 挂件数据
- // return: 返回 true 则过滤掉当前记录, 返回 false 则不过滤
- switch (true) {
- case row.ial.indexOf(`custom-type="${config.query.attribute.code}"`) != -1:
- case row.ial.indexOf(`custom-type="${config.query.attribute.widget}"`) != -1:
- case row.ial.indexOf(`custom-type="${config.query.attribute.table}"`) != -1:
- return true;
- default:
- return false;
- }
- },
- ],
- }
- },
- rows: { // 查询结果处理方法
- ials: { // IAL 处理方法
- keys: (rows, ialParser) => {
- // 获得查询结果所有记录 IAL 键
- let keys = new Set();
- if (rows.length > 0) {
- for (let i = 0, len = rows.length; i < len; i++) {
- let ial = ialParser(rows[i].ial);
- Object.keys(ial).forEach(key => keys.add(key));
- }
- }
- return keys;
- },
- },
- },
- handler: { // 块查询结果各字段处理方法
- content: (row, ial, ...args) => {
- switch (config.query.limit) {
- case 'len':
- return markdown2span(cutString(ReplaceSpace(row.content, config.query.space), config.query.maxlen));
- case 'row':
- return markdown2span(ReplaceCRLF(cutString(row.content, undefined, config.query.maxrow), config.query.CRLF));
- default:
- return markdown2span(row.content);
- }
- },
- fcontent: (row, ial, ...args) => {
- switch (config.query.limit) {
- case 'len':
- return markdown2span(cutString(ReplaceSpace(row.fcontent, config.query.space), config.query.maxlen));
- case 'row':
- return markdown2span(ReplaceCRLF(cutString(row.fcontent, undefined, config.query.maxrow), config.query.CRLF));
- default:
- return markdown2span(row.fcontent);
- }
- },
- markdown: (row, ial, ...args) => {
- switch (config.query.limit) {
- case 'len':
- return markdown2span(cutString(ReplaceSpace(row.markdown, config.query.space), config.query.maxlen));
- case 'row':
- return markdown2span(ReplaceCRLF(cutString(row.markdown, undefined, config.query.maxrow), config.query.CRLF));
- default:
- return markdown2span(row.markdown);
- }
- },
- created: (row, ial, ...args) => {
- return timestampFormat(row.created);
- },
- updated: (row, ial, ...args) => {
- return timestampFormat(row.updated);
- },
- type: (row, ial, ...args) => {
- switch (config.query.render.type) {
- case 'link':
- return `[${config.query.map.blocktype[row.type]}](siyuan://blocks/${row.id})`;
- case 'ref':
- default:
- return `((${row.id} "${config.query.map.blocktype[row.type]}"))`;
- }
- },
- hpath: (row, ial, ...args) => {
- switch (config.query.render.hpath) {
- case 'link':
- return `[${row.hpath}](siyuan://blocks/${row.root_id})`;
- case 'ref':
- default:
- return `((${row.root_id} "${row.hpath}"))`;
- }
- },
-
- id: (row, ial, ...args) => {
- switch (config.query.render.id) {
- case 'link':
- return `[${row.id}](siyuan://blocks/${row.id})`;
- case 'ref':
- default:
- return `((${row.id} "${row.id}"))`;
- }
- },
- parent_id: (row, ial, ...args) => {
- if (isEmptyString(row.parent_id)) return '';
- else {
- switch (config.query.render.parent_id) {
- case 'link':
- return `[${row.parent_id}](siyuan://blocks/${row.parent_id})`;
- case 'ref':
- default:
- return `((${row.parent_id} "${row.parent_id}"))`;
- }
- }
- },
- root_id: (row, ial, ...args) => {
- switch (config.query.render.root_id) {
- case 'link':
- return `[${row.root_id}](siyuan://blocks/${row.root_id})`;
- case 'ref':
- default:
- return `((${row.root_id} "${row.root_id}"))`;
- }
- },
- hash: (row, ial, ...args) => {
- return `\`${row.hash}\``;
- },
- box: (row, ial, ...args) => {
- return `\`${row.box}\``;
- },
- path: (row, ial, ...args) => {
- return `\`${row.path}\``;
- },
- name: (row, ial, ...args) => {
- return markdown2span(row.name, 'kbd');
- },
- alias: (row, ial, ...args) => {
- return markdown2span(row.alias, 'kbd', /\\s+,\\s+/g);
- },
- memo: (row, ial, ...args) => {
- return markdown2span(row.memo);
- },
- length: (row, ial, ...args) => {
- return row.length;
- },
- subtype: (row, ial, ...args) => {
- return config.query.map.subtype[row.subtype];
- },
- ial: (row, ial, ...args) => {
- let ial_markdown = [];
- let ial_keys = args[0];
- switch (config.query.render.ial.shape) {
- case 'columns':
- ial_keys.forEach((key) => {
- if (ial[key]) {
- switch (key) {
- case 'icon':
- if (ial[key].startsWith(':') && ial[key].endsWith(':')) {
- // 自定义图标
- ial_markdown.push(ial[key]);
- break;
- }
- default:
- ial_markdown.push(markdown2span(ial[key], config.query.render.ial.style.columns.value));
- break;
- }
- }
- else ial_markdown.push(config.query.render.ial.style.columns.null
- ? markdown2span(config.query.render.ial.style.columns.null, config.query.render.ial.style.columns.value)
- : '');
- });
- return ial_markdown.join(' | ');
- case 'rows':
- default:
- ial_keys.forEach((key) => {
- if (config.query.render.ial.fields.forced.length > 0 || ial[key])
- console.log(key, config.query.render.ial.fields.forced, ial[key], ial);
- if (config.query.render.ial.fields.forced.length > 0 || ial[key] !== undefined) {
- let ial_key = markdown2span(key, config.query.render.ial.style.rows.key)
- let ial_value = ial[key] || (config.query.render.ial.style.rows.null
- ? markdown2span(config.query.render.ial.style.rows.null, config.query.render.ial.style.rows.value)
- : '');
- switch (key) {
- case 'icon':
- if (ial_value.startsWith(':') && ial_value.endsWith(':')) {
- // 自定义图标
- ial_markdown.push(`${ial_key}\:${ial_value}`);
- break;
- }
- default:
- ial_markdown.push(`${ial_key}\:${markdown2span(ial_value, config.query.render.ial.style.rows.value)}`);
- break;
- }
- }
- });
- return ial_markdown.join(config.query.CRLF);
- }
- },
- sort: (row, ial, ...args) => {
- return row.sort;
- },
- },
- map: {
- // 映射表
- blocktype: { // 块类型映射
- d: '文档块',
- h: '标题块',
- l: '列表块',
- i: '列表项',
- c: '代码块',
- m: '公式块',
- t: '表格块',
- b: '引述块',
- s: '超级块',
- p: '段落块',
- tb: '分隔线',
- video: '视频块',
- audio: '音频块',
- widget: '挂件块',
- iframe: 'iframe',
- query_embed: '嵌入块',
- '': '',
- null: '',
- undefined: '',
- },
- subtype: { // 子类型映射
- o: '有序列表',
- u: '无序列表',
- t: '任务列表',
- h1: '一级标题',
- h2: '二级标题',
- h3: '三级标题',
- h4: '四级标题',
- h5: '五级标题',
- h6: '六级标题',
- '': '',
- null: '',
- undefined: '',
- },
- },
- prefix: {
- // 非默认查询时字段别名前缀
- hidden: '__hidden__', // 不显示此字段,仅用于数据查询
-
- ref: '__ref__', // 该字段渲染为引用
- link: '__link__', // 该字段渲染为链接
- pre: '__pre__', // 该字段渲染为预览
- raw: '__raw__', // 该字段渲染为原始值
- date: '__date__', // 该字段渲染为日期
- time: '__time__', // 该字段渲染为时间
- datetime: '__datetime__', // 该字段渲染为日期时间
-
- s: '__s__', // 该字段渲染为删除线
- u: '__u__', // 该字段渲染为下划线
- em: '__em__', // 该字段渲染为斜体
- tag: '__tag__', // 该字段渲染为标签
- kbd: '__kbd__', // 该字段渲染为按键样式
- sub: '__sub__', // 该字段渲染为下标样式
- sup: '__sup__', // 该字段渲染为上标样式
- code: '__code__', // 该字段渲染为行内代码
- mark: '__mark__', // 该字段渲染为标记
- math: '__math__', // 该字段渲染为公式
- strong: '__strong__', // 该字段渲染为粗体
- },
- default: {
- // 非块查询的处理模式
- name: (key) => { // 字段名称处理函数
- let name = config.query.regs.sort.test(key) ? config.query.regs.sort.exec(key)[2] : key;
- return config.query.regs.render.test(name) ? config.query.regs.render.exec(name)[2] : name;
- },
- handler: (key) => { // 其他查询结果默认处理方法生成函数, key 是字段名, 返回一个处理方法
- let name = config.query.regs.sort.test(key) ? config.query.regs.sort.exec(key)[2] : key;
- switch (true) {
- case name.startsWith(config.query.prefix.ref):
- return (row, key) => `((${row[key]} "${row[key]}"))`;
- case name.startsWith(config.query.prefix.link):
- return (row, key) => `[${row[key]}](siyuan://blocks/${row[key]})`;
- case name.startsWith(config.query.prefix.pre):
- return (row, key) => markdown2span(row[key]);
- case name.startsWith(config.query.prefix.date):
- return (row, key) => dateFormat(row[key]);
- case name.startsWith(config.query.prefix.time):
- return (row, key) => timeFormat(row[key]);
- case name.startsWith(config.query.prefix.datetime):
- return (row, key) => timestampFormat(row[key]);
-
- case name.startsWith(config.query.prefix.s):
- return (row, key) => markdown2span(row[key], 's');
- case name.startsWith(config.query.prefix.u):
- return (row, key) => markdown2span(row[key], 'u');
- case name.startsWith(config.query.prefix.em):
- return (row, key) => markdown2span(row[key], 'em');
- case name.startsWith(config.query.prefix.kbd):
- return (row, key) => markdown2span(row[key], 'kbd');
- case name.startsWith(config.query.prefix.sub):
- return (row, key) => markdown2span(row[key], 'sub');
- case name.startsWith(config.query.prefix.sup):
- return (row, key) => markdown2span(row[key], 'sup');
- case name.startsWith(config.query.prefix.tag):
- return (row, key) => markdown2span(row[key], 'tag');
- case name.startsWith(config.query.prefix.mark):
- return (row, key) => markdown2span(row[key], 'mark');
- case name.startsWith(config.query.prefix.math):
- return (row, key) => markdown2span(row[key], 'math');
- case name.startsWith(config.query.prefix.strong):
- return (row, key) => markdown2span(row[key], 'strong');
-
- case name.startsWith(config.query.prefix.raw):
- case name.startsWith(config.query.prefix.code):
- default:
- return (row, key) => markdown2span(row[key], 'code');
- }
- },
- style: {
- column: '',
- align: ':-',
+ ial: {
+ shape: 'columns',
},
},
},
};
+
```
+更多配置项请参考 [config.js](./src/script/module/config.js)
+
### 块自定义配置
* 在挂件块(笔记中的Query按钮)中设置自定义块属性
@@ -879,7 +382,7 @@ export var config = {
注: 排序不分先后
-## 贡献者
+## contributors
diff --git a/README_en.md b/README_en.md
index 2c1920e..310e63e 100644
--- a/README_en.md
+++ b/README_en.md
@@ -9,7 +9,7 @@
![GitHub repo size](https://img.shields.io/github/repo-size/Zuoqiu-Yingyi/widget-query?style=flat-square)
![hits](https://hits.b3log.org/Zuoqiu-Yingyi/widget-query.svg)
[![GitHub all releases](https://img.shields.io/github/downloads/Zuoqiu-Yingyi/widget-query/total?style=flat-square)](https://github.com/Zuoqiu-Yingyi/widget-query/releases)
-[![All Contributors](https://img.shields.io/badge/all_contributors-7-orange.svg?style=flat-square)](#贡献者--contributor)
+[![All Contributors](https://img.shields.io/badge/all_contributors-7-orange.svg?style=flat-square)](#contributors)
[简体中文](./README.md)
@@ -25,97 +25,248 @@ It is now on the shelves of the [Siyuan Notes Community Bazaar](https://github.c
![preview](https://cdn.jsdelivr.net/gh/Zuoqiu-Yingyi/widget-query/preview.png)
Background color status indication:
-- White:
- - Initialization.
- - Processing query.
-- Green:
- - Query success.
-- Blue:
- - Please continue to operate.
-- Yellow:
- - Query result is empty.
-- Red:
- - SQL SQL statement error.
- - Unknown error.
+
+* White:
+
+ * Initialization.
+ * Processing query.
+* Green:
+
+ * Query success.
+* Blue:
+
+ * Please continue to operate.
+* Yellow:
+
+ * Query result is empty.
+* Red:
+
+ * SQL SQL statement error.
+ * Unknown error.
## FUNCTION
-1. SQL statements that conform to the regular expression `^\s*SELECT\s+\*\s+FROM\s+blocks\s+.*` will enable the default block query mode.
- - This regular expression is configured in `config.query.regs.blocks` in `/src/script/module/config.js`
- - example: `SELECT * FROM blocks WHERE content LIKE '%Content block%'`
-2. Partial template field parsing support.
- - `.prefix{.field}`
- - `prefix`: prefix field
- - `block`: Widget block.
- - `parent`: The parent block of the pendant block.
- - `root`: The document block in which the pendant block resides.
- - `field`: attribute field
- - The field name of the `blocks` table in the database.
-3. Normal mode
- - Use field aliases prefix to define query display styles.
- - `__hidden__alias0`:
- - This field does not appear in the query results.
- - `__ref__alias1`:
- - The field is rendered as a block reference.
- - example: `(( ""))`
- - `__link__alias2`:
- - The field is rendered as a block link.
- - example: `[](siyuan://blocks/)`
- - `__raw__alias3`:
- - The field is rendered as the original value (inline code style).
- - example: `` `` ``
- - `__date__alias4`:
- - The field is rendered as a date.
- - example: `yyyy-MM-dd`
- - `__time__alias5`:
- - The field is rendered as a time.
- - example: `HH:mm:ss`
- - `__datetime__alias6`:
- - The field is rendered as a datetime.
- - example: `yyyy-MM-dd HH:mm:ss`
- - `___s__alias7`:
- - The field is rendered as strikethrough.
- - example: `~~~~`
- - `___u__alias8`:
- - The field is rendered as underline.
- - example: ``
- - `___em__alias9`:
- - The field is rendered as emphasis.
- - example: `**`
- - `__tag__alias10`:
- - The field is rendered as tag.
- - example: ``
- - `__kbd__alias11`:
- - The field is rendered as keyboard.
- - example: `~~`
- - `__sub__alias12`:
- - The field is rendered as subscript.
- - example: `^^`
- - `__sup__alias13`:
- - The field is rendered as superscript.
- - example: `##`
- - `__code__alias14`:
- - The field is rendered as inline code.
- - example: `` `` ``
- - `__mark__alias15`:
- - The field is rendered as mark.
- - example: `====`
- - `__math__alias16`:
- - The field is rendered as math formula.
- - example: `$$`
- - `__strong__alias17`:
- - The field is rendered as weightbold.
- - example: `****`
- - `__pre__alias7`:
- - The field is rendered as a preview (rendering the markdown row-level identifier).
- - example: ``
- - Use field aliases prefix to define query result field order.
- - `____alias8`:
- - The field can be placed in front of the query style prefix field.
- - example:
- - `__1____pre__alias9`
- - `__02____raw__alias10`
- - Displays the original value of the query result by default (using inline code).
+1. Click the Auto query check box to automatically query once the next time you open the page.
+2. SQL statements that conform to the regular expression `^\s*SELECT\s+\*\s+FROM\s+blocks\s+.*` will enable the default block query mode.
+
+ * This regular expression is configured in `config.query.regs.blocks` in `/src/script/module/config.js`
+ * Example: `SELECT * FROM blocks WHERE content LIKE '%Content block%'`
+ * In this mode, the query result rendering style is controlled with the following configuration options.
+
+ * **TODO**
+3. Queries that do not conform to the default block query mode are normal query mode
+
+ * Example:
+
+ * Query the help document `请从这里开始` and all of its subordinate documents.
+
+ ```sql
+ SELECT
+ '[' || b.content || '](siyuan://blocks/' || b.id || ')' AS __1____pre__文档标题,
+ b.hpath AS __2__文档路径
+ FROM
+ blocks AS b
+ WHERE
+ b.type = 'd'
+ AND b.hpath LIKE '%请从这里开始%'
+ ORDER BY
+ b.path
+ LIMIT 10
+ ```
+ * Query all tables in Siyuan database.
+
+ ```sql
+ SELECT
+ *
+ FROM
+ sqlite_master
+ ```
+ * Query all fields in the `blocks` table of Siyuan database.
+
+ ```sql
+ PRAGMA table_info('blocks')
+ ```
+ * Customized property views.
+
+ ```sql
+ SELECT
+ '[' || b.content || '](siyuan://blocks/' || a.block_id || ')' AS __1____pre__Title,
+ MAX(
+ CASE
+ WHEN a.name = 'name' THEN a.value
+ ELSE NULL
+ END
+ ) AS __2____kbd__Name,
+ MAX(
+ CASE
+ WHEN a.name = 'alias' THEN REPLACE(
+ '' || a.value || '',
+ ',',
+ '
'
+ )
+ ELSE NULL
+ END
+ ) AS __3____pre__Alias,
+ MAX(
+ CASE
+ WHEN a.name = 'memo' THEN REPLACE(
+ '' || a.value || '',
+ ',',
+ '
'
+ )
+ ELSE NULL
+ END
+ ) AS __3____pre__Memo
+ FROM
+ attributes AS a
+ INNER JOIN blocks AS b ON a.block_id = b.id
+ WHERE
+ (
+ a.name = 'name'
+ OR a.name = 'alias'
+ OR a.name = 'memo'
+ )
+ AND b.type = 'd'
+ GROUP BY
+ a.block_id
+ ORDER BY
+ RANDOM()
+ LIMIT
+ 10;
+ ```
+ * Use field aliases prefix to define query display styles.
+
+ * `__hidden__alias0`:
+
+ * This field does not appear in the query results.
+ * `__ref__alias1`:
+
+ * The field is rendered as a block reference.
+ * example: `(( ""))`
+ * `__link__alias2`:
+
+ * The field is rendered as a block link.
+ * example: `[](siyuan://blocks/)`
+ * `__raw__alias3`:
+
+ * The field is rendered as the original value (inline code style).
+ * example: ````
+ * `__date__alias4`:
+
+ * The field is rendered as a date.
+ * example: `yyyy-MM-dd`
+ * `__time__alias5`:
+
+ * The field is rendered as a time.
+ * example: `HH:mm:ss`
+ * `__datetime__alias6`:
+
+ * The field is rendered as a datetime.
+ * example: `yyyy-MM-dd HH:mm:ss`
+ * `___s__alias7`:
+
+ * The field is rendered as strikethrough.
+ * example: `~~~~`
+ * `___u__alias8`:
+
+ * The field is rendered as underline.
+ * example: ``
+ * `___em__alias9`:
+
+ * The field is rendered as emphasis.
+ * example: `**`
+ * `__tag__alias10`:
+
+ * The field is rendered as tag.
+ * example: ``
+ * `__kbd__alias11`:
+
+ * The field is rendered as keyboard.
+ * example: `~~`
+ * `__sub__alias12`:
+
+ * The field is rendered as subscript.
+ * example: `^^`
+ * `__sup__alias13`:
+
+ * The field is rendered as superscript.
+ * example: `##`
+ * `__code__alias14`:
+
+ * The field is rendered as inline code.
+ * example: ````
+ * `__mark__alias15`:
+
+ * The field is rendered as mark.
+ * example: `====`
+ * `__math__alias16`:
+
+ * The field is rendered as math formula.
+ * example: `$$`
+ * `__strong__alias17`:
+
+ * The field is rendered as weightbold.
+ * example: `****`
+ * `__pre__alias7`:
+
+ * The field is rendered as a preview (rendering the markdown row-level identifier).
+ * example: ``
+ * Use field aliases prefix to define query result field order.
+
+ * `____alias8`:
+
+ * The field can be placed in front of the query style prefix field.
+ * example:
+
+ * `__1____pre__alias9`
+ * `__02____raw__alias10`
+ * Displays the original value of the query result by default (using inline code).
+ * Example of a field alias prefix
+
+ * ```sql
+ SELECT
+ b.id AS __00____ref__ref,
+ b.id AS __01____link__link,
+ b.id AS __02____pre__pre,
+ b.id AS __03____raw__raw,
+ b.created AS __04____date__date,
+ b.created AS __05____time__time,
+ b.created AS __06____datetime__datetime,
+ b.id AS __07____s__s,
+ b.id AS __08____u__u,
+ b.id AS __09____em__em,
+ b.id AS __10____tag__tag,
+ b.id AS __11____kbd__kbd,
+ b.id AS __12____sub__sub,
+ b.id AS __13____sup__sup,
+ b.id AS __14____code__code,
+ b.id AS __15____mark__mark,
+ b.id AS __16____math__math,
+ b.id AS __17____strong__strong
+ FROM
+ blocks AS b
+ WHERE
+ id = '.root{.id}'
+ ```
+
+ ![字段别名前缀示例](https://cdn.jsdelivr.net/gh/Zuoqiu-Yingyi/widget-query//image/README/1648568044659.png)
+4. Partial template field parsing support
+5. Partial template field parsing support.
+
+ * `.{.}`
+
+ * ``: prefix field
+
+ * `block`: Widget block.
+ * `parent`: The parent block of the pendant block.
+ * `root`: The document block in which the pendant block resides.
+ * ``: attribute field
+
+ * The field name of the `blocks` table in the database.
+ * Example: `SELECT * FROM blocks WHERE id = '.root{.id}' content LIKE '%content blocks%'`
+
+ * Equivalent to `SELECT * FROM blocks WHERE id = '.block{.root_id}' content LIKE '%content blocks%'`
+ * Query all blocks in the document where the pendant is located that contain the word `content blocks`
## CUSTOM CONFIG
@@ -127,547 +278,34 @@ Background color status indication:
#### CONFIG EXAMPLE
```js
-/* 路径 | Path
- * <工作空间>/data/widgets/custom.js
- * /data/widgets/custom.js
+/**
+ * File Path
+ * /data/widgets/custom.js
+ * Example function:
+ * Block attributes are displayed in columns in the default block query results.
*/
-import {
- cutString,
- ReplaceSpace,
- ReplaceCRLF,
- markdown2span,
- dateFormat,
- timeFormat,
- timestampFormat,
- isEmptyString,
-} from '/widgets/Query/src/script/utils/string.js';
-
-import {
- templateParse
-} from '/widgets/Query/src/script/utils/templateParser.js';
-
-export var config = {
- token: '', // API token, 无需填写
- query: { // 查询配置
- width: '128px', // 挂件宽度
- height: '32px', // 挂件高度
- radius: '8px', // 挂件圆角
- color: {
- default: 'rgb(255, 255, 255)', // 默认颜色
- success: 'rgb(183, 223, 185)', // 成功颜色
- info: 'rgb(166, 213, 250)', // 信息颜色
- warning: 'rgb(255, 213, 153)', // 警告颜色
- error: 'rgb(250, 179, 174)', // 错误颜色
- },
- regs: {
- blocks: /^\s*SELECT\s+\*\s+FROM\s+blocks\s+.*/i, // 块查询的正则表达式
- limit: /\s+LIMIT\s+\d+/i, // SQL LIMIT 关键字正则表达式
- sort: /^__(\d+)__(.*)$/i, // 手动排序字段正则表达式
- render: /^__(\w+)__(.*)$/i, // 渲染控制字段正则表达式
- hex: /^[0-9a-fA-F]+$/, // 16 进制正则表达式
- },
- attribute: { // 块属性
- code: 'query-code', // 查询代码块
- widget: 'query-widget', // 查询挂件块
- table: 'query-table', // 查询结果表格块
- },
- sql: {
- // SQL 语句处理
- limit: { // 查询记录数量限制, 若启用且为设置 LIMIT 语句, 则在查询语句末尾添加 "LIMIT begin, end"
- enable: false, // 是否启用限制
- begin: 0, // 开始记录数
- end: 100, // 结束记录数
- },
- },
- template: { // 类似模板字段解析支持, 类似 .prefix{.field}, 目前支持的有 .root{.<挂件所在文档块的字段名>} .parent{.<挂件上级块的字段名>} .block{挂件块的字段名}
- enable: true, // 是否启用模板解析
- handler: async (data) => { // 模板解析处理函数
- return await templateParse(data);
- }
- },
- index: {
- enable: true, // 查询结果是否显示索引序号
- },
+export const config = {
+ query: {
render: {
- // 块查询部分字段渲染方案
- /**
- * 'ref': 渲染为块引用
- * 'link': 渲染为块超链接
- */
- type: 'link', // 块类型
- hpath: 'link', // 块所在文档路径
- id: 'link', // 块 ID
- parent_id: 'link', // 块的上级块 ID
- root_id: 'link', // 块所在文档 ID
-
- ial: { // 内联属性样式
- /**形状
- * 'rows': 一列中分行显示
- * 'columns': 一行中分列显示
- */
- shape: 'rows',
- /**样式
- * 's': 该字段渲染为删除线
- * 'u': 该字段渲染为下划线
- * 'em': 该字段渲染为斜体
- * 'tag': 该字段渲染为标签
- * 'kbd': 该字段渲染为按键样式
- * 'sub': 该字段渲染为下标样式
- * 'sup': 该字段渲染为上标样式
- * 'code': 该字段渲染为行内代码
- * 'mark': 该字段渲染为标记
- * 'math': 该字段渲染为公式
- * 'strong': 该字段渲染为粗体
- */
- style: {
- rows: {
- key: 'kbd', // 内联属性键样式
- value: 'code', // 内联属性值样式
- null: 'NULL', // 内联属性为空时占位符
- },
- columns: {
- key: 'kbd', // 内联属性键样式
- value: 'kbd', // 内联属性值样式
- null: '', // 内联属性为空时占位符
- },
- },
- fields: { // 内联属性字段
- forced: [], // 强制显示的 IAL 键, 为空则使用黑白名单
- ignore: [ // 需渲染的 IAL 键黑名单
- 'id',
- 'fold',
- 'style',
- 'updated',
- 'colgroup',
- 'heading-fold',
- ],
- valid: [], // 按照顺序渲染的 IAL 键白名单, 为空则全部渲染
- },
- },
- },
- limit: 'row', // 查询结果字段限制, (null 为不限制, 'len' 为限制长度, 'row' 为限制行数)
- maxlen: 64, // 查询结果每个字段最大长度
- maxrow: 3, // 查询结果每个字段最大行数
- CRLF: '
', // 换行符替换
- space: ' ', // 空白字符替换
- fields: [ // 需渲染的 blocks 表的字段, 顺序分先后
- 'type', // 内容块类型,参考((20210210103523-ombf290 "类型字段"))
- // 'content', // 去除了 Markdown 标记符的文本
- // 'fcontent', // 容器块第一个子块的内容
- 'markdown', // 包含完整 Markdown 标记符的文本
- 'ial', // 内联属性列表,形如 `{: name="value"}`
- 'hpath', // 人类可读的内容块所在文档路径
- 'created', // 创建时间
- 'updated', // 更新时间
-
- // 'id', // 内容块 ID
- // 'parent_id', // 双亲块 ID, 如果内容块是文档块则该字段为空
- // 'root_id', // 文档块 ID
- // 'box', // 笔记本 ID
- // 'path', // 内容块所在文档路径
- // 'name', // 内容块名称
- // 'alias', // 内容块别名
- // 'memo', // 内容块备注
- // 'hash', // content 字段的 SHA256 校验和
- // 'length', // content 字段文本长度
- // 'subtype', // 内容块子类型,参考((20210210103411-tcbcjja "子类型字段"))
- // 'sort', // 排序权重, 数值越小排序越靠前
- ],
- style: {
- // 查询结果样式
- table: {
- // 表格样式
- enable: true, // 是否启用使用块自定义属性设置表格样式
- attributes: [
- {
- // 表格自定义属性, 表格自动折行, 详情请参考 [siyuan-theme-dark-plus/custom-table-width.css at main · Zuoqiu-Yingyi/siyuan-theme-dark-plus](https://github.com/Zuoqiu-Yingyi/siyuan-theme-dark-plus/blob/main/style/module/custom-table-width.css)
- enable: false, // 是否启用该自定义属性
- key: 'custom-table-width', // 属性名
- value: 'auto', // 属性值
- },
- {
- // 块自定义属性, 为块设置滚动条, 详情请参考 [siyuan-theme-dark-plus/custom-render-scroll.css at main · Zuoqiu-Yingyi/siyuan-theme-dark-plus](https://github.com/Zuoqiu-Yingyi/siyuan-theme-dark-plus/blob/main/style/module/custom-render-scroll.css)
- enable: true, // 是否启用该自定义属性
- key: 'custom-render', // 属性名
- value: 'scroll', // 属性值
- },
- ],
- },
- column: {
- // 列样式, 自定义宽度的字段可以设置为 '{: style="width: 512px"}'
- content: '',
- fcontent: '',
- markdown: '',
- created: '',
- updated: '',
- type: '',
- hpath: '',
-
- id: '',
- parent_id: '',
- root_id: '',
- hash: '',
- box: '',
- path: '',
- name: '',
- alias: '',
- memo: '',
- length: '',
- subtype: '',
- ial: '',
- sort: '',
- },
- align: { // 查询结果字段对齐样式(':-' 左对齐, ':-:' 居中, '-:' 右对齐)
- content: ':-',
- fcontent: ':-',
- markdown: ':-',
- created: ':-:',
- updated: ':-:',
- type: ':-:',
- hpath: ':-',
-
- id: ':-:',
- parent_id: ':-:',
- root_id: ':-:',
- hash: ':-:',
- box: ':-:',
- path: ':-',
- name: ':-',
- alias: ':-',
- memo: ':-',
- length: '-:',
- subtype: '-:',
- ial: ':-',
- sort: '-:',
- },
- },
- filter: {
- // 查询结果过滤器
- blocks: { // 块查询的过滤
- enable: true, // 是否启用过滤
- handlers: [ // 过滤处理方法序列
- (row, data) => { // 过滤查询结果中的查询结构(查询代码块, Query 挂件块)
- // row: 查询结果一条记录
- // data: 挂件数据
- // return: 返回 true 则过滤掉当前记录, 返回 false 则不过滤
- switch (true) {
- case row.ial.indexOf(`custom-type="${config.query.attribute.code}"`) != -1:
- case row.ial.indexOf(`custom-type="${config.query.attribute.widget}"`) != -1:
- case row.ial.indexOf(`custom-type="${config.query.attribute.table}"`) != -1:
- return true;
- default:
- return false;
- }
- },
- ],
- }
- },
- rows: { // 查询结果处理方法
- ials: { // IAL 处理方法
- keys: (rows, ialParser) => {
- // 获得查询结果所有记录 IAL 键
- let keys = new Set();
- if (rows.length > 0) {
- for (let i = 0, len = rows.length; i < len; i++) {
- let ial = ialParser(rows[i].ial);
- Object.keys(ial).forEach(key => keys.add(key));
- }
- }
- return keys;
- },
- },
- },
- handler: { // 块查询结果各字段处理方法
- content: (row, ial, ...args) => {
- switch (config.query.limit) {
- case 'len':
- return markdown2span(cutString(ReplaceSpace(row.content, config.query.space), config.query.maxlen));
- case 'row':
- return markdown2span(ReplaceCRLF(cutString(row.content, undefined, config.query.maxrow), config.query.CRLF));
- default:
- return markdown2span(row.content);
- }
- },
- fcontent: (row, ial, ...args) => {
- switch (config.query.limit) {
- case 'len':
- return markdown2span(cutString(ReplaceSpace(row.fcontent, config.query.space), config.query.maxlen));
- case 'row':
- return markdown2span(ReplaceCRLF(cutString(row.fcontent, undefined, config.query.maxrow), config.query.CRLF));
- default:
- return markdown2span(row.fcontent);
- }
- },
- markdown: (row, ial, ...args) => {
- switch (config.query.limit) {
- case 'len':
- return markdown2span(cutString(ReplaceSpace(row.markdown, config.query.space), config.query.maxlen));
- case 'row':
- return markdown2span(ReplaceCRLF(cutString(row.markdown, undefined, config.query.maxrow), config.query.CRLF));
- default:
- return markdown2span(row.markdown);
- }
- },
- created: (row, ial, ...args) => {
- return timestampFormat(row.created);
- },
- updated: (row, ial, ...args) => {
- return timestampFormat(row.updated);
- },
- type: (row, ial, ...args) => {
- switch (config.query.render.type) {
- case 'link':
- return `[${config.query.map.blocktype[row.type]}](siyuan://blocks/${row.id})`;
- case 'ref':
- default:
- return `((${row.id} "${config.query.map.blocktype[row.type]}"))`;
- }
- },
- hpath: (row, ial, ...args) => {
- switch (config.query.render.hpath) {
- case 'link':
- return `[${row.hpath}](siyuan://blocks/${row.root_id})`;
- case 'ref':
- default:
- return `((${row.root_id} "${row.hpath}"))`;
- }
- },
-
- id: (row, ial, ...args) => {
- switch (config.query.render.id) {
- case 'link':
- return `[${row.id}](siyuan://blocks/${row.id})`;
- case 'ref':
- default:
- return `((${row.id} "${row.id}"))`;
- }
- },
- parent_id: (row, ial, ...args) => {
- if (isEmptyString(row.parent_id)) return '';
- else {
- switch (config.query.render.parent_id) {
- case 'link':
- return `[${row.parent_id}](siyuan://blocks/${row.parent_id})`;
- case 'ref':
- default:
- return `((${row.parent_id} "${row.parent_id}"))`;
- }
- }
- },
- root_id: (row, ial, ...args) => {
- switch (config.query.render.root_id) {
- case 'link':
- return `[${row.root_id}](siyuan://blocks/${row.root_id})`;
- case 'ref':
- default:
- return `((${row.root_id} "${row.root_id}"))`;
- }
- },
- hash: (row, ial, ...args) => {
- return `\`${row.hash}\``;
- },
- box: (row, ial, ...args) => {
- return `\`${row.box}\``;
- },
- path: (row, ial, ...args) => {
- return `\`${row.path}\``;
- },
- name: (row, ial, ...args) => {
- return markdown2span(row.name, 'kbd');
- },
- alias: (row, ial, ...args) => {
- return markdown2span(row.alias, 'kbd', /\\s+,\\s+/g);
- },
- memo: (row, ial, ...args) => {
- return markdown2span(row.memo);
- },
- length: (row, ial, ...args) => {
- return row.length;
- },
- subtype: (row, ial, ...args) => {
- return config.query.map.subtype[row.subtype];
- },
- ial: (row, ial, ...args) => {
- let ial_markdown = [];
- let ial_keys = args[0];
- switch (config.query.render.ial.shape) {
- case 'columns':
- ial_keys.forEach((key) => {
- if (ial[key]) {
- switch (key) {
- case 'icon':
- if (ial[key].startsWith(':') && ial[key].endsWith(':')) {
- // 自定义图标
- ial_markdown.push(ial[key]);
- break;
- }
- default:
- ial_markdown.push(markdown2span(ial[key], config.query.render.ial.style.columns.value));
- break;
- }
- }
- else ial_markdown.push(config.query.render.ial.style.columns.null
- ? markdown2span(config.query.render.ial.style.columns.null, config.query.render.ial.style.columns.value)
- : '');
- });
- return ial_markdown.join(' | ');
- case 'rows':
- default:
- ial_keys.forEach((key) => {
- if (config.query.render.ial.fields.forced.length > 0 || ial[key])
- console.log(key, config.query.render.ial.fields.forced, ial[key], ial);
- if (config.query.render.ial.fields.forced.length > 0 || ial[key] !== undefined) {
- let ial_key = markdown2span(key, config.query.render.ial.style.rows.key)
- let ial_value = ial[key] || (config.query.render.ial.style.rows.null
- ? markdown2span(config.query.render.ial.style.rows.null, config.query.render.ial.style.rows.value)
- : '');
- switch (key) {
- case 'icon':
- if (ial_value.startsWith(':') && ial_value.endsWith(':')) {
- // 自定义图标
- ial_markdown.push(`${ial_key}\:${ial_value}`);
- break;
- }
- default:
- ial_markdown.push(`${ial_key}\:${markdown2span(ial_value, config.query.render.ial.style.rows.value)}`);
- break;
- }
- }
- });
- return ial_markdown.join(config.query.CRLF);
- }
- },
- sort: (row, ial, ...args) => {
- return row.sort;
- },
- },
- map: {
- // 映射表
- blocktype: { // 块类型映射
- d: '文档块',
- h: '标题块',
- l: '列表块',
- i: '列表项',
- c: '代码块',
- m: '公式块',
- t: '表格块',
- b: '引述块',
- s: '超级块',
- p: '段落块',
- tb: '分隔线',
- video: '视频块',
- audio: '音频块',
- widget: '挂件块',
- iframe: 'iframe',
- query_embed: '嵌入块',
- '': '',
- null: '',
- undefined: '',
- },
- subtype: { // 子类型映射
- o: '有序列表',
- u: '无序列表',
- t: '任务列表',
- h1: '一级标题',
- h2: '二级标题',
- h3: '三级标题',
- h4: '四级标题',
- h5: '五级标题',
- h6: '六级标题',
- '': '',
- null: '',
- undefined: '',
- },
- },
- prefix: {
- // 非默认查询时字段别名前缀
- hidden: '__hidden__', // 不显示此字段,仅用于数据查询
-
- ref: '__ref__', // 该字段渲染为引用
- link: '__link__', // 该字段渲染为链接
- pre: '__pre__', // 该字段渲染为预览
- raw: '__raw__', // 该字段渲染为原始值
- date: '__date__', // 该字段渲染为日期
- time: '__time__', // 该字段渲染为时间
- datetime: '__datetime__', // 该字段渲染为日期时间
-
- s: '__s__', // 该字段渲染为删除线
- u: '__u__', // 该字段渲染为下划线
- em: '__em__', // 该字段渲染为斜体
- tag: '__tag__', // 该字段渲染为标签
- kbd: '__kbd__', // 该字段渲染为按键样式
- sub: '__sub__', // 该字段渲染为下标样式
- sup: '__sup__', // 该字段渲染为上标样式
- code: '__code__', // 该字段渲染为行内代码
- mark: '__mark__', // 该字段渲染为标记
- math: '__math__', // 该字段渲染为公式
- strong: '__strong__', // 该字段渲染为粗体
- },
- default: {
- // 非块查询的处理模式
- name: (key) => { // 字段名称处理函数
- let name = config.query.regs.sort.test(key) ? config.query.regs.sort.exec(key)[2] : key;
- return config.query.regs.render.test(name) ? config.query.regs.render.exec(name)[2] : name;
- },
- handler: (key) => { // 其他查询结果默认处理方法生成函数, key 是字段名, 返回一个处理方法
- let name = config.query.regs.sort.test(key) ? config.query.regs.sort.exec(key)[2] : key;
- switch (true) {
- case name.startsWith(config.query.prefix.ref):
- return (row, key) => `((${row[key]} "${row[key]}"))`;
- case name.startsWith(config.query.prefix.link):
- return (row, key) => `[${row[key]}](siyuan://blocks/${row[key]})`;
- case name.startsWith(config.query.prefix.pre):
- return (row, key) => markdown2span(row[key]);
- case name.startsWith(config.query.prefix.date):
- return (row, key) => dateFormat(row[key]);
- case name.startsWith(config.query.prefix.time):
- return (row, key) => timeFormat(row[key]);
- case name.startsWith(config.query.prefix.datetime):
- return (row, key) => timestampFormat(row[key]);
-
- case name.startsWith(config.query.prefix.s):
- return (row, key) => markdown2span(row[key], 's');
- case name.startsWith(config.query.prefix.u):
- return (row, key) => markdown2span(row[key], 'u');
- case name.startsWith(config.query.prefix.em):
- return (row, key) => markdown2span(row[key], 'em');
- case name.startsWith(config.query.prefix.kbd):
- return (row, key) => markdown2span(row[key], 'kbd');
- case name.startsWith(config.query.prefix.sub):
- return (row, key) => markdown2span(row[key], 'sub');
- case name.startsWith(config.query.prefix.sup):
- return (row, key) => markdown2span(row[key], 'sup');
- case name.startsWith(config.query.prefix.tag):
- return (row, key) => markdown2span(row[key], 'tag');
- case name.startsWith(config.query.prefix.mark):
- return (row, key) => markdown2span(row[key], 'mark');
- case name.startsWith(config.query.prefix.math):
- return (row, key) => markdown2span(row[key], 'math');
- case name.startsWith(config.query.prefix.strong):
- return (row, key) => markdown2span(row[key], 'strong');
-
- case name.startsWith(config.query.prefix.raw):
- case name.startsWith(config.query.prefix.code):
- default:
- return (row, key) => markdown2span(row[key], 'code');
- }
- },
- style: {
- column: '',
- align: ':-',
+ ial: {
+ shape: 'columns',
},
},
},
};
+
```
+For more configuration items, see [config.js](./src/script/module/config.js)
+
### BLOCK CUSTOM CONFIG
-- Set custom block attributes in the widget block(the Query button in your note).
- - Custom block attribute names are property in the `config` object under the file `src/script/module/config.js`.
- - For example, if you want to customize the query result field list, you can set the custom block attribute `query-fields`: `["hpath", "type", "markdown"]`, where the `config.query.fields` property will be replaced in this block.
+* Set custom block attributes in the widget block(the Query button in your note).
+
+ * Custom block attribute names are property in the `config` object under the file `src/script/module/config.js`.
+ * For example, if you want to customize the query result field list, you can set the custom block attribute `query-fields`: `["hpath", "type", "markdown"]`, where the `config.query.fields` property will be replaced in this block.
## START
@@ -675,19 +313,22 @@ The widget has been put on the shelves at [SiYuan community bazaar](https://gith
## REFERENCE & THANKS
-| Author | Project | License |
-| :---------------------------------------------- | :---------------------------------------------------------------- | :-------- |
-| **[leolee9086](https://github.com/leolee9086)** | [leolee9086/cc-baselib](https://github.com/leolee9086/cc-baselib) | *Unknown* |
+|Author|Project|License|
+| :------------------------------------------------------| :------------------------------------------------------------------| :------------|
+|**[leolee9086](https://github.com/leolee9086)**|[leolee9086/cc-baselib](https://github.com/leolee9086/cc-baselib)|*Unknown*|
PS: Sort in no particular order.
-## CONTRIBUTOR
+## CONTRIBUTORS
+
+
+
leolee9086 🐛 💻 |
@@ -701,6 +342,7 @@ PS: Sort in no particular order.
+
diff --git a/index.html b/index.html
index ec94dac..9983604 100644
--- a/index.html
+++ b/index.html
@@ -36,8 +36,8 @@
Query
-