@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/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/md.js +6 -3
- package/lib/md.js.map +1 -1
- package/lib/plugins/block-anchor/index.js +6 -1
- package/lib/plugins/block-anchor/index.js.map +1 -1
- package/lib/plugins/includes/index.js +1 -0
- package/lib/plugins/includes/index.js.map +1 -1
- package/lib/sanitize.js +6 -1
- package/lib/sanitize.js.map +1 -1
- package/lib/typings.d.ts +6 -0
- package/lib/utilsFS.js +5 -4
- package/lib/utilsFS.js.map +1 -1
- package/lib/yfmlint/index.js +3 -1
- package/lib/yfmlint/index.js.map +1 -1
- package/lib/yfmlint/typings.d.ts +2 -0
- package/package.json +2 -1
- package/src/transform/md.ts +7 -2
- package/src/transform/plugins/block-anchor/index.ts +5 -1
- package/src/transform/plugins/includes/index.ts +1 -0
- package/src/transform/sanitize.ts +6 -1
- package/src/transform/typings.ts +7 -0
- package/src/transform/utilsFS.ts +5 -4
- package/src/transform/yfmlint/index.ts +3 -1
- package/src/transform/yfmlint/typings.ts +3 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@diplodoc/transform",
|
|
3
|
-
"version": "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",
|
package/src/transform/md.ts
CHANGED
|
@@ -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
|
-
//
|
|
101
|
-
|
|
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
|
-
|
|
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() || '';
|
package/src/transform/typings.ts
CHANGED
|
@@ -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
|
|
package/src/transform/utilsFS.ts
CHANGED
|
@@ -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
|
|
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
|
|
66
|
-
content = filesCache
|
|
66
|
+
if (filesCache.has(path)) {
|
|
67
|
+
content = filesCache.get(path) as string;
|
|
67
68
|
} else {
|
|
68
69
|
content = readFileSync(path, 'utf8');
|
|
69
|
-
filesCache
|
|
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
|
-
|
|
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
|