@diplodoc/transform 4.50.4 → 4.51.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@diplodoc/transform",
3
- "version": "4.50.4",
3
+ "version": "4.51.1",
4
4
  "description": "A simple transformer of text in YFM (Yandex Flavored Markdown) to HTML",
5
5
  "keywords": [
6
6
  "markdown",
@@ -65,6 +65,7 @@
65
65
  "markdown-it-sup": "1.0.0",
66
66
  "markdownlint": "^0.32.1",
67
67
  "markdownlint-rule-helpers": "0.17.2",
68
+ "quick-lru": "^5.1.1",
68
69
  "sanitize-html": "^2.11.0",
69
70
  "slugify": "1.6.6",
70
71
  "svgo": "^3.2.0",
@@ -95,10 +95,15 @@ function initPlugins(md: MarkdownIt, options: OptionsType, pluginOptions: Markdo
95
95
  leftDelimiter = '{',
96
96
  rightDelimiter = '}',
97
97
  plugins = DefaultPlugins,
98
+ enableMarkdownAttrs,
98
99
  } = options;
99
100
 
100
- // Need for ids of headers
101
- md.use(attrs, {leftDelimiter, rightDelimiter});
101
+ // TODO: set enableMarkdownAttrs to false by default in next major
102
+ if (enableMarkdownAttrs !== false) {
103
+ // Need for ids of headers
104
+ md.use(attrs, {leftDelimiter, rightDelimiter});
105
+ }
106
+
102
107
  md.use(olAttrConversion);
103
108
 
104
109
  plugins.forEach((plugin) => md.use(plugin, pluginOptions));
@@ -3,7 +3,11 @@ import MarkdownIt from 'markdown-it';
3
3
  import {TOKEN_NAME, renderTokens, replaceTokens} from './block-anchor';
4
4
 
5
5
  const blockAnchor = (md: MarkdownIt) => {
6
- md.core.ruler.before('curly_attributes', TOKEN_NAME, replaceTokens);
6
+ try {
7
+ md.core.ruler.before('curly_attributes', TOKEN_NAME, replaceTokens);
8
+ } catch (e) {
9
+ md.core.ruler.push(TOKEN_NAME, replaceTokens);
10
+ }
7
11
  md.renderer.rules[TOKEN_NAME] = renderTokens;
8
12
 
9
13
  return md;
@@ -76,6 +76,7 @@ function unfoldIncludes(md: MarkdownItIncluded, state: StateCore, path: string,
76
76
  let includedTokens;
77
77
  if (hash) {
78
78
  // TODO: add warning about missed block
79
+ // TODO: findBlockTokens requires markdown-it-attrs plugin for find block with id=hash
79
80
  includedTokens = findBlockTokens(fileTokens, hash);
80
81
  } else {
81
82
  includedTokens = fileTokens;
@@ -511,6 +511,12 @@ export const defaultOptions: SanitizeOptions = {
511
511
  ...sanitizeHtml.defaults.allowedAttributes,
512
512
  '*': allowedAttributes,
513
513
  },
514
+ allowedSchemesAppliedToAttributes: [
515
+ ...sanitizeHtml.defaults.allowedSchemesAppliedToAttributes,
516
+ 'xlink:href',
517
+ 'from',
518
+ 'to',
519
+ ],
514
520
  allowVulnerableTags: true,
515
521
  parser: defaultParseOptions,
516
522
  cssWhiteList: defaultCssWhitelist,
@@ -593,7 +599,6 @@ function sanitizeStyles(html: string, options: SanitizeOptions) {
593
599
  const $ = cheerio.load(html);
594
600
 
595
601
  sanitizeStyleTags($, cssWhiteList);
596
-
597
602
  sanitizeStyleAttrs($, cssWhiteList);
598
603
 
599
604
  const styles = $('head').html() || '';
@@ -59,6 +59,13 @@ export interface OptionsType {
59
59
  getPublicPath?: (options: OptionsType, href?: string) => string;
60
60
  renderInline?: boolean;
61
61
  cache?: CacheContext;
62
+ // TODO: set false by default in next major
63
+ /**
64
+ * `markdown-it-attrs` plugin is enabled by default
65
+ *
66
+ * Set value to `false` to disable it
67
+ */
68
+ enableMarkdownAttrs?: boolean;
62
69
  [x: string]: unknown;
63
70
  }
64
71
 
@@ -3,13 +3,14 @@ import type {Dictionary} from 'lodash';
3
3
  import {readFileSync, realpathSync, statSync} from 'fs';
4
4
  import escapeRegExp from 'lodash/escapeRegExp';
5
5
  import {join, parse, relative, resolve, sep} from 'path';
6
+ import QuickLRU from 'quick-lru';
6
7
 
7
8
  import liquidSnippet from './liquid';
8
9
  import {StateCore} from './typings';
9
10
  import {defaultTransformLink} from './utils';
10
11
  import {preprocess} from './preprocessors';
11
12
 
12
- const filesCache: Record<string, string> = {};
13
+ const filesCache = new QuickLRU<string, string>({maxSize: 1000});
13
14
 
14
15
  export function isFileExists(file: string) {
15
16
  try {
@@ -62,11 +63,11 @@ export function getFileTokens(
62
63
 
63
64
  // Read the content only if we dont have one in the args
64
65
  if (!content) {
65
- if (filesCache[path]) {
66
- content = filesCache[path];
66
+ if (filesCache.has(path)) {
67
+ content = filesCache.get(path) as string;
67
68
  } else {
68
69
  content = readFileSync(path, 'utf8');
69
- filesCache[path] = content;
70
+ filesCache.set(path, content);
70
71
  }
71
72
  }
72
73
 
@@ -56,7 +56,9 @@ function yfmlint(opts: Options) {
56
56
  lintRules = union(lintRules, customLintRules);
57
57
  }
58
58
 
59
- const plugins = customPlugins && [attrs, ...customPlugins];
59
+ // TODO: set to false in next major
60
+ const {enableMarkdownAttrs = true} = opts;
61
+ const plugins = customPlugins && [...(enableMarkdownAttrs ? [attrs] : []), ...customPlugins];
60
62
  const preparedPlugins = plugins && plugins.map((plugin) => [plugin, pluginOptions]);
61
63
 
62
64
  // Run preprocessor
@@ -16,4 +16,7 @@ export interface Options {
16
16
  lintConfig?: LintConfig;
17
17
  customLintRules?: Rule[];
18
18
  sourceMap?: Dictionary<string>;
19
+ // TODO: set false in next major
20
+ /** @default true */
21
+ enableMarkdownAttrs?: boolean;
19
22
  }