@diplodoc/transform 4.51.1 → 4.53.0
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 +57 -0
- package/README.ru.md +56 -0
- package/dist/css/_yfm-only.css.map +1 -1
- package/dist/css/_yfm-only.min.css.map +1 -1
- package/dist/css/base.css +14 -2
- package/dist/css/base.css.map +3 -3
- package/dist/css/base.min.css +1 -1
- package/dist/css/base.min.css.map +3 -3
- package/dist/css/print.css.map +1 -1
- package/dist/css/yfm.css +14 -2
- 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-only.js +1 -15
- package/dist/js/_yfm-only.js.map +2 -2
- package/dist/js/_yfm-only.min.js +1 -1
- package/dist/js/_yfm-only.min.js.map +3 -3
- package/dist/js/yfm.js +1 -15
- package/dist/js/yfm.js.map +2 -2
- package/dist/js/yfm.min.js +1 -1
- package/dist/js/yfm.min.js.map +3 -3
- package/lib/md.js +9 -4
- package/lib/md.js.map +1 -1
- package/lib/plugins/term/termDefinitions.js +0 -7
- package/lib/plugins/term/termDefinitions.js.map +1 -1
- package/lib/sanitize.d.ts +1 -0
- package/lib/sanitize.js.map +1 -1
- package/lib/typings.d.ts +2 -1
- package/lib/yfmlint/markdownlint-custom-rule/yfm009.js +4 -4
- package/lib/yfmlint/markdownlint-custom-rule/yfm009.js.map +1 -1
- package/package.json +3 -1
- package/src/js/term/utils.ts +1 -18
- package/src/scss/_lists.scss +10 -4
- package/src/transform/md.ts +10 -4
- package/src/transform/plugins/term/termDefinitions.ts +0 -11
- package/src/transform/sanitize.ts +6 -0
- package/src/transform/typings.ts +2 -1
- package/src/transform/yfmlint/markdownlint-custom-rule/yfm009.ts +4 -4
package/src/js/term/utils.ts
CHANGED
|
@@ -6,19 +6,6 @@ export const openClass = 'open';
|
|
|
6
6
|
export const openDefinitionClass = Selector.CONTENT.replace(/\./g, '') + ' ' + openClass;
|
|
7
7
|
let isListenerNeeded = true;
|
|
8
8
|
|
|
9
|
-
export function createDefinitionElement(termElement: HTMLElement) {
|
|
10
|
-
const termKey = termElement.getAttribute('term-key');
|
|
11
|
-
const definitionTemplate = document.getElementById(
|
|
12
|
-
`${termKey}_template`,
|
|
13
|
-
) as HTMLTemplateElement;
|
|
14
|
-
const definitionElement = definitionTemplate?.content.cloneNode(true).firstChild as HTMLElement;
|
|
15
|
-
|
|
16
|
-
definitionTemplate?.parentElement?.appendChild(definitionElement);
|
|
17
|
-
definitionTemplate.remove();
|
|
18
|
-
|
|
19
|
-
return definitionElement;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
9
|
export function setDefinitionId(definitionElement: HTMLElement, termElement: HTMLElement): void {
|
|
23
10
|
const termId = termElement.getAttribute('id') || Math.random().toString(36).substr(2, 8);
|
|
24
11
|
definitionElement?.setAttribute('term-id', termId);
|
|
@@ -143,11 +130,7 @@ export function openDefinition(target: HTMLElement) {
|
|
|
143
130
|
|
|
144
131
|
const termId = target.getAttribute('id');
|
|
145
132
|
const termKey = target.getAttribute('term-key');
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
if (termKey && !definitionElement) {
|
|
149
|
-
definitionElement = createDefinitionElement(target);
|
|
150
|
-
}
|
|
133
|
+
const definitionElement = document.getElementById(termKey + '_element');
|
|
151
134
|
|
|
152
135
|
const isSameTerm = openedDefinition && termId === openedDefinition.getAttribute('term-id');
|
|
153
136
|
if (isSameTerm) {
|
package/src/scss/_lists.scss
CHANGED
|
@@ -62,10 +62,16 @@
|
|
|
62
62
|
@include hier-list(5);
|
|
63
63
|
|
|
64
64
|
&.yfm_no-list-reset ol,
|
|
65
|
-
ol.yfm_no-list-reset
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
65
|
+
ol.yfm_no-list-reset,
|
|
66
|
+
.yfm_no-list-reset ol {
|
|
67
|
+
counter-reset: list-item;
|
|
68
|
+
|
|
69
|
+
& li {
|
|
70
|
+
counter-increment: unset;
|
|
71
|
+
|
|
72
|
+
&::marker {
|
|
73
|
+
content: unset;
|
|
74
|
+
}
|
|
69
75
|
}
|
|
70
76
|
}
|
|
71
77
|
}
|
package/src/transform/md.ts
CHANGED
|
@@ -160,7 +160,7 @@ function initParser(
|
|
|
160
160
|
}
|
|
161
161
|
|
|
162
162
|
function initCompiler(md: MarkdownIt, options: OptionsType, env: EnvType) {
|
|
163
|
-
const {needToSanitizeHtml = true, renderInline = false, sanitizeOptions} = options;
|
|
163
|
+
const {needToSanitizeHtml = true, renderInline = false, sanitizeOptions, sanitize} = options;
|
|
164
164
|
|
|
165
165
|
return (tokens: Token[]) => {
|
|
166
166
|
// Remove inline tokens if inline mode is activated
|
|
@@ -171,10 +171,16 @@ function initCompiler(md: MarkdownIt, options: OptionsType, env: EnvType) {
|
|
|
171
171
|
// Generate HTML
|
|
172
172
|
const html = md.renderer.render(tokens, md.options, env);
|
|
173
173
|
|
|
174
|
+
if (!needToSanitizeHtml) {
|
|
175
|
+
return html;
|
|
176
|
+
}
|
|
177
|
+
|
|
174
178
|
// Sanitize the page
|
|
175
|
-
return
|
|
176
|
-
?
|
|
177
|
-
: html
|
|
179
|
+
return sanitize
|
|
180
|
+
? sanitize(html, sanitizeOptions)
|
|
181
|
+
: sanitizeHtml(html, sanitizeOptions, {
|
|
182
|
+
cssWhiteList: env.additionalOptionsCssWhiteList,
|
|
183
|
+
});
|
|
178
184
|
};
|
|
179
185
|
}
|
|
180
186
|
|
|
@@ -132,13 +132,6 @@ function processTermDefinition(
|
|
|
132
132
|
state.env.terms[':' + label] = title;
|
|
133
133
|
}
|
|
134
134
|
|
|
135
|
-
token = new state.Token('template_open', 'template', 1);
|
|
136
|
-
token.map = [startLine, currentLine + 1];
|
|
137
|
-
token.attrSet('id', ':' + label + '_template');
|
|
138
|
-
token.attrSet('label', label);
|
|
139
|
-
|
|
140
|
-
state.tokens.push(token);
|
|
141
|
-
|
|
142
135
|
token = new state.Token('dfn_open', 'dfn', 1);
|
|
143
136
|
token.attrSet('class', 'yfm yfm-term_dfn');
|
|
144
137
|
token.attrSet('id', ':' + label + '_element');
|
|
@@ -170,10 +163,6 @@ function processTermDefinition(
|
|
|
170
163
|
|
|
171
164
|
state.tokens.push(token);
|
|
172
165
|
|
|
173
|
-
token = new state.Token('template_close', 'template', -1);
|
|
174
|
-
|
|
175
|
-
state.tokens.push(token);
|
|
176
|
-
|
|
177
166
|
/** current line links to end of term definition */
|
|
178
167
|
state.line = currentLine + 1;
|
|
179
168
|
|
|
@@ -7,6 +7,12 @@ import css from 'css';
|
|
|
7
7
|
import {CssWhiteList} from './typings';
|
|
8
8
|
import log from './log';
|
|
9
9
|
|
|
10
|
+
export type SanitizeFunction = (
|
|
11
|
+
html: string,
|
|
12
|
+
options?: SanitizeOptions,
|
|
13
|
+
additionalOptions?: SanitizeOptions,
|
|
14
|
+
) => string;
|
|
15
|
+
|
|
10
16
|
const htmlTags = [
|
|
11
17
|
'a',
|
|
12
18
|
'abbr',
|
package/src/transform/typings.ts
CHANGED
|
@@ -2,7 +2,7 @@ import {LanguageFn} from 'highlight.js';
|
|
|
2
2
|
import DefaultMarkdownIt, {Token} from 'markdown-it';
|
|
3
3
|
import DefaultStateCore from 'markdown-it/lib/rules_core/state_core';
|
|
4
4
|
|
|
5
|
-
import {SanitizeOptions} from './sanitize';
|
|
5
|
+
import {SanitizeFunction, SanitizeOptions} from './sanitize';
|
|
6
6
|
import {LogLevels, Logger} from './log';
|
|
7
7
|
import {ChangelogItem} from './plugins/changelog/types';
|
|
8
8
|
|
|
@@ -46,6 +46,7 @@ export interface OptionsType {
|
|
|
46
46
|
isLiquided?: boolean;
|
|
47
47
|
needToSanitizeHtml?: boolean;
|
|
48
48
|
sanitizeOptions?: SanitizeOptions;
|
|
49
|
+
sanitize?: SanitizeFunction;
|
|
49
50
|
needFlatListHeadings?: boolean;
|
|
50
51
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
51
52
|
plugins?: ExtendedPluginWithCollect<any, any>[];
|
|
@@ -14,11 +14,11 @@ export const yfm009: Rule = {
|
|
|
14
14
|
const size = params.tokens.length;
|
|
15
15
|
|
|
16
16
|
for (let i = 0; i < size; i++) {
|
|
17
|
-
if (params.tokens[i].type === '
|
|
17
|
+
if (params.tokens[i].type === 'dfn_close') {
|
|
18
18
|
lastCloseIndex = i;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
if (params.tokens[i].type !== '
|
|
21
|
+
if (params.tokens[i].type !== 'dfn_close') {
|
|
22
22
|
continue;
|
|
23
23
|
}
|
|
24
24
|
|
|
@@ -26,11 +26,11 @@ export const yfm009: Rule = {
|
|
|
26
26
|
continue;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
if (params.tokens[i + 1].type === '
|
|
29
|
+
if (params.tokens[i + 1].type === 'dfn_open') {
|
|
30
30
|
continue;
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
if (i < size - 2 && params.tokens[i + 2].type === '
|
|
33
|
+
if (i < size - 2 && params.tokens[i + 2].type === 'dfn_open') {
|
|
34
34
|
continue;
|
|
35
35
|
}
|
|
36
36
|
|