@diplodoc/transform 4.29.0 → 4.30.2

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.
Files changed (147) hide show
  1. package/dist/css/print.css.map +1 -1
  2. package/dist/css/yfm.css +0 -1
  3. package/dist/css/yfm.css.map +2 -2
  4. package/dist/css/yfm.min.css +1 -1
  5. package/dist/css/yfm.min.css.map +2 -2
  6. package/dist/js/yfm.js.map +2 -2
  7. package/dist/js/yfm.min.js.map +2 -2
  8. package/lib/headings.js.map +1 -1
  9. package/lib/highlight.js.map +1 -1
  10. package/lib/index.js.map +1 -1
  11. package/lib/liquid/conditions.js +1 -1
  12. package/lib/liquid/conditions.js.map +1 -1
  13. package/lib/liquid/cycles.js +1 -1
  14. package/lib/liquid/cycles.js.map +1 -1
  15. package/lib/liquid/evaluation.js +1 -1
  16. package/lib/liquid/evaluation.js.map +1 -1
  17. package/lib/liquid/index.d.ts +1 -1
  18. package/lib/liquid/index.js.map +1 -1
  19. package/lib/liquid/substitutions.js +2 -2
  20. package/lib/liquid/substitutions.js.map +1 -1
  21. package/lib/md.js +30 -9
  22. package/lib/md.js.map +1 -1
  23. package/lib/plugins/anchors/collect.js +1 -1
  24. package/lib/plugins/anchors/collect.js.map +1 -1
  25. package/lib/plugins/anchors/index.js +4 -4
  26. package/lib/plugins/anchors/index.js.map +1 -1
  27. package/lib/plugins/block-anchor/index.js.map +1 -1
  28. package/lib/plugins/changelog/collect.d.ts +1 -1
  29. package/lib/plugins/changelog/collect.js +1 -1
  30. package/lib/plugins/changelog/collect.js.map +1 -1
  31. package/lib/plugins/changelog/index.js.map +1 -1
  32. package/lib/plugins/checkbox/index.js.map +1 -1
  33. package/lib/plugins/deflist.js.map +1 -1
  34. package/lib/plugins/file/index.js.map +1 -1
  35. package/lib/plugins/images/index.js +1 -1
  36. package/lib/plugins/images/index.js.map +1 -1
  37. package/lib/plugins/imsize/index.js.map +1 -1
  38. package/lib/plugins/imsize/plugin.js.map +1 -1
  39. package/lib/plugins/includes/collect.d.ts +4 -2
  40. package/lib/plugins/includes/collect.js +20 -3
  41. package/lib/plugins/includes/collect.js.map +1 -1
  42. package/lib/plugins/includes/index.js +8 -5
  43. package/lib/plugins/includes/index.js.map +1 -1
  44. package/lib/plugins/includes/types.d.ts +6 -0
  45. package/lib/plugins/includes/types.js +3 -0
  46. package/lib/plugins/includes/types.js.map +1 -0
  47. package/lib/plugins/links/collect.js.map +1 -1
  48. package/lib/plugins/links/index.js +1 -1
  49. package/lib/plugins/links/index.js.map +1 -1
  50. package/lib/plugins/meta.js.map +1 -1
  51. package/lib/plugins/monospace.js +0 -1
  52. package/lib/plugins/monospace.js.map +1 -1
  53. package/lib/plugins/notes/index.js +0 -2
  54. package/lib/plugins/notes/index.js.map +1 -1
  55. package/lib/plugins/sup.js.map +1 -1
  56. package/lib/plugins/table/index.js.map +1 -1
  57. package/lib/plugins/term/index.js.map +1 -1
  58. package/lib/plugins/term/termDefinitions.js.map +1 -1
  59. package/lib/plugins/typings.d.ts +1 -14
  60. package/lib/plugins/typings.js +15 -0
  61. package/lib/plugins/typings.js.map +1 -1
  62. package/lib/plugins/utils.d.ts +1 -1
  63. package/lib/plugins/utils.js.map +1 -1
  64. package/lib/plugins/video/const.d.ts +3 -1
  65. package/lib/plugins/video/const.js +4 -0
  66. package/lib/plugins/video/const.js.map +1 -1
  67. package/lib/plugins/video/index.js +7 -9
  68. package/lib/plugins/video/index.js.map +1 -1
  69. package/lib/plugins/video/parsers.d.ts +2 -0
  70. package/lib/plugins/video/parsers.js +19 -1
  71. package/lib/plugins/video/parsers.js.map +1 -1
  72. package/lib/plugins/video/types.d.ts +8 -0
  73. package/lib/plugins/video/utils.js +9 -6
  74. package/lib/plugins/video/utils.js.map +1 -1
  75. package/lib/preprocessors/included/index.d.ts +5 -0
  76. package/lib/preprocessors/included/index.js +71 -0
  77. package/lib/preprocessors/included/index.js.map +1 -0
  78. package/lib/preprocessors.d.ts +3 -0
  79. package/lib/preprocessors.js +8 -0
  80. package/lib/preprocessors.js.map +1 -0
  81. package/lib/sanitize.js +1 -1
  82. package/lib/sanitize.js.map +1 -1
  83. package/lib/typings.d.ts +22 -2
  84. package/lib/utilsFS.d.ts +2 -0
  85. package/lib/utilsFS.js +18 -8
  86. package/lib/utilsFS.js.map +1 -1
  87. package/lib/yfmlint/index.d.ts +2 -2
  88. package/lib/yfmlint/index.js +6 -1
  89. package/lib/yfmlint/index.js.map +1 -1
  90. package/lib/yfmlint/markdownlint-custom-rule/yfm001.js.map +1 -1
  91. package/lib/yfmlint/typings.d.ts +2 -0
  92. package/lib/yfmlint/utils.d.ts +2 -2
  93. package/lib/yfmlint/utils.js.map +1 -1
  94. package/lib/yfmlint/yfmlint.js.map +1 -1
  95. package/package.json +13 -11
  96. package/src/.eslintrc.js +1 -23
  97. package/src/js/index.ts +0 -1
  98. package/src/js/term/index.ts +1 -0
  99. package/src/transform/headings.ts +1 -0
  100. package/src/transform/highlight.ts +1 -0
  101. package/src/transform/index.ts +2 -0
  102. package/src/transform/liquid/conditions.ts +3 -1
  103. package/src/transform/liquid/cycles.ts +3 -1
  104. package/src/transform/liquid/evaluation.ts +2 -1
  105. package/src/transform/liquid/index.ts +2 -3
  106. package/src/transform/liquid/substitutions.ts +3 -2
  107. package/src/transform/md.ts +55 -14
  108. package/src/transform/plugins/anchors/collect.ts +2 -1
  109. package/src/transform/plugins/anchors/index.ts +4 -3
  110. package/src/transform/plugins/block-anchor/index.ts +1 -0
  111. package/src/transform/plugins/changelog/collect.ts +5 -2
  112. package/src/transform/plugins/changelog/index.ts +2 -1
  113. package/src/transform/plugins/checkbox/index.ts +1 -0
  114. package/src/transform/plugins/deflist.ts +1 -0
  115. package/src/transform/plugins/file/index.ts +1 -0
  116. package/src/transform/plugins/images/index.ts +2 -2
  117. package/src/transform/plugins/imsize/index.ts +1 -0
  118. package/src/transform/plugins/imsize/plugin.ts +1 -0
  119. package/src/transform/plugins/includes/collect.ts +45 -5
  120. package/src/transform/plugins/includes/index.ts +23 -7
  121. package/src/transform/plugins/includes/types.ts +7 -0
  122. package/src/transform/plugins/links/collect.ts +2 -0
  123. package/src/transform/plugins/links/index.ts +5 -3
  124. package/src/transform/plugins/meta.ts +1 -0
  125. package/src/transform/plugins/monospace.ts +1 -1
  126. package/src/transform/plugins/notes/index.ts +2 -2
  127. package/src/transform/plugins/sup.ts +1 -0
  128. package/src/transform/plugins/table/index.ts +3 -1
  129. package/src/transform/plugins/term/index.ts +1 -0
  130. package/src/transform/plugins/term/termDefinitions.ts +2 -0
  131. package/src/transform/plugins/typings.ts +1 -16
  132. package/src/transform/plugins/utils.ts +2 -1
  133. package/src/transform/plugins/video/const.ts +5 -0
  134. package/src/transform/plugins/video/index.ts +8 -10
  135. package/src/transform/plugins/video/parsers.ts +18 -0
  136. package/src/transform/plugins/video/types.ts +2 -0
  137. package/src/transform/plugins/video/utils.ts +9 -6
  138. package/src/transform/preprocessors/included/index.ts +101 -0
  139. package/src/transform/preprocessors.ts +7 -0
  140. package/src/transform/sanitize.ts +2 -2
  141. package/src/transform/typings.ts +27 -2
  142. package/src/transform/utilsFS.ts +19 -7
  143. package/src/transform/yfmlint/index.ts +18 -5
  144. package/src/transform/yfmlint/markdownlint-custom-rule/yfm001.ts +0 -1
  145. package/src/transform/yfmlint/typings.ts +5 -0
  146. package/src/transform/yfmlint/utils.ts +4 -2
  147. package/src/transform/yfmlint/yfmlint.ts +2 -1
@@ -1,5 +1,6 @@
1
- import {readFileSync, statSync} from 'fs';
2
1
  import type {Dictionary} from 'lodash';
2
+
3
+ import {readFileSync, statSync} from 'fs';
3
4
  import escapeRegExp from 'lodash/escapeRegExp';
4
5
  import {join, parse, relative, resolve, sep} from 'path';
5
6
 
@@ -35,6 +36,7 @@ export type GetFileTokensOpts = {
35
36
  disableCircularError?: boolean;
36
37
  inheritVars?: boolean;
37
38
  conditionsInCode?: boolean;
39
+ content?: string;
38
40
  };
39
41
 
40
42
  export function getFileTokens(path: string, state: StateCore, options: GetFileTokensOpts) {
@@ -49,15 +51,18 @@ export function getFileTokens(path: string, state: StateCore, options: GetFileTo
49
51
  inheritVars = true,
50
52
  conditionsInCode,
51
53
  } = options;
52
- let content;
54
+ let {content} = options;
53
55
 
54
56
  const builtVars = (getVarsPerFile && !inheritVars ? getVarsPerFile(path) : vars) || {};
55
57
 
56
- if (filesCache[path]) {
57
- content = filesCache[path];
58
- } else {
59
- content = readFileSync(path, 'utf8');
60
- filesCache[path] = content;
58
+ // Read the content only if we dont have one in the args
59
+ if (!content) {
60
+ if (filesCache[path]) {
61
+ content = filesCache[path];
62
+ } else {
63
+ content = readFileSync(path, 'utf8');
64
+ filesCache[path] = content;
65
+ }
61
66
  }
62
67
 
63
68
  let sourceMap;
@@ -148,3 +153,10 @@ export function getPublicPath(
148
153
  const href = transformer(filePath);
149
154
  return href;
150
155
  }
156
+
157
+ export function getRelativePath(path: string, toPath: string) {
158
+ const pathDirs = path.split(sep);
159
+ pathDirs.pop();
160
+ const parentPath = pathDirs.join(sep);
161
+ return relative(parentPath, toPath);
162
+ }
@@ -1,9 +1,14 @@
1
+ import type {Dictionary} from 'lodash';
2
+
1
3
  import {Rule, sync} from 'markdownlint';
2
4
  import merge from 'lodash/merge';
3
5
  import union from 'lodash/union';
4
6
  import attrs from 'markdown-it-attrs';
5
- import baseDefaultLintConfig from './yfmlint';
6
7
 
8
+ import {LogLevels, Logger} from '../log';
9
+ import defaultPreprocessors from '../preprocessors';
10
+
11
+ import baseDefaultLintConfig from './yfmlint';
7
12
  import {
8
13
  yfm001,
9
14
  yfm002,
@@ -14,11 +19,8 @@ import {
14
19
  yfm007,
15
20
  yfm008,
16
21
  } from './markdownlint-custom-rule';
17
-
18
22
  import {errorToString, getLogLevel} from './utils';
19
23
  import {Options} from './typings';
20
- import type {Dictionary} from 'lodash';
21
- import {LogLevels, Logger} from '../log';
22
24
  import {yfm009} from './markdownlint-custom-rule/yfm009';
23
25
 
24
26
  const defaultLintRules = [yfm001, yfm002, yfm003, yfm004, yfm005, yfm006, yfm007, yfm008, yfm009];
@@ -26,7 +28,14 @@ const defaultLintRules = [yfm001, yfm002, yfm003, yfm004, yfm005, yfm006, yfm007
26
28
  const lintCache = new Set();
27
29
 
28
30
  function yfmlint(opts: Options) {
29
- const {input, plugins: customPlugins, pluginOptions, customLintRules, sourceMap} = opts;
31
+ let {input} = opts;
32
+ const {
33
+ plugins: customPlugins,
34
+ preprocessors = defaultPreprocessors,
35
+ pluginOptions,
36
+ customLintRules,
37
+ sourceMap,
38
+ } = opts;
30
39
  const {path = 'input', log} = pluginOptions;
31
40
 
32
41
  pluginOptions.isLintRun = true;
@@ -56,6 +65,10 @@ function yfmlint(opts: Options) {
56
65
  const plugins = customPlugins && [attrs, ...customPlugins];
57
66
  const preparedPlugins = plugins && plugins.map((plugin) => [plugin, pluginOptions]);
58
67
 
68
+ for (const preprocessor of preprocessors) {
69
+ input = preprocessor(input, pluginOptions);
70
+ }
71
+
59
72
  let result;
60
73
  try {
61
74
  result = sync({
@@ -1,6 +1,5 @@
1
1
  // @ts-expect-error
2
2
  import {addErrorDetailIf, filterTokens, forEachInlineCodeSpan} from 'markdownlint-rule-helpers';
3
-
4
3
  import {MarkdownItToken, Rule} from 'markdownlint';
5
4
 
6
5
  export const yfm001: Rule = {
@@ -1,10 +1,15 @@
1
1
  import type {Dictionary} from 'lodash';
2
+
2
3
  import {Plugin, Rule} from 'markdownlint';
4
+
5
+ import {MarkdownItPreprocessorCb} from '../typings';
6
+
3
7
  import {LintConfig, PluginOptions} from '.';
4
8
 
5
9
  export interface Options {
6
10
  input: string;
7
11
  plugins?: Function[] | Plugin;
12
+ preprocessors?: MarkdownItPreprocessorCb[];
8
13
  pluginOptions: PluginOptions;
9
14
  defaultLintConfig?: LintConfig;
10
15
  lintConfig?: LintConfig;
@@ -1,8 +1,10 @@
1
- import {LogLevels} from '../log';
2
- import {LintError} from 'markdownlint';
3
1
  import type {Dictionary} from 'lodash';
2
+
3
+ import {LintError} from 'markdownlint';
4
4
  import {sep} from 'path';
5
5
 
6
+ import {LogLevels} from '../log';
7
+
6
8
  export function errorToString(path: string, error: LintError, sourceMap?: Dictionary<string>) {
7
9
  const ruleMoniker = error.ruleNames
8
10
  ? error.ruleNames.join(sep)
@@ -1,6 +1,7 @@
1
- import {LintConfig} from '.';
2
1
  import {LogLevels} from '../log';
3
2
 
3
+ import {LintConfig} from '.';
4
+
4
5
  const index: LintConfig = {
5
6
  // Default state for all rules
6
7
  default: true,