@diplodoc/transform 4.28.3 → 4.29.0-beta2
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/print.css.map +2 -2
- package/dist/css/yfm.css +52 -45
- package/dist/css/yfm.css.map +3 -3
- package/dist/css/yfm.min.css +1 -1
- package/dist/css/yfm.min.css.map +3 -3
- package/dist/js/yfm.js +60 -52
- package/dist/js/yfm.js.map +4 -4
- package/dist/js/yfm.min.js +1 -1
- package/dist/js/yfm.min.js.map +4 -4
- package/lib/plugins/cut.d.ts +4 -3
- package/lib/plugins/cut.js +2 -68
- package/lib/plugins/cut.js.map +1 -1
- package/lib/plugins/term/index.js +1 -1
- package/lib/plugins/term/index.js.map +1 -1
- package/lib/plugins/term/termDefinitions.js +1 -2
- package/lib/plugins/term/termDefinitions.js.map +1 -1
- package/package.json +3 -2
- package/src/js/index.ts +1 -1
- package/src/js/term/utils.ts +2 -3
- package/src/scss/yfm.scss +1 -1
- package/src/transform/plugins/cut.ts +2 -97
- package/src/transform/plugins/term/index.ts +1 -1
- package/src/transform/plugins/term/termDefinitions.ts +1 -2
- package/src/js/cut.ts +0 -57
|
@@ -1,98 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
import type Token from 'markdown-it/lib/token';
|
|
3
|
-
import {MarkdownItPluginCb} from './typings';
|
|
4
|
-
import {MatchTokenFunction, nestedCloseTokenIdxFactory as closeTokenFactory} from './utils';
|
|
1
|
+
import {transform} from '@diplodoc/cut-extension';
|
|
5
2
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const matchCloseToken: MatchTokenFunction = (tokens, i) => {
|
|
9
|
-
return (
|
|
10
|
-
tokens[i].type === 'paragraph_open' &&
|
|
11
|
-
tokens[i + 1].type === 'inline' &&
|
|
12
|
-
tokens[i + 1].content.trim() === '{% endcut %}'
|
|
13
|
-
);
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
const matchOpenToken = (tokens: Token[], i: number) => {
|
|
17
|
-
return (
|
|
18
|
-
tokens[i].type === 'paragraph_open' &&
|
|
19
|
-
tokens[i + 1].type === 'inline' &&
|
|
20
|
-
tokens[i + 1].content.match(CUT_REGEXP)
|
|
21
|
-
);
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
const findCloseTokenIdx = closeTokenFactory('Cut', matchOpenToken, matchCloseToken);
|
|
25
|
-
|
|
26
|
-
const cut: MarkdownItPluginCb = (md, {path, log}) => {
|
|
27
|
-
const plugin: Core.RuleCore = (state) => {
|
|
28
|
-
const tokens = state.tokens;
|
|
29
|
-
let i = 0;
|
|
30
|
-
|
|
31
|
-
while (i < tokens.length) {
|
|
32
|
-
const match = matchOpenToken(tokens, i);
|
|
33
|
-
|
|
34
|
-
if (match) {
|
|
35
|
-
const closeTokenIdx = findCloseTokenIdx(tokens, i + 4, path, log);
|
|
36
|
-
|
|
37
|
-
if (!closeTokenIdx) {
|
|
38
|
-
i += 3;
|
|
39
|
-
continue;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const newOpenToken = new state.Token('yfm_cut_open', 'details', 1);
|
|
43
|
-
newOpenToken.attrSet('class', 'yfm-cut');
|
|
44
|
-
newOpenToken.map = tokens[i].map;
|
|
45
|
-
|
|
46
|
-
const titleOpen = new state.Token('yfm_cut_title_open', 'summary', 1);
|
|
47
|
-
titleOpen.attrSet('class', 'yfm-cut-title');
|
|
48
|
-
|
|
49
|
-
const titleInline = state.md.parseInline(
|
|
50
|
-
match[1] === undefined ? 'ad' : match[1],
|
|
51
|
-
state.env,
|
|
52
|
-
)[0];
|
|
53
|
-
|
|
54
|
-
const titleClose = new state.Token('yfm_cut_title_close', 'summary', -1);
|
|
55
|
-
|
|
56
|
-
const contentOpen = new state.Token('yfm_cut_content_open', 'div', 1);
|
|
57
|
-
contentOpen.attrSet('class', 'yfm-cut-content');
|
|
58
|
-
|
|
59
|
-
if (newOpenToken.map) {
|
|
60
|
-
const contentOpenStart = newOpenToken.map[0] + 1;
|
|
61
|
-
const contentOpenEnd = newOpenToken.map[0] + 2;
|
|
62
|
-
|
|
63
|
-
contentOpen.map = [contentOpenStart, contentOpenEnd];
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const contentClose = new state.Token('yfm_cut_content_close', 'div', -1);
|
|
67
|
-
|
|
68
|
-
const newCloseToken = new state.Token('yfm_cut_close', 'details', -1);
|
|
69
|
-
newCloseToken.map = tokens[closeTokenIdx].map;
|
|
70
|
-
|
|
71
|
-
const insideTokens = [
|
|
72
|
-
newOpenToken,
|
|
73
|
-
titleOpen,
|
|
74
|
-
titleInline,
|
|
75
|
-
titleClose,
|
|
76
|
-
contentOpen,
|
|
77
|
-
...tokens.slice(i + 3, closeTokenIdx),
|
|
78
|
-
contentClose,
|
|
79
|
-
newCloseToken,
|
|
80
|
-
];
|
|
81
|
-
|
|
82
|
-
tokens.splice(i, closeTokenIdx - i + 3, ...insideTokens);
|
|
83
|
-
|
|
84
|
-
i++;
|
|
85
|
-
} else {
|
|
86
|
-
i++;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
try {
|
|
92
|
-
md.core.ruler.before('curly_attributes', 'cut', plugin);
|
|
93
|
-
} catch (e) {
|
|
94
|
-
md.core.ruler.push('cut', plugin);
|
|
95
|
-
}
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
export = cut;
|
|
3
|
+
export = transform({bundle: false});
|
|
@@ -99,7 +99,7 @@ const term: MarkdownItPluginCb = (md, options) => {
|
|
|
99
99
|
token = new state.Token('term_open', 'i', 1);
|
|
100
100
|
token.attrSet('class', 'yfm yfm-term_title');
|
|
101
101
|
token.attrSet('term-key', ':' + termKey);
|
|
102
|
-
token.attrSet('role', '
|
|
102
|
+
token.attrSet('role', 'term');
|
|
103
103
|
token.attrSet('aria-describedby', ':' + termKey + '_element');
|
|
104
104
|
token.attrSet('tabindex', '0');
|
|
105
105
|
token.attrSet('id', generateID());
|
|
@@ -140,9 +140,8 @@ function processTermDefinition(
|
|
|
140
140
|
token = new state.Token('dfn_open', 'dfn', 1);
|
|
141
141
|
token.attrSet('class', 'yfm yfm-term_dfn');
|
|
142
142
|
token.attrSet('id', ':' + label + '_element');
|
|
143
|
-
token.attrSet('role', '
|
|
143
|
+
token.attrSet('role', 'tooltip');
|
|
144
144
|
token.attrSet('aria-live', 'polite');
|
|
145
|
-
token.attrSet('aria-modal', 'true');
|
|
146
145
|
|
|
147
146
|
state.tokens.push(token);
|
|
148
147
|
|
package/src/js/cut.ts
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import {getEventTarget, isCustom} from './utils';
|
|
2
|
-
|
|
3
|
-
const Selector = {
|
|
4
|
-
CUT: '.yfm .yfm-cut',
|
|
5
|
-
TITLE: '.yfm .yfm-cut-title',
|
|
6
|
-
CONTENT: '.yfm .yfm-cut-content',
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
const ClassName = {
|
|
10
|
-
OPEN: 'open',
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
function toggleCut(element: HTMLElement) {
|
|
14
|
-
const cutNode = element.parentNode;
|
|
15
|
-
|
|
16
|
-
if (!(cutNode instanceof HTMLElement)) {
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
cutNode.classList.toggle(ClassName.OPEN);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function matchTitle(target: EventTarget | null) {
|
|
24
|
-
if (!(target instanceof HTMLElement)) {
|
|
25
|
-
return false;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
return target?.matches?.(Selector.TITLE);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function findTitleInPath(event: MouseEvent): HTMLElement | undefined {
|
|
32
|
-
const target = getEventTarget(event);
|
|
33
|
-
|
|
34
|
-
if (matchTitle(target)) {
|
|
35
|
-
return target as HTMLElement;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const path = event.composedPath?.();
|
|
39
|
-
|
|
40
|
-
return path?.find(matchTitle) as HTMLElement | undefined;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
if (typeof document !== 'undefined') {
|
|
44
|
-
document.addEventListener('click', (event) => {
|
|
45
|
-
if (isCustom(event)) {
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const title = findTitleInPath(event);
|
|
50
|
-
|
|
51
|
-
if (!title) {
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
toggleCut(title);
|
|
56
|
-
});
|
|
57
|
-
}
|