@diplodoc/transform 4.69.3 → 4.70.1
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/dist/css/_yfm-only.css.map +1 -1
- package/dist/css/_yfm-only.min.css.map +1 -1
- package/dist/css/base.css.map +1 -1
- package/dist/css/base.min.css.map +1 -1
- package/dist/css/print.css.map +1 -1
- package/dist/css/yfm.css.map +1 -1
- package/dist/css/yfm.min.css.map +1 -1
- package/lib/plugins/anchors/constants.d.ts +1 -2
- package/lib/plugins/anchors/constants.js +3 -2
- package/lib/plugins/anchors/constants.js.map +1 -1
- package/lib/plugins/anchors/custom-id.d.ts +6 -0
- package/lib/plugins/anchors/custom-id.js +42 -0
- package/lib/plugins/anchors/custom-id.js.map +1 -0
- package/lib/plugins/anchors/index.js +9 -38
- package/lib/plugins/anchors/index.js.map +1 -1
- package/lib/plugins/code.js +3 -1
- package/lib/plugins/code.js.map +1 -1
- package/lib/plugins/term/index.js +106 -2
- package/lib/plugins/term/index.js.map +1 -1
- package/lib/plugins/term/termDefinitions.js +34 -4
- package/lib/plugins/term/termDefinitions.js.map +1 -1
- package/package.json +1 -1
- package/src/transform/plugins/anchors/constants.ts +1 -2
- package/src/transform/plugins/anchors/custom-id.ts +45 -0
- package/src/transform/plugins/anchors/index.ts +4 -40
- package/src/transform/plugins/code.ts +3 -1
- package/src/transform/plugins/term/index.ts +138 -2
- package/src/transform/plugins/term/termDefinitions.ts +38 -4
|
@@ -4,6 +4,33 @@ import type {MarkdownItPluginOpts} from '../typings';
|
|
|
4
4
|
|
|
5
5
|
import {BASIC_TERM_REGEXP} from './constants';
|
|
6
6
|
|
|
7
|
+
const INCLUDE_LINE_RE = /^{%\s*include\s/;
|
|
8
|
+
const NEW_LINE_RE = /^(\r\n|\r|\n)/;
|
|
9
|
+
const TERM_DEF_RE = /^\[\*(\w+)\]:/;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Checks whether the first non-blank line after {@link fromLine} is an
|
|
13
|
+
* `{% include %}` directive. Used to allow blank-line gaps between
|
|
14
|
+
* consecutive includes inside a single term definition.
|
|
15
|
+
*
|
|
16
|
+
* @param {StateBlock} state - The markdown-it state block containing parsing information
|
|
17
|
+
* @param {number} fromLine - The line number from which to start searching for include directives
|
|
18
|
+
* @param {number} endLine - The last line number to search within
|
|
19
|
+
* @returns {boolean} Returns true if an include directive is found after blank lines, false otherwise
|
|
20
|
+
*/
|
|
21
|
+
function hasIncludeAfterBlanks(state: StateBlock, fromLine: number, endLine: number): boolean {
|
|
22
|
+
for (let line = fromLine + 1; line <= endLine; line++) {
|
|
23
|
+
const start = state.bMarks[line];
|
|
24
|
+
const end = state.eMarks[line];
|
|
25
|
+
|
|
26
|
+
if (start === end) continue;
|
|
27
|
+
|
|
28
|
+
const content = state.src.slice(start, end);
|
|
29
|
+
return INCLUDE_LINE_RE.test(content.trimStart());
|
|
30
|
+
}
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
|
|
7
34
|
export function termDefinitions(md: MarkdownIt, options: MarkdownItPluginOpts) {
|
|
8
35
|
return (state: StateBlock, startLine: number, endLine: number, silent: boolean) => {
|
|
9
36
|
let ch;
|
|
@@ -36,11 +63,12 @@ export function termDefinitions(md: MarkdownIt, options: MarkdownItPluginOpts) {
|
|
|
36
63
|
}
|
|
37
64
|
}
|
|
38
65
|
|
|
39
|
-
const newLineReg = new RegExp(/^(\r\n|\r|\n)/);
|
|
40
|
-
const termReg = new RegExp(/^\[\*(\w+)\]:/);
|
|
41
66
|
let currentLine = startLine;
|
|
42
67
|
|
|
43
|
-
// Allow multiline term definition
|
|
68
|
+
// Allow multiline term definition.
|
|
69
|
+
// Blank lines normally terminate the definition, but we look ahead
|
|
70
|
+
// past them: if the next non-blank line is an {% include %} directive,
|
|
71
|
+
// we keep scanning so that multiple includes can be part of one term.
|
|
44
72
|
for (; currentLine < endLine; currentLine++) {
|
|
45
73
|
const nextLineStart = state.bMarks[currentLine + 1];
|
|
46
74
|
const nextLineEnd = state.eMarks[currentLine + 1];
|
|
@@ -50,10 +78,16 @@ export function termDefinitions(md: MarkdownIt, options: MarkdownItPluginOpts) {
|
|
|
50
78
|
? state.src[nextLineStart]
|
|
51
79
|
: state.src.slice(nextLineStart, nextLineEnd);
|
|
52
80
|
|
|
53
|
-
if (
|
|
81
|
+
if (TERM_DEF_RE.test(nextLine)) {
|
|
54
82
|
break;
|
|
55
83
|
}
|
|
56
84
|
|
|
85
|
+
if (NEW_LINE_RE.test(nextLine)) {
|
|
86
|
+
if (!hasIncludeAfterBlanks(state, currentLine + 1, endLine)) {
|
|
87
|
+
break;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
57
91
|
state.line = currentLine + 1;
|
|
58
92
|
}
|
|
59
93
|
|