markdown-it-any-block 3.2.10-beta5 → 3.2.11
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/README.md +2 -0
- package/dist/mdit-any-block.cjs +189 -201
- package/dist/mdit-any-block.cjs.map +1 -1
- package/dist/mdit-any-block.js +189 -201
- package/dist/mdit-any-block.js.map +1 -1
- package/index_mdit.ts +87 -60
- package/package.json +50 -50
- package/styles.css +9 -1
package/index_mdit.ts
CHANGED
|
@@ -218,7 +218,8 @@ function abSelector_squareInline(md: MarkdownIt, options?: Partial<Options>): vo
|
|
|
218
218
|
}
|
|
219
219
|
|
|
220
220
|
/**
|
|
221
|
-
* 选择 anyBlock 块 - :::规则 (vuepress-mdit 版本)
|
|
221
|
+
* 选择 anyBlock 块 - :::规则 (vuepress-mdit 版本),
|
|
222
|
+
* TODO: 该函数应该可以被abSelector_container替代,测试后删除
|
|
222
223
|
*
|
|
223
224
|
* @detail 选择 `:::anyBlock` 包裹的片段
|
|
224
225
|
*/
|
|
@@ -246,15 +247,15 @@ function abSelector_container_vuepress(md: MarkdownIt, options?: Partial<Options
|
|
|
246
247
|
}
|
|
247
248
|
|
|
248
249
|
/**
|
|
249
|
-
* 选择 anyBlock 块 - :::规则 (
|
|
250
|
+
* 选择 anyBlock 块 - :::规则 (通用版本)
|
|
250
251
|
*
|
|
251
252
|
* @detail
|
|
252
253
|
* 注意:
|
|
253
|
-
* -
|
|
254
|
-
* -
|
|
254
|
+
* - 基于 https://github.com/mdit-plugins/mdit-plugins 下的 mdit-tab 重写了 mdit 选择器解析规则
|
|
255
|
+
* - 应该不会与 markdown-it-container 的mdit插件冲突,(待测试)
|
|
255
256
|
*
|
|
256
257
|
* 该函数负责识别和处理Markdown中的:::容器语法,ABConvert支持的container容器都能被支持
|
|
257
|
-
* 例如 :::col、:::tab
|
|
258
|
+
* 例如 :::col、:::tab、:::card
|
|
258
259
|
*
|
|
259
260
|
* 工作流程:
|
|
260
261
|
* 1. 识别以:::开头的行
|
|
@@ -265,69 +266,95 @@ function abSelector_container_vuepress(md: MarkdownIt, options?: Partial<Options
|
|
|
265
266
|
* @param md MarkdownIt实例
|
|
266
267
|
* @param options 可选配置参数
|
|
267
268
|
*/
|
|
268
|
-
function
|
|
269
|
+
function abSelector_container(md: MarkdownIt, options?: Partial<Options>): void {
|
|
269
270
|
md.block.ruler.before('fence', 'AnyBlockMditContainer', (
|
|
270
|
-
state
|
|
271
|
+
state, startLine, endLine, silent
|
|
271
272
|
): boolean => {
|
|
272
|
-
//
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
let nestLevel = 0;
|
|
286
|
-
|
|
287
|
-
// 逐行解析内容,直到遇到结束标记
|
|
288
|
-
while (nextLine < endLine) {
|
|
289
|
-
const lineStart = state.bMarks[nextLine] + state.tShift[nextLine];
|
|
290
|
-
const lineEnd = state.eMarks[nextLine];
|
|
291
|
-
const line = state.src.slice(lineStart, lineEnd);
|
|
292
|
-
const trimmedLine = line.trim();
|
|
293
|
-
|
|
294
|
-
// 检查是否为围栏块标记
|
|
295
|
-
if (trimmedLine.startsWith(':::')) {
|
|
296
|
-
if (trimmedLine === ':::') {
|
|
297
|
-
// 结束标记
|
|
298
|
-
if (nestLevel === 0) {
|
|
299
|
-
break;
|
|
300
|
-
} else {
|
|
301
|
-
// 嵌套块的结束
|
|
302
|
-
nestLevel--;
|
|
303
|
-
content.push(line);
|
|
304
|
-
}
|
|
305
|
-
} else {
|
|
306
|
-
// 开始标记
|
|
307
|
-
nestLevel++;
|
|
308
|
-
content.push(line);
|
|
309
|
-
}
|
|
310
|
-
} else {
|
|
311
|
-
// 收集内容
|
|
312
|
-
content.push(line);
|
|
313
|
-
}
|
|
314
|
-
nextLine++;
|
|
273
|
+
const typeNames = ["mditABDemo"] // 在这里设置需要接管ab块类型,其余放行
|
|
274
|
+
let start = state.bMarks[startLine];
|
|
275
|
+
let max = state.eMarks[startLine];
|
|
276
|
+
|
|
277
|
+
// 快速检查第一个字符,过滤掉非容器块
|
|
278
|
+
if (state.src[start] !== ":") return false;
|
|
279
|
+
|
|
280
|
+
let pos = start + 1;
|
|
281
|
+
|
|
282
|
+
// 检查标记字符串的剩余部分
|
|
283
|
+
while (pos <= max) {
|
|
284
|
+
if (state.src[pos] !== ":") break;
|
|
285
|
+
pos++;
|
|
315
286
|
}
|
|
316
287
|
|
|
317
|
-
|
|
288
|
+
const markerCount = pos - start;
|
|
289
|
+
|
|
290
|
+
// 需要至少3个冒号才视为有效标记
|
|
291
|
+
if (markerCount < 3) return false;
|
|
292
|
+
|
|
293
|
+
const markup = state.src.slice(start, pos);
|
|
294
|
+
const ab_mdit_header = state.src.slice(pos, max);
|
|
295
|
+
|
|
296
|
+
// 检查是否在允许的类型列表中
|
|
297
|
+
if (!typeNames.includes(ab_mdit_header.split("|")[0].trim())) return false;
|
|
298
|
+
|
|
299
|
+
// 静默模式下直接返回验证成功
|
|
318
300
|
if (silent) return true;
|
|
319
301
|
|
|
320
|
-
|
|
321
|
-
|
|
302
|
+
const ab_startLine = startLine;
|
|
303
|
+
let nextLine = startLine;
|
|
304
|
+
let autoClosed = false;
|
|
305
|
+
|
|
306
|
+
let ab_content = "";
|
|
307
|
+
|
|
308
|
+
// 搜索块的结束标记
|
|
309
|
+
while (
|
|
310
|
+
// unclosed block should be auto closed by end of document.
|
|
311
|
+
// also block seems to be auto closed by end of parent
|
|
312
|
+
nextLine < endLine
|
|
313
|
+
) {
|
|
314
|
+
nextLine++;
|
|
315
|
+
start = state.bMarks[nextLine];
|
|
316
|
+
max = state.eMarks[nextLine];
|
|
317
|
+
|
|
318
|
+
if (start < max && state.sCount[nextLine] < state.blkIndent)
|
|
319
|
+
// non-empty line with negative indent should stop the list:
|
|
320
|
+
// - ```
|
|
321
|
+
// test
|
|
322
|
+
break;
|
|
323
|
+
if (
|
|
324
|
+
// match start
|
|
325
|
+
state.src[start] === ":" &&
|
|
326
|
+
// closing fence should be indented less than 4 spaces
|
|
327
|
+
state.sCount[nextLine] - state.blkIndent < 4
|
|
328
|
+
) {
|
|
329
|
+
// check rest of marker
|
|
330
|
+
for (pos = start + 1; pos <= max; pos++)
|
|
331
|
+
if (state.src[pos] !== ":") break;
|
|
332
|
+
|
|
333
|
+
// closing code fence must be at least as long as the opening one
|
|
334
|
+
if (pos - start >= markerCount) {
|
|
335
|
+
// make sure tail has spaces only
|
|
336
|
+
pos = state.skipSpaces(pos);
|
|
337
|
+
|
|
338
|
+
if (pos >= max) {
|
|
339
|
+
// found!
|
|
340
|
+
autoClosed = true;
|
|
341
|
+
break;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
ab_content += "\n" + state.src.substring(start, max);
|
|
347
|
+
}
|
|
322
348
|
|
|
323
|
-
|
|
324
|
-
|
|
349
|
+
state.line = nextLine + (autoClosed ? 1 : 0);
|
|
350
|
+
|
|
351
|
+
const token = state.push('fence', 'code', 0)
|
|
325
352
|
token.info = "AnyBlock"
|
|
326
|
-
token.content = `[${
|
|
327
|
-
|
|
328
|
-
token.
|
|
329
|
-
token.markup = ':::::';
|
|
353
|
+
token.content = `[${ab_mdit_header}]\n${ab_content}`
|
|
354
|
+
token.map = [ab_startLine, nextLine]
|
|
355
|
+
token.markup = markup;
|
|
330
356
|
token.nesting = 0;
|
|
357
|
+
|
|
331
358
|
return true
|
|
332
359
|
});
|
|
333
360
|
}
|
|
@@ -419,6 +446,6 @@ export function ab_mdit(md: MarkdownIt, options?: Partial<Options>): void {
|
|
|
419
446
|
ABCSetting.env = "vuepress"
|
|
420
447
|
|
|
421
448
|
md.use(abSelector_squareInline)
|
|
422
|
-
md.use(
|
|
449
|
+
md.use(abSelector_container)
|
|
423
450
|
md.use(abRender_fence)
|
|
424
451
|
}
|
package/package.json
CHANGED
|
@@ -1,50 +1,50 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "markdown-it-any-block",
|
|
3
|
-
"version": "3.2.
|
|
4
|
-
"description": "```typescript\r import { ABConvertManager } from \"ABConvertManager\"",
|
|
5
|
-
"types": "@types/index_mdit.d.ts",
|
|
6
|
-
"type": "module",
|
|
7
|
-
"main": "dist/mdit-any-block.cjs",
|
|
8
|
-
"exports": {
|
|
9
|
-
".": {
|
|
10
|
-
"import": "./dist/mdit-any-block.js",
|
|
11
|
-
"require": "./dist/mdit-any-block.cjs"
|
|
12
|
-
}
|
|
13
|
-
},
|
|
14
|
-
"scripts": {
|
|
15
|
-
"test": "echo \"Error: no test specified\" && exit 1",
|
|
16
|
-
"build": "pnpm build_vite",
|
|
17
|
-
"build_tsc": "pnpm copy_abc_style && tsc",
|
|
18
|
-
"build_tsup": "pnpm copy_abc_style && tsup",
|
|
19
|
-
"build_vite": "pnpm copy_abc_style && vite build",
|
|
20
|
-
"build_rollup": "pnpm copy_abc_style && rollup -c rollup.config.ts --configPlugin esbuild",
|
|
21
|
-
"build_test": "echo '区别见README文件的 `构建测试` 一节'",
|
|
22
|
-
"prepublishOnly": "pnpm build",
|
|
23
|
-
"copy_abc_style": "copyfiles --flat ../../src/ABConverter/style/styles.css ./"
|
|
24
|
-
},
|
|
25
|
-
"author": "LincZero",
|
|
26
|
-
"license": "GNU Affero General Public License v3.0",
|
|
27
|
-
"peerDependencies": {
|
|
28
|
-
"markdown-it": "^14.1.0"
|
|
29
|
-
},
|
|
30
|
-
"dependencies": {
|
|
31
|
-
"jsdom": "^26.0.0",
|
|
32
|
-
"markdown-it": "^14.1.0",
|
|
33
|
-
"plantuml-encoder": "^1.4.0"
|
|
34
|
-
},
|
|
35
|
-
"devDependencies": {
|
|
36
|
-
"@rollup/plugin-alias": "^5.1.1",
|
|
37
|
-
"@types/jsdom": "^21.1.7",
|
|
38
|
-
"@types/markdown-it": "^14.1.2",
|
|
39
|
-
"@types/markdown-it-container": "^2.0.10",
|
|
40
|
-
"@types/plantuml-encoder": "^1.4.2",
|
|
41
|
-
"copyfiles": "^2.4.1",
|
|
42
|
-
"markdown-it-container": "^4.0.0",
|
|
43
|
-
"rollup": "4.40.1",
|
|
44
|
-
"rollup-plugin-dts": "6.2.1",
|
|
45
|
-
"rollup-plugin-esbuild": "6.2.1",
|
|
46
|
-
"tsup": "^8.2.4",
|
|
47
|
-
"typescript": "^5.6.2",
|
|
48
|
-
"vite": "^5.4.5"
|
|
49
|
-
}
|
|
50
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "markdown-it-any-block",
|
|
3
|
+
"version": "3.2.11",
|
|
4
|
+
"description": "```typescript\r import { ABConvertManager } from \"ABConvertManager\"",
|
|
5
|
+
"types": "@types/index_mdit.d.ts",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "dist/mdit-any-block.cjs",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/mdit-any-block.js",
|
|
11
|
+
"require": "./dist/mdit-any-block.cjs"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"scripts": {
|
|
15
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
16
|
+
"build": "pnpm build_vite",
|
|
17
|
+
"build_tsc": "pnpm copy_abc_style && tsc",
|
|
18
|
+
"build_tsup": "pnpm copy_abc_style && tsup",
|
|
19
|
+
"build_vite": "pnpm copy_abc_style && vite build",
|
|
20
|
+
"build_rollup": "pnpm copy_abc_style && rollup -c rollup.config.ts --configPlugin esbuild",
|
|
21
|
+
"build_test": "echo '区别见README文件的 `构建测试` 一节'",
|
|
22
|
+
"prepublishOnly": "pnpm build",
|
|
23
|
+
"copy_abc_style": "copyfiles --flat ../../src/ABConverter/style/styles.css ./"
|
|
24
|
+
},
|
|
25
|
+
"author": "LincZero",
|
|
26
|
+
"license": "GNU Affero General Public License v3.0",
|
|
27
|
+
"peerDependencies": {
|
|
28
|
+
"markdown-it": "^14.1.0"
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"jsdom": "^26.0.0",
|
|
32
|
+
"markdown-it": "^14.1.0",
|
|
33
|
+
"plantuml-encoder": "^1.4.0"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@rollup/plugin-alias": "^5.1.1",
|
|
37
|
+
"@types/jsdom": "^21.1.7",
|
|
38
|
+
"@types/markdown-it": "^14.1.2",
|
|
39
|
+
"@types/markdown-it-container": "^2.0.10",
|
|
40
|
+
"@types/plantuml-encoder": "^1.4.2",
|
|
41
|
+
"copyfiles": "^2.4.1",
|
|
42
|
+
"markdown-it-container": "^4.0.0",
|
|
43
|
+
"rollup": "4.40.1",
|
|
44
|
+
"rollup-plugin-dts": "6.2.1",
|
|
45
|
+
"rollup-plugin-esbuild": "6.2.1",
|
|
46
|
+
"tsup": "^8.2.4",
|
|
47
|
+
"typescript": "^5.6.2",
|
|
48
|
+
"vite": "^5.4.5"
|
|
49
|
+
}
|
|
50
|
+
}
|
package/styles.css
CHANGED
|
@@ -429,10 +429,18 @@ html[data-theme=dark] #app {
|
|
|
429
429
|
border-right: none;
|
|
430
430
|
border-bottom: none;
|
|
431
431
|
}
|
|
432
|
-
.ab-note
|
|
432
|
+
.ab-note .ab-list-table-parent {
|
|
433
|
+
position: relative;
|
|
434
|
+
}
|
|
435
|
+
.ab-note .ab-list-table-parent .ab-table-fold {
|
|
433
436
|
position: absolute;
|
|
434
437
|
bottom: 0;
|
|
435
438
|
right: 0;
|
|
439
|
+
background: none;
|
|
440
|
+
border: none;
|
|
441
|
+
color: currentColor;
|
|
442
|
+
cursor: pointer;
|
|
443
|
+
padding: 2px 6px;
|
|
436
444
|
}
|
|
437
445
|
.ab-note table.ab-table-timeline td {
|
|
438
446
|
border-right: none;
|