@anyblock/any-block-core 3.4.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ABAlias.ts +298 -0
- package/ABConvertEvent.ts +307 -0
- package/ABConvertManager.ts +266 -0
- package/ABSetting.ts +114 -0
- package/LICENSE +661 -0
- package/README.md +162 -0
- package/converter/ABConvert.ts +158 -0
- package/converter/GeneratorDataTable.ts +40 -0
- package/converter/abc_c2list.ts +497 -0
- package/converter/abc_code.ts +93 -0
- package/converter/abc_deco.ts +793 -0
- package/converter/abc_dir_tree.ts +467 -0
- package/converter/abc_echarts.ts +539 -0
- package/converter/abc_ex.ts +112 -0
- package/converter/abc_list.ts +650 -0
- package/converter/abc_markmap.ts +119 -0
- package/converter/abc_mdit_container.ts +161 -0
- package/converter/abc_mermaid.ts +343 -0
- package/converter/abc_plantuml.ts +109 -0
- package/converter/abc_plantuml_tools.ts +236 -0
- package/converter/abc_table.ts +242 -0
- package/converter/abc_text.ts +237 -0
- package/demo.ts +236 -0
- package/index.min.ts +26 -0
- package/index.ts +26 -0
- package/locales/en.ts +88 -0
- package/locales/helper.ts +27 -0
- package/locales/zh-cn.ts +88 -0
- package/package.json +22 -0
- package/setting.ts +0 -0
- package/style/styles.css +1218 -0
- package/style/styles.min.css +1 -0
- package/style/styles.scss +1244 -0
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @detail
|
|
3
|
+
* 具体用法和介绍等见 README.md
|
|
4
|
+
*
|
|
5
|
+
* 依赖顺序
|
|
6
|
+
* 1. ABConvert.ts,转换器的抽象基类
|
|
7
|
+
* 2. ABConvertManager.ts,转换器的容器
|
|
8
|
+
* 3. ……,其他具体的转换器
|
|
9
|
+
*
|
|
10
|
+
* 跨平台兼容依赖问题
|
|
11
|
+
* - 在Obsidian环境,能够使用document
|
|
12
|
+
* - 在vuepress和mdit环境,他是使用纯文本来解析渲染md而非面向对象,也不依赖document。所以为了兼顾这个,需要额外安装Node.js中能使用的[jsdom](https://github.com/jsdom/jsdom)
|
|
13
|
+
*
|
|
14
|
+
* jsdom 老install失败。网上搜说:
|
|
15
|
+
* a: jsdom 依赖于 contextify,而 contextify 最近才支持 windows。安装它需要 python 和 C++ 编译器。
|
|
16
|
+
* b: jsdom 使用 contextify 在 DOM 上运行 JavaScript。而 contextify 需要本地 C++ 编译器。根据官方自述,在 Windows 平台上必须安装一堆东西
|
|
17
|
+
* 不过我后来尝试按一个回答中那样指定了版本就可以了:npm install -D jsdom@4.2.0
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
// AB转换器容器
|
|
21
|
+
import {
|
|
22
|
+
ABConvert_IOEnum,
|
|
23
|
+
type ABConvert_IOType,
|
|
24
|
+
ABConvert
|
|
25
|
+
} from './converter/ABConvert'
|
|
26
|
+
import { autoABAlias } from "./ABAlias"
|
|
27
|
+
import { ABCSetting } from "./ABSetting"
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* AB转换器的管理器。注意:使用前必须先执行:`redefine_renderMarkdown`
|
|
31
|
+
*
|
|
32
|
+
* @default
|
|
33
|
+
* 单例模式
|
|
34
|
+
* 负责转换器的:注册、寻找、依次使用
|
|
35
|
+
*/
|
|
36
|
+
export class ABConvertManager {
|
|
37
|
+
|
|
38
|
+
/** --------------------------------- 特殊函数 ---------------------------- */
|
|
39
|
+
|
|
40
|
+
/// 单例模式
|
|
41
|
+
static getInstance(): ABConvertManager {
|
|
42
|
+
if (!ABConvertManager.m_instance) {
|
|
43
|
+
ABConvertManager.m_instance = new ABConvertManager()
|
|
44
|
+
}
|
|
45
|
+
return ABConvertManager.m_instance;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/// 单例
|
|
49
|
+
private static m_instance: ABConvertManager
|
|
50
|
+
|
|
51
|
+
/// 构造函数
|
|
52
|
+
private constructor() {
|
|
53
|
+
/// 环境打印 (编译期打印)
|
|
54
|
+
// @ts-ignore 用于检查obsidian是否存在,不存在的话正常是飘红的
|
|
55
|
+
if (typeof obsidian == 'undefined' && typeof app == 'undefined') {
|
|
56
|
+
console.log('[environment]: markdown-it, without obsidian')
|
|
57
|
+
} else {
|
|
58
|
+
console.log('[environment]: obsidian')
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** --------------------------------- 处理器容器管理 --------------------- */
|
|
63
|
+
|
|
64
|
+
/// ab处理器 - 严格版,的接口与列表 (动态)
|
|
65
|
+
public list_abConvert: ABConvert[] = []
|
|
66
|
+
|
|
67
|
+
/// 处理器一览表 - 下拉框推荐
|
|
68
|
+
public getConvertOptions(){
|
|
69
|
+
return this.list_abConvert
|
|
70
|
+
.filter(item=>{
|
|
71
|
+
return item.default
|
|
72
|
+
})
|
|
73
|
+
.map(item=>{
|
|
74
|
+
return {id:item.default, name:item.name}
|
|
75
|
+
})
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** --------------------------------- 通用解耦适配 (动态) ----------------- */
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* 渲染文本为html
|
|
82
|
+
* @detail 这里需要能够被回调函数替换。从而用于接回软件自身的html渲染机制,来进行解耦
|
|
83
|
+
* @param markdown 原md
|
|
84
|
+
* @param el 要追加到的元素
|
|
85
|
+
* @param ctx Obsidian在这里需要传入 MarkdownRenderChild 类型,但为了跨平台我这里修改成可选的any类型
|
|
86
|
+
*/
|
|
87
|
+
public m_renderMarkdownFn:(markdown: string, el: HTMLElement, ctx?: any) => void = (markdown, el) => {
|
|
88
|
+
el.classList.add("markdown-rendered") // 并注意,应当在使用该函数前将el添加该css类,或者重定义时增加该条语句
|
|
89
|
+
console.error("Please use renderMarkdownFn redefine render function")
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/// 用回调函数替换重渲染器
|
|
93
|
+
public redefine_renderMarkdown(callback: (markdown: string, el: HTMLElement, ctx?: any) => void) {
|
|
94
|
+
this.m_renderMarkdownFn = callback
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** --------------------------------- 处理器的调用 ----------------------- */
|
|
98
|
+
|
|
99
|
+
static startTime: number; // cache
|
|
100
|
+
/**
|
|
101
|
+
* 自动寻找相匹配的ab处理器进行处理
|
|
102
|
+
*
|
|
103
|
+
* @detail
|
|
104
|
+
* ab转换器能根据header和content来将有段txt文本转换为html元素
|
|
105
|
+
* 主要分三个过程:
|
|
106
|
+
* 1. 预处理
|
|
107
|
+
* 2. 递归处理
|
|
108
|
+
* 3. 尾处理 (其实尾处理也可以归到预处理那)
|
|
109
|
+
* @param el 最后的渲染结果
|
|
110
|
+
* @param header 转换方式
|
|
111
|
+
* @param content 要转换的初始文本 (无前缀版本,前缀在选择器环节已经删除了)
|
|
112
|
+
* @param selectorName 选择器名,空表示未知
|
|
113
|
+
* @return 等于el,无用,后面可以删了
|
|
114
|
+
*/
|
|
115
|
+
public static autoABConvert(el:HTMLDivElement, header:string, content:string, selectorName:string = "", ctx?: any): void{
|
|
116
|
+
let prev_result: ABConvert_IOType = content // 上次转换后的结果,初始必为string
|
|
117
|
+
let prev_type: string = "string" // 上次转换后的结果的类型 (类型检测而来)
|
|
118
|
+
let prev_type2: ABConvert_IOEnum = ABConvert_IOEnum.text // 上次转换后的结果的类型 (接口声明而来)
|
|
119
|
+
let prev_processor; // 上一次转换的处理器
|
|
120
|
+
let prev = { // 组合在一起是为了引用传参
|
|
121
|
+
prev_result, prev_type, prev_type2, prev_processor
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (false && ABCSetting.is_debug) ABConvertManager.startTime = performance.now();
|
|
125
|
+
{
|
|
126
|
+
header = autoABAlias(header, selectorName, prev_result as string);
|
|
127
|
+
let list_header = header.split("|")
|
|
128
|
+
prev_result = this.autoABConvert_runConvert(el, list_header, prev, ctx)
|
|
129
|
+
this.autoABConvert_last(el, header, selectorName, prev, ctx)
|
|
130
|
+
}
|
|
131
|
+
if (false && ABCSetting.is_debug) {
|
|
132
|
+
const endTime = performance.now();
|
|
133
|
+
console.log(`Takes ${(endTime - ABConvertManager.startTime).toFixed(2)} ms when selector "${selectorName}" header "${header}"`);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* autoABConvert的递归子函数
|
|
139
|
+
* @param el
|
|
140
|
+
* @param list_header
|
|
141
|
+
* @param prev_result 上次转换后的结果
|
|
142
|
+
* @param prev_type 上次转换后的结果的类型 (类型检测而来, typeof类型)
|
|
143
|
+
* @param prev_type2 上次转换后的结果的类型 (接口声明而来, IOEnum类型)
|
|
144
|
+
* @returns 递归转换后的结果
|
|
145
|
+
*/
|
|
146
|
+
private static autoABConvert_runConvert(el:HTMLDivElement, list_header:string[], prev:any, ctx?: any):any{
|
|
147
|
+
// 循环header组,直到遍历完文本处理器或遇到渲染处理器
|
|
148
|
+
for (let item_header of list_header){ // TODO 因为可能被插入新的“中间自动转换器”,要么for替换成递归,要么都在头部预处理时弄完
|
|
149
|
+
for (let abReplaceProcessor of ABConvertManager.getInstance().list_abConvert){
|
|
150
|
+
// 通过header寻找处理器
|
|
151
|
+
if (typeof(abReplaceProcessor.match)=='string'){if (abReplaceProcessor.match!=item_header) continue}
|
|
152
|
+
else {if (!abReplaceProcessor.match.test(item_header)) continue}
|
|
153
|
+
// TODO 删除旧的别名系统
|
|
154
|
+
// 检查是否有别名。若是,递归
|
|
155
|
+
if(abReplaceProcessor.process_alias){
|
|
156
|
+
// 别名支持引用正则参数
|
|
157
|
+
let alias = abReplaceProcessor.process_alias
|
|
158
|
+
;(()=>{
|
|
159
|
+
if (abReplaceProcessor.process_alias.indexOf("%")<0) return
|
|
160
|
+
if (typeof(abReplaceProcessor.match)=="string") return
|
|
161
|
+
const matchs = item_header.match(abReplaceProcessor.match)
|
|
162
|
+
if (!matchs) return
|
|
163
|
+
const len = matchs.length
|
|
164
|
+
if (len==1) return
|
|
165
|
+
// replaceAlias
|
|
166
|
+
for (let i=1; i<len; i++){
|
|
167
|
+
if (!matchs[i]) continue
|
|
168
|
+
alias = alias.replace(RegExp(`%${i}`), matchs[i]) /** @bug 按理应该用`(?<!\\)%${i}`,但ob不支持正则的向前查找 */
|
|
169
|
+
}
|
|
170
|
+
})()
|
|
171
|
+
prev.prev_result = this.autoABConvert_runConvert(el, alias.split("|"), prev, ctx)
|
|
172
|
+
}
|
|
173
|
+
// 若不是,使用process方法
|
|
174
|
+
else if(abReplaceProcessor.process){
|
|
175
|
+
// (1) 检查输入类型
|
|
176
|
+
if (abReplaceProcessor.process_param != prev.prev_type2){
|
|
177
|
+
// TODO,两个自动处理器,后面要被别名系统替换掉
|
|
178
|
+
if (abReplaceProcessor.process_param==ABConvert_IOEnum.el &&
|
|
179
|
+
prev.prev_type2==ABConvert_IOEnum.text
|
|
180
|
+
){ // 需要输入html,实际输入md,则插入一个md->html
|
|
181
|
+
const subEl: HTMLDivElement = document.createElement("div"); el.appendChild(subEl);
|
|
182
|
+
ABConvertManager.getInstance().m_renderMarkdownFn(prev.prev_result, subEl);
|
|
183
|
+
prev.prev_result = el
|
|
184
|
+
prev.prev_type = typeof(prev.prev_result)
|
|
185
|
+
prev.prev_type2 = ABConvert_IOEnum.el
|
|
186
|
+
prev.prev_processor = "md"
|
|
187
|
+
}
|
|
188
|
+
else if (abReplaceProcessor.process_param==ABConvert_IOEnum.text &&
|
|
189
|
+
(prev.prev_type2==ABConvert_IOEnum.list_stream || prev.prev_type2==ABConvert_IOEnum.c2list_stream)
|
|
190
|
+
) { // 需要输入text,实际输入object,则插入一个object->text
|
|
191
|
+
prev.prev_result = JSON.stringify(prev.prev_result, null, 2)
|
|
192
|
+
prev.prev_type = typeof(prev.prev_result)
|
|
193
|
+
prev.prev_type2 = ABConvert_IOEnum.text
|
|
194
|
+
prev.prev_processor = "stream to text"
|
|
195
|
+
}
|
|
196
|
+
else if (abReplaceProcessor.process_param==ABConvert_IOEnum.text &&
|
|
197
|
+
prev.prev_type2==ABConvert_IOEnum.json
|
|
198
|
+
) {
|
|
199
|
+
prev.prev_type2 = ABConvert_IOEnum.text
|
|
200
|
+
prev.prev_processor = "json to text"
|
|
201
|
+
}
|
|
202
|
+
else{
|
|
203
|
+
console.warn(`处理器输入类型错误, id:${abReplaceProcessor.id}, virtualParam:${abReplaceProcessor.process_param}, realParam:${prev.prev_type2}`);
|
|
204
|
+
break
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// (2) 执行处理器
|
|
209
|
+
prev.prev_result = abReplaceProcessor.process(el, item_header, prev.prev_result, ctx)
|
|
210
|
+
prev.prev_type = typeof(prev.prev_result)
|
|
211
|
+
prev.prev_type2 = abReplaceProcessor.process_return as ABConvert_IOEnum
|
|
212
|
+
prev.prev_processor = abReplaceProcessor.process
|
|
213
|
+
|
|
214
|
+
// (3) 检查输出类型
|
|
215
|
+
// if(typeof(prev_result) == "string"){prev_type = ABConvert_IOEnum.text}
|
|
216
|
+
// 下行换成了下下行。因为下行在mdit/jsdom环境可能报错:Right-hand side of 'instanceof' is not callable
|
|
217
|
+
//else if (prev_result instanceof HTMLElement){prev_type = ABConvert_IOType.el}
|
|
218
|
+
// else if (typeof(prev_result) == "object"){prev_type = ABConvert_IOEnum.el}
|
|
219
|
+
// else {
|
|
220
|
+
// console.warn(`处理器输出类型错误, id:${abReplaceProcessor.id}, virtualReturn:${abReplaceProcessor.process_return}, realReturn${prev_type}`);
|
|
221
|
+
// break
|
|
222
|
+
// }
|
|
223
|
+
}
|
|
224
|
+
else{
|
|
225
|
+
console.warn("处理器必须实现process或process_alias方法")
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
return prev
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* 子函数,后处理/尾处理,主要进行末尾追加指令
|
|
234
|
+
*/
|
|
235
|
+
private static autoABConvert_last (el:HTMLDivElement, header:string, selectorName:string, prev:any, ctx?: any):any{
|
|
236
|
+
// text内容,则给一个md渲染器
|
|
237
|
+
if (prev.prev_type == "string" && prev.prev_type2 == ABConvert_IOEnum.text) {
|
|
238
|
+
const subEl = document.createElement("div"); el.appendChild(subEl);
|
|
239
|
+
ABConvertManager.getInstance().m_renderMarkdownFn(prev.prev_result as string, subEl);
|
|
240
|
+
prev.prev_result = el; prev.prev_type = "object"; prev.prev_type2 = ABConvert_IOEnum.el; prev.process = "md";
|
|
241
|
+
}
|
|
242
|
+
// json内容/数组内容,则用代码块表示
|
|
243
|
+
else if (prev.prev_type == "string" && prev.prev_type2 == ABConvert_IOEnum.json) {
|
|
244
|
+
const code_str:string = "```json\n" + prev.prev_result + "\n```\n"
|
|
245
|
+
const subEl = document.createElement("div"); el.appendChild(subEl);
|
|
246
|
+
ABConvertManager.getInstance().m_renderMarkdownFn(code_str, subEl);
|
|
247
|
+
prev.prev_result = el; prev.prev_type = "object"; prev.prev_type2 = ABConvert_IOEnum.el; prev.process = "show_json";
|
|
248
|
+
}
|
|
249
|
+
// 数组流,用代码块表示
|
|
250
|
+
else if (prev.prev_type == "object" &&
|
|
251
|
+
(prev.prev_type2 == ABConvert_IOEnum.list_stream || prev.prev_type2 == ABConvert_IOEnum.c2list_stream || prev.prev_type2 == ABConvert_IOEnum.json)
|
|
252
|
+
) {
|
|
253
|
+
const code_str:string = "```json\n" + JSON.stringify(prev.prev_result, null, 2) + "\n```\n"
|
|
254
|
+
const subEl = document.createElement("div"); el.appendChild(subEl);
|
|
255
|
+
ABConvertManager.getInstance().m_renderMarkdownFn(code_str, subEl);
|
|
256
|
+
prev.prev_result = el; prev.prev_type = "object"; prev.prev_type2 = ABConvert_IOEnum.el; prev.process = "show_listStream";
|
|
257
|
+
}
|
|
258
|
+
else if (prev.prev_type == "object" && prev.prev_type2 == ABConvert_IOEnum.el) {
|
|
259
|
+
return prev
|
|
260
|
+
}
|
|
261
|
+
else {
|
|
262
|
+
console.warn("other type in tail, can not tail processor:", prev.prev_type, prev.prev_type2, prev.prev_result)
|
|
263
|
+
}
|
|
264
|
+
return prev
|
|
265
|
+
}
|
|
266
|
+
}
|
package/ABSetting.ts
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @attention 注意: 该文件以前名字为 `ABReg.ts`,注意历史遗留问题
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* ABConvert的设置
|
|
7
|
+
*
|
|
8
|
+
* 全平台通用设置
|
|
9
|
+
*
|
|
10
|
+
* @detail
|
|
11
|
+
* 在 obsidian 环境中,需要保证与 obsidian 设置的一致性 (可以被obsidian的设置修改)
|
|
12
|
+
* 如果没有GUI设置页面,可以人工修改
|
|
13
|
+
*/
|
|
14
|
+
export const ABCSetting: {
|
|
15
|
+
is_debug: boolean,
|
|
16
|
+
env: "obsidian"|"obsidian-min"|"obsidian-pro"|"app"|"markdown-it"|"remark",
|
|
17
|
+
// 某些环境的独占 api,其他环境用不上
|
|
18
|
+
obsidian: {
|
|
19
|
+
global_app: any,
|
|
20
|
+
global_ctx: any, // MarkdownPostProcessorContext类型, obsidian专用
|
|
21
|
+
mermaid?: Promise<any>, // obsidian专用,obsidian 如何渲染mermaid
|
|
22
|
+
},
|
|
23
|
+
pro: {
|
|
24
|
+
disable: boolean, // 禁用 pro 版的扩展功能,变为非 pro 版
|
|
25
|
+
enable_callout_selector: boolean, // 是否启用 callout 选择器并自动替换 callout 为可编辑 callout
|
|
26
|
+
enable_alias_override: boolean, // 启用别名覆盖 (启用后 pro 处理器会使用旧处理器名,并覆盖掉之前的行为)
|
|
27
|
+
editableblock_defaultRender: 'readmode' | 'realtime' | 'textarea', // 可编辑块的默认渲染模式
|
|
28
|
+
create_decorations: undefined | ((
|
|
29
|
+
customData: {
|
|
30
|
+
cancelFlag: number[];
|
|
31
|
+
updateMode: string | number;
|
|
32
|
+
},
|
|
33
|
+
oldView: any, tr: any, decorationSet: any | undefined, create_widget: any
|
|
34
|
+
) => any)
|
|
35
|
+
},
|
|
36
|
+
// 运行时状态
|
|
37
|
+
state: {
|
|
38
|
+
language: 'en'|'zh'|'zh-TW'|string // 语言 (字典语言标志: 本地化语言名转标志, 不存在语言转en,自动选择转实际语言)
|
|
39
|
+
},
|
|
40
|
+
} = {
|
|
41
|
+
is_debug: false,
|
|
42
|
+
env: "obsidian",
|
|
43
|
+
// 某些环境的独占 api,其他环境用不上
|
|
44
|
+
obsidian: {
|
|
45
|
+
global_app: null,
|
|
46
|
+
global_ctx: null,
|
|
47
|
+
mermaid: undefined,
|
|
48
|
+
},
|
|
49
|
+
pro: {
|
|
50
|
+
disable: false,
|
|
51
|
+
enable_callout_selector: true,
|
|
52
|
+
enable_alias_override: true,
|
|
53
|
+
editableblock_defaultRender: 'readmode',
|
|
54
|
+
create_decorations: undefined
|
|
55
|
+
},
|
|
56
|
+
state: {
|
|
57
|
+
language: 'en',
|
|
58
|
+
},
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* 正则匹配规则
|
|
63
|
+
*
|
|
64
|
+
* @attention 注意:修改正则要注意小括号的位置是否对应,不然还要去修改索引
|
|
65
|
+
*/
|
|
66
|
+
export const ABReg = {
|
|
67
|
+
/**
|
|
68
|
+
* AB块头部
|
|
69
|
+
*
|
|
70
|
+
* 例子:` > - > %%[d]:%% `
|
|
71
|
+
*
|
|
72
|
+
* - 前缀部分
|
|
73
|
+
* - $1: 前缀 | ` > - > ` | ((\s|>\s|-\s|\*\s|\+\s)*)
|
|
74
|
+
* - $2: 无用 | `>` | (\s|>\s|-\s|\*\s|\+\s)
|
|
75
|
+
* - 指令部分
|
|
76
|
+
* - $3: 无用 | `%%` | (%%)?
|
|
77
|
+
* - $4:无用 | `[header]` | (\[((?!toc)[0-9a-zA-Z].*)\])
|
|
78
|
+
* - $5:指令 | `header` | (?!toc)[0-9a-zA-Z].*)
|
|
79
|
+
* - $6: 无用 | `%%` | (%%)?
|
|
80
|
+
*
|
|
81
|
+
* 注意:
|
|
82
|
+
* - (?!\[) (?!\toc) 这种向后否定语句不作为一个匹配项
|
|
83
|
+
* - 允许 `%%` 和 `:` 的规则是V3新增的
|
|
84
|
+
* - 不允许 `::` 是避免与 dataview 的 inline property 冲突
|
|
85
|
+
*/
|
|
86
|
+
// 有前缀版本(给选择器用)
|
|
87
|
+
reg_header: /^((\s|>\s|-\s|\*\s|\+\s)*)(%%)?(\[((?!toc|TOC|\!|< )[\|\!#:;\(\)\s0-9a-zA-Z\u4e00-\u9fa5](?!.*::).*)\]):?\3\s*$/, // 可以用空`|`来解除首字符限制。(`|`注意:可以用来弄严格模式,`#`注意:建议后面空一格避免变成“标签”,`!`注意:别易误触发 `> [!note]`
|
|
88
|
+
reg_header_up:/^((\s|>\s|-\s|\*\s|\+\s)*)(%%)?(\[((?!toc|TOC|\!)< [\|\!#:;\(\)\s0-9a-zA-Z\u4e00-\u9fa5](?!.*::).*)\]):?\3\s*$/, // 向上检查标志的 头部选择器
|
|
89
|
+
|
|
90
|
+
reg_mdit_head:/^((\s|>\s|-\s|\*\s|\+\s)*)(::::*)\s?(.*)/,
|
|
91
|
+
reg_mdit_tail:/^((\s|>\s|-\s|\*\s|\+\s)*)(::::*)/,
|
|
92
|
+
reg_list: /^((\s|>\s|-\s|\*\s|\+\s)*)(-\s|\*\s|\+\s)(.*)/, //: /^\s*(>\s)*-\s(.*)$/
|
|
93
|
+
reg_code: /^((\s|>\s|-\s|\*\s|\+\s)*)(````*|~~~~*)(.*)/, //: /^\s*(>\s|-\s)*(````*|~~~~*)(.*)$/
|
|
94
|
+
reg_quote: /^((\s|>\s|-\s|\*\s|\+\s)*)(>\s)(.*)/, // `- > ` 不匹配,要认为这种是列表
|
|
95
|
+
reg_heading: /^((\s|>\s|-\s|\*\s|\+\s)*)(\#+\s)(.*)/,
|
|
96
|
+
reg_table: /^((\s|>\s|-\s|\*\s|\+\s)*)(\|(.*)\|)/,
|
|
97
|
+
|
|
98
|
+
// 无前缀版本(给处理器用,处理器不需要处理前缀,前缀在选择器阶段已经被去除了)
|
|
99
|
+
reg_header_noprefix: /^((\s)*)(%%)?(\[((?!toc|TOC|\!|< )[\|\!#:;\(\)\s0-9a-zA-Z\u4e00-\u9fa5](?!.*::).*)\]):?\3\s*$/,
|
|
100
|
+
reg_header_up_noprefix:/^((\s)*)(%%)?(\[((?!toc|TOC|\!)< [\|\!#:;\(\)\s0-9a-zA-Z\u4e00-\u9fa5](?!.*::).*)\]):?\3\s*$/,
|
|
101
|
+
|
|
102
|
+
reg_mdit_head_noprefix:/^((\s)*)(::::*)\s?(.*)/,
|
|
103
|
+
reg_mdit_tail_noprefix:/^((\s)*)(::::*)/,
|
|
104
|
+
reg_list_noprefix: /^((\s)*)(-\s|\*\s|\+\s)(.*)/,
|
|
105
|
+
reg_code_noprefix: /^((\s)*)(````*|~~~~*)(.*)/,
|
|
106
|
+
reg_quote_noprefix: /^((\s)*)(>\s)(.*)/,
|
|
107
|
+
reg_heading_noprefix: /^((\s)*)(\#+\s)(.*)/,
|
|
108
|
+
reg_table_noprefix: /^((\s)*)(\|(.*)\|)/,
|
|
109
|
+
|
|
110
|
+
reg_emptyline_noprefix:/^\s*$/,
|
|
111
|
+
reg_indentline_noprefix:/^\s+?\S/,
|
|
112
|
+
|
|
113
|
+
inline_split: /\| |, |, |\. |。 |: |: /, // 内联切分。`|`或全角符号+一空格,半角符号+两空格 (后者由于空格压缩,若经历了重渲染可能有问题)
|
|
114
|
+
}
|