@diplodoc/transform 4.52.0 → 4.54.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.
@@ -13,19 +13,19 @@ exports.yfm009 = {
13
13
  let lastCloseIndex = -1;
14
14
  const size = params.tokens.length;
15
15
  for (let i = 0; i < size; i++) {
16
- if (params.tokens[i].type === 'template_close') {
16
+ if (params.tokens[i].type === 'dfn_close') {
17
17
  lastCloseIndex = i;
18
18
  }
19
- if (params.tokens[i].type !== 'template_close') {
19
+ if (params.tokens[i].type !== 'dfn_close') {
20
20
  continue;
21
21
  }
22
22
  if (i === size - 1) {
23
23
  continue;
24
24
  }
25
- if (params.tokens[i + 1].type === 'template_open') {
25
+ if (params.tokens[i + 1].type === 'dfn_open') {
26
26
  continue;
27
27
  }
28
- if (i < size - 2 && params.tokens[i + 2].type === 'template_open') {
28
+ if (i < size - 2 && params.tokens[i + 2].type === 'dfn_open') {
29
29
  continue;
30
30
  }
31
31
  onError({
@@ -1 +1 @@
1
- {"version":3,"file":"yfm009.js","sourceRoot":"","sources":["../../../src/transform/yfmlint/markdownlint-custom-rule/yfm009.ts"],"names":[],"mappings":";;;AAEa,QAAA,MAAM,GAAS;IACxB,KAAK,EAAE,CAAC,QAAQ,EAAE,+BAA+B,CAAC;IAClD,WAAW,EAAE,qDAAqD;IAClE,IAAI,EAAE,CAAC,MAAM,CAAC;IACd,QAAQ,EAAE,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO;QACrC,MAAM,EAAC,MAAM,EAAC,GAAG,MAAM,CAAC;QACxB,IAAI,CAAC,MAAM,EAAE;YACT,OAAO;SACV;QAED,IAAI,cAAc,GAAG,CAAC,CAAC,CAAC;QACxB,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC;QAElC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,CAAC,EAAE,EAAE;YAC3B,IAAI,MAAM,CAAC,M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J,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@diplodoc/transform",
3
- "version": "4.52.0",
3
+ "version": "4.54.0",
4
4
  "description": "A simple transformer of text in YFM (Yandex Flavored Markdown) to HTML",
5
5
  "keywords": [
6
6
  "markdown",
@@ -39,6 +39,8 @@
39
39
  "artifact:pages": "npm run build && npm run artifact:playground",
40
40
  "prepublishOnly": "npm run lint && npm run test && npm run build",
41
41
  "test": "jest --coverage",
42
+ "test:playwright:nobuild": "cd e2e && npm run playwright:docker",
43
+ "test:playwright": "npm run build && npm run test:playwright:nobuild",
42
44
  "typecheck": "tsc -p tsconfig.json --noEmit",
43
45
  "lint": "lint update && lint",
44
46
  "lint:fix": "lint update && lint fix",
@@ -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
- let definitionElement = document.getElementById(termKey + '_element');
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) {
@@ -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
- // No direct ancestor (>) combinator to preserve legacy behavior
67
- & > li::marker {
68
- content: unset;
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
  }
@@ -10,7 +10,7 @@ import {log} from './log';
10
10
  import makeHighlight from './highlight';
11
11
  import extractTitle from './title';
12
12
  import getHeadings from './headings';
13
- import sanitizeHtml from './sanitize';
13
+ import sanitizeHtml, {defaultOptions, sanitizeStyles} from './sanitize';
14
14
  import {olAttrConversion} from './plugins/ol-attr-conversion';
15
15
 
16
16
  function initMarkdownIt(options: OptionsType) {
@@ -169,18 +169,36 @@ function initCompiler(md: MarkdownIt, options: OptionsType, env: EnvType) {
169
169
  }
170
170
 
171
171
  // Generate HTML
172
- const html = md.renderer.render(tokens, md.options, env);
172
+ let html = md.renderer.render(tokens, md.options, env);
173
173
 
174
174
  if (!needToSanitizeHtml) {
175
175
  return html;
176
176
  }
177
177
 
178
- // Sanitize the page
179
- return sanitize
178
+ // If a custom sanitizer was used, we need to ensure styles are sanitized
179
+ // unless explicitly disabled via disableStyleSanitizer option
180
+ if (sanitize && !(sanitizeOptions?.disableStyleSanitizer ?? false)) {
181
+ const baseOptions = sanitizeOptions || defaultOptions;
182
+
183
+ const mergedOptions = {
184
+ ...baseOptions,
185
+ cssWhiteList: {
186
+ ...(defaultOptions.cssWhiteList || {}),
187
+ ...(baseOptions.cssWhiteList || {}),
188
+ ...(env.additionalOptionsCssWhiteList || {}),
189
+ },
190
+ };
191
+
192
+ html = sanitizeStyles(html, mergedOptions);
193
+ }
194
+
195
+ const sanitizedHtml = sanitize
180
196
  ? sanitize(html, sanitizeOptions)
181
197
  : sanitizeHtml(html, sanitizeOptions, {
182
198
  cssWhiteList: env.additionalOptionsCssWhiteList,
183
199
  });
200
+
201
+ return sanitizedHtml;
184
202
  };
185
203
  }
186
204
 
@@ -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
 
@@ -599,7 +599,7 @@ function sanitizeStyleAttrs(dom: cheerio.CheerioAPI, cssWhiteList: CssWhiteList)
599
599
  });
600
600
  }
601
601
 
602
- function sanitizeStyles(html: string, options: SanitizeOptions) {
602
+ export function sanitizeStyles(html: string, options: SanitizeOptions) {
603
603
  const cssWhiteList = options.cssWhiteList || {};
604
604
 
605
605
  const $ = cheerio.load(html);
@@ -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 === 'template_close') {
17
+ if (params.tokens[i].type === 'dfn_close') {
18
18
  lastCloseIndex = i;
19
19
  }
20
20
 
21
- if (params.tokens[i].type !== 'template_close') {
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 === 'template_open') {
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 === 'template_open') {
33
+ if (i < size - 2 && params.tokens[i + 2].type === 'dfn_open') {
34
34
  continue;
35
35
  }
36
36