@diplodoc/transform 4.65.3 → 4.67.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.
Files changed (183) hide show
  1. package/README.md +56 -3
  2. package/dist/css/_yfm-only.css +3 -1
  3. package/dist/css/_yfm-only.css.map +3 -3
  4. package/dist/css/_yfm-only.min.css +1 -1
  5. package/dist/css/_yfm-only.min.css.map +3 -3
  6. package/dist/css/base.css +2 -0
  7. package/dist/css/base.css.map +3 -3
  8. package/dist/css/base.min.css.map +3 -3
  9. package/dist/css/print.css.map +3 -3
  10. package/dist/css/yfm.css +5 -1
  11. package/dist/css/yfm.css.map +3 -3
  12. package/dist/css/yfm.min.css +1 -1
  13. package/dist/css/yfm.min.css.map +3 -3
  14. package/dist/js/base.js +2 -22
  15. package/dist/js/base.js.map +1 -1
  16. package/dist/js/base.min.js +3 -3
  17. package/dist/js/base.min.js.map +2 -2
  18. package/dist/js/yfm.js +27 -57
  19. package/dist/js/yfm.js.map +3 -3
  20. package/dist/js/yfm.min.js +3 -3
  21. package/dist/js/yfm.min.js.map +3 -3
  22. package/dist/scss/_common.scss +6 -4
  23. package/dist/scss/_note.scss +10 -8
  24. package/dist/scss/print/code.scss +1 -1
  25. package/dist/scss/print/common.scss +3 -2
  26. package/dist/scss/print/table.scss +3 -2
  27. package/dist/scss/print/term.scss +1 -1
  28. package/lib/frontmatter.d.ts +1 -1
  29. package/lib/frontmatter.js.map +1 -1
  30. package/lib/getObject.js.map +1 -1
  31. package/lib/headings.js.map +1 -1
  32. package/lib/highlight.js +1 -1
  33. package/lib/highlight.js.map +1 -1
  34. package/lib/index.d.ts +1 -1
  35. package/lib/index.js +1 -1
  36. package/lib/index.js.map +1 -1
  37. package/lib/liquid/conditions.js.map +1 -1
  38. package/lib/liquid/cycles.js +1 -1
  39. package/lib/liquid/cycles.js.map +1 -1
  40. package/lib/liquid/evaluation.js +21 -11
  41. package/lib/liquid/evaluation.js.map +1 -1
  42. package/lib/liquid/filters.js +3 -4
  43. package/lib/liquid/filters.js.map +1 -1
  44. package/lib/liquid/index.js +3 -4
  45. package/lib/liquid/index.js.map +1 -1
  46. package/lib/liquid/legacyConditions.js.map +1 -1
  47. package/lib/liquid/lexical.js +5 -5
  48. package/lib/liquid/lexical.js.map +1 -1
  49. package/lib/liquid/services/argv.d.ts +1 -1
  50. package/lib/liquid/services/argv.js +3 -4
  51. package/lib/liquid/services/argv.js.map +1 -1
  52. package/lib/liquid/sourceMap.d.ts +2 -2
  53. package/lib/liquid/sourceMap.js +3 -4
  54. package/lib/liquid/sourceMap.js.map +1 -1
  55. package/lib/liquid/substitutions.js.map +1 -1
  56. package/lib/liquid/utils.d.ts +1 -1
  57. package/lib/liquid/utils.js +2 -3
  58. package/lib/liquid/utils.js.map +1 -1
  59. package/lib/log.d.ts +1 -1
  60. package/lib/log.js +1 -1
  61. package/lib/log.js.map +1 -1
  62. package/lib/md.d.ts +5 -5
  63. package/lib/md.js +31 -22
  64. package/lib/md.js.map +1 -1
  65. package/lib/plugins/anchors/collect.js.map +1 -1
  66. package/lib/plugins/anchors/index.js.map +1 -1
  67. package/lib/plugins/block-anchor/block-anchor.js +3 -3
  68. package/lib/plugins/block-anchor/block-anchor.js.map +1 -1
  69. package/lib/plugins/block-anchor/index.js +1 -1
  70. package/lib/plugins/block-anchor/index.js.map +1 -1
  71. package/lib/plugins/changelog/collect.d.ts +1 -1
  72. package/lib/plugins/changelog/collect.js.map +1 -1
  73. package/lib/plugins/changelog/index.js +6 -3
  74. package/lib/plugins/changelog/index.js.map +1 -1
  75. package/lib/plugins/checkbox/checkbox.d.ts +1 -1
  76. package/lib/plugins/checkbox/checkbox.js +83 -23
  77. package/lib/plugins/checkbox/checkbox.js.map +1 -1
  78. package/lib/plugins/code.js.map +1 -1
  79. package/lib/plugins/cut.d.ts +1 -1
  80. package/lib/plugins/deflist.d.ts +1 -1
  81. package/lib/plugins/images/collect.d.ts +1 -1
  82. package/lib/plugins/images/collect.js.map +1 -1
  83. package/lib/plugins/images/index.d.ts +1 -1
  84. package/lib/plugins/images/index.js +16 -7
  85. package/lib/plugins/images/index.js.map +1 -1
  86. package/lib/plugins/imsize/const.js +1 -1
  87. package/lib/plugins/imsize/const.js.map +1 -1
  88. package/lib/plugins/imsize/helpers.js +1 -2
  89. package/lib/plugins/imsize/helpers.js.map +1 -1
  90. package/lib/plugins/imsize/plugin.d.ts +1 -1
  91. package/lib/plugins/imsize/plugin.js.map +1 -1
  92. package/lib/plugins/includes/collect.js +11 -3
  93. package/lib/plugins/includes/collect.js.map +1 -1
  94. package/lib/plugins/includes/index.d.ts +1 -1
  95. package/lib/plugins/includes/index.js +5 -3
  96. package/lib/plugins/includes/index.js.map +1 -1
  97. package/lib/plugins/includes/types.d.ts +1 -1
  98. package/lib/plugins/links/collect.d.ts +1 -1
  99. package/lib/plugins/links/collect.js +1 -1
  100. package/lib/plugins/links/collect.js.map +1 -1
  101. package/lib/plugins/links/index.d.ts +1 -1
  102. package/lib/plugins/links/index.js +35 -12
  103. package/lib/plugins/links/index.js.map +1 -1
  104. package/lib/plugins/meta.js.map +1 -1
  105. package/lib/plugins/monospace.js +1 -1
  106. package/lib/plugins/monospace.js.map +1 -1
  107. package/lib/plugins/notes/index.d.ts +1 -1
  108. package/lib/plugins/notes/index.js +1 -1
  109. package/lib/plugins/notes/index.js.map +1 -1
  110. package/lib/plugins/ol-attr-conversion.js.map +1 -1
  111. package/lib/plugins/sup.d.ts +1 -1
  112. package/lib/plugins/table/index.js +7 -18
  113. package/lib/plugins/table/index.js.map +1 -1
  114. package/lib/plugins/table/types.d.ts +1 -1
  115. package/lib/plugins/tabs.d.ts +3 -3
  116. package/lib/plugins/term/index.js.map +1 -1
  117. package/lib/plugins/term/termDefinitions.js +1 -2
  118. package/lib/plugins/term/termDefinitions.js.map +1 -1
  119. package/lib/plugins/utils.d.ts +1 -1
  120. package/lib/plugins/utils.js +3 -3
  121. package/lib/plugins/utils.js.map +1 -1
  122. package/lib/plugins/video/const.js +1 -1
  123. package/lib/plugins/video/const.js.map +1 -1
  124. package/lib/plugins/video/index.js +1 -1
  125. package/lib/plugins/video/index.js.map +1 -1
  126. package/lib/plugins/video/parsers.js +9 -10
  127. package/lib/plugins/video/parsers.js.map +1 -1
  128. package/lib/plugins/video/types.d.ts +8 -8
  129. package/lib/plugins/video/utils.js.map +1 -1
  130. package/lib/plugins.d.ts +1 -1
  131. package/lib/preprocessors/included/index.js.map +1 -1
  132. package/lib/preprocessors/index.d.ts +1 -1
  133. package/lib/preprocessors/index.js +1 -2
  134. package/lib/preprocessors/index.js.map +1 -1
  135. package/lib/sanitize.d.ts +1 -1
  136. package/lib/sanitize.js +54 -26
  137. package/lib/sanitize.js.map +1 -1
  138. package/lib/title.js.map +1 -1
  139. package/lib/typings.d.ts +10 -10
  140. package/lib/utils.d.ts +1 -1
  141. package/lib/utils.js +16 -13
  142. package/lib/utils.js.map +1 -1
  143. package/lib/utilsFS.d.ts +2 -1
  144. package/lib/utilsFS.js +45 -15
  145. package/lib/utilsFS.js.map +1 -1
  146. package/lib/yfmlint/index.js +4 -1
  147. package/lib/yfmlint/index.js.map +1 -1
  148. package/lib/yfmlint/markdownlint-custom-rule/yfm001.js.map +1 -1
  149. package/lib/yfmlint/markdownlint-custom-rule/yfm002.js.map +1 -1
  150. package/lib/yfmlint/markdownlint-custom-rule/yfm003.js.map +1 -1
  151. package/lib/yfmlint/markdownlint-custom-rule/yfm004.js.map +1 -1
  152. package/lib/yfmlint/markdownlint-custom-rule/yfm005.js.map +1 -1
  153. package/lib/yfmlint/markdownlint-custom-rule/yfm006.js.map +1 -1
  154. package/lib/yfmlint/markdownlint-custom-rule/yfm007.js.map +1 -1
  155. package/lib/yfmlint/markdownlint-custom-rule/yfm008.js.map +1 -1
  156. package/lib/yfmlint/markdownlint-custom-rule/yfm009.js.map +1 -1
  157. package/lib/yfmlint/utils.js +6 -6
  158. package/lib/yfmlint/utils.js.map +1 -1
  159. package/lib/yfmlint/yfmlint.js +60 -60
  160. package/lib/yfmlint/yfmlint.js.map +1 -1
  161. package/package.json +12 -11
  162. package/src/scss/_common.scss +6 -4
  163. package/src/scss/_note.scss +10 -8
  164. package/src/scss/print/code.scss +1 -1
  165. package/src/scss/print/common.scss +3 -2
  166. package/src/scss/print/table.scss +3 -2
  167. package/src/scss/print/term.scss +1 -1
  168. package/src/transform/highlight.ts +1 -1
  169. package/src/transform/liquid/evaluation.ts +2 -2
  170. package/src/transform/plugins/block-anchor/index.ts +1 -1
  171. package/src/transform/plugins/changelog/index.ts +1 -1
  172. package/src/transform/plugins/checkbox/checkbox.ts +104 -26
  173. package/src/transform/plugins/images/index.ts +8 -6
  174. package/src/transform/plugins/includes/collect.ts +1 -1
  175. package/src/transform/plugins/includes/index.ts +5 -3
  176. package/src/transform/plugins/links/index.ts +7 -3
  177. package/src/transform/plugins/notes/index.ts +1 -1
  178. package/src/transform/plugins/video/types.ts +1 -1
  179. package/src/transform/sanitize.ts +1 -1
  180. package/src/transform/utils.ts +2 -2
  181. package/src/transform/utilsFS.ts +33 -6
  182. package/src/transform/yfmlint/index.ts +5 -1
  183. package/src/transform/yfmlint/utils.ts +4 -4
@@ -32,8 +32,8 @@ function replaceImageSrc(
32
32
 
33
33
  const relativeToRoot = path.replace(root + sep, '');
34
34
  const publicSrc = join(assetsPublicPath, relativeToRoot);
35
-
36
- return publicSrc;
35
+ // Normalize path separators to forward slashes for cross-platform compatibility
36
+ return publicSrc.replace(/\\/g, '/');
37
37
  }
38
38
 
39
39
  interface InlineOptions {
@@ -50,12 +50,14 @@ interface SVGOpts extends MarkdownItPluginOpts {
50
50
  function getSvgContent(file: string, from: string, {rawContent, notFoundCb, log, root = ''}: Opts) {
51
51
  try {
52
52
  return rawContent(file);
53
- } catch (e: unknown) {
53
+ } catch {
54
54
  const path = file.replace(root, '');
55
- log.error(`SVG ${path} from ${from} not found`);
55
+ // Normalize path separators to forward slashes for cross-platform compatibility
56
+ const normalizedPath = path.replace(/\\/g, '/');
57
+ log.error(`SVG ${normalizedPath} from ${from} not found`);
56
58
 
57
59
  if (notFoundCb) {
58
- notFoundCb(path);
60
+ notFoundCb(normalizedPath);
59
61
  }
60
62
 
61
63
  return null;
@@ -168,7 +170,7 @@ const index: MarkdownItPluginCb<Opts> = (md, opts) => {
168
170
 
169
171
  try {
170
172
  md.core.ruler.before('includes', 'images', plugin);
171
- } catch (e) {
173
+ } catch {
172
174
  md.core.ruler.push('images', plugin);
173
175
  }
174
176
 
@@ -51,7 +51,7 @@ function processRecursive(
51
51
  }
52
52
  }
53
53
  }
54
- } catch (e) {
54
+ } catch {
55
55
  log.error(`No such file or has no access to ${bold(includePath)} in ${bold(path)}`);
56
56
  }
57
57
  }
@@ -91,11 +91,13 @@ function unfoldIncludes(md: MarkdownItIncluded, state: StateCore, path: string,
91
91
  } catch (e) {
92
92
  // @ts-ignore for some reason typescript fails here
93
93
  const errPath = e.path?.replace(root, '');
94
+ // Normalize path separators to forward slashes for cross-platform compatibility
95
+ const normalizedPath = errPath ? errPath.replace(/\\/g, '/') : errPath;
94
96
 
95
97
  if (notFoundCb) {
96
- notFoundCb(errPath);
98
+ notFoundCb(normalizedPath);
97
99
  }
98
- log.error(`Skip error: ${e} in ${errPath}`);
100
+ log.error(`Skip error: ${e} in ${normalizedPath}`);
99
101
 
100
102
  i++;
101
103
  }
@@ -132,7 +134,7 @@ const index: MarkdownItPluginCb<Options> = (md: MarkdownItIncluded, options) =>
132
134
 
133
135
  try {
134
136
  md.core.ruler.before('curly_attributes', 'includes', plugin);
135
- } catch (e) {
137
+ } catch {
136
138
  md.core.ruler.push('includes', plugin);
137
139
  }
138
140
  };
@@ -117,7 +117,9 @@ function getDefaultPublicPath(
117
117
  },
118
118
  input?: string | null,
119
119
  ) {
120
- return relative(parse(path || '').dir, input || file || '');
120
+ const relativePath = relative(parse(path || '').dir, input || file || '');
121
+ // Normalize path separators to forward slashes for cross-platform compatibility
122
+ return relativePath.replace(/\\/g, '/');
121
123
  }
122
124
 
123
125
  // eslint-disable-next-line complexity
@@ -174,7 +176,9 @@ function processLink(
174
176
  }
175
177
 
176
178
  if (notFoundCb && needShowError) {
177
- notFoundCb(file.replace(root, ''));
179
+ const relativePath = file.replace(root, '');
180
+ // Normalize path separators to forward slashes for cross-platform compatibility
181
+ notFoundCb(relativePath.replace(/\\/g, '/'));
178
182
  }
179
183
 
180
184
  if (needShowError) {
@@ -262,7 +266,7 @@ const index: MarkdownItPluginCb<ProcOpts & Options> = (md: MarkdownItIncluded, o
262
266
 
263
267
  try {
264
268
  md.core.ruler.before('includes', 'links', plugin);
265
- } catch (e) {
269
+ } catch {
266
270
  md.core.ruler.push('links', plugin);
267
271
  }
268
272
  };
@@ -138,7 +138,7 @@ const index: MarkdownItPluginCb<NotesPluginParams> = (
138
138
 
139
139
  try {
140
140
  md.core.ruler.before('curly_attributes', 'notes', plugin);
141
- } catch (e) {
141
+ } catch {
142
142
  md.core.ruler.push('notes', plugin);
143
143
  }
144
144
  };
@@ -7,7 +7,7 @@ export type VideoToken = Token & {
7
7
  };
8
8
 
9
9
  export type VideoServicesOptions = {
10
- [service in VideoService]: {
10
+ [_service in VideoService]: {
11
11
  width: number | string;
12
12
  height: number | string;
13
13
  };
@@ -660,7 +660,7 @@ function normalizeCssValue(value: string): string {
660
660
  // unicode normalization (NFKC) to prevent homograph attacks
661
661
  try {
662
662
  normalized = normalized.normalize('NFKC');
663
- } catch (_) {
663
+ } catch {
664
664
  // silent fail: logging the value could expose sensitive data
665
665
  }
666
666
 
@@ -87,7 +87,7 @@ export function getHrefTokenAttr(token: Token) {
87
87
  let href = token.attrGet('href') || '';
88
88
  try {
89
89
  href = decodeURI(href);
90
- } catch (e) {}
90
+ } catch {}
91
91
 
92
92
  return href;
93
93
  }
@@ -97,7 +97,7 @@ export function getSrcTokenAttr(token: Token) {
97
97
  try {
98
98
  // decodeURI can throw an error https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/URIError
99
99
  src = decodeURI(src);
100
- } catch (e) {}
100
+ } catch {}
101
101
 
102
102
  return src;
103
103
  }
@@ -3,7 +3,7 @@ import type {StateCore} from './typings';
3
3
 
4
4
  import {readFileSync, realpathSync, statSync} from 'fs';
5
5
  import escapeRegExp from 'lodash/escapeRegExp';
6
- import {join, parse, relative, resolve, sep} from 'path';
6
+ import {basename, join, parse, relative, resolve, sep} from 'path';
7
7
  import QuickLRU from 'quick-lru';
8
8
 
9
9
  import liquidSnippet from './liquid';
@@ -17,7 +17,7 @@ export function isFileExists(file: string) {
17
17
  const stats = statSync(file);
18
18
 
19
19
  return stats.isFile();
20
- } catch (e) {
20
+ } catch {
21
21
  return false;
22
22
  }
23
23
  }
@@ -39,6 +39,7 @@ export type GetFileTokensOpts = {
39
39
  inheritVars?: boolean;
40
40
  conditionsInCode?: boolean;
41
41
  content?: string;
42
+ root?: string;
42
43
  };
43
44
 
44
45
  export function getFileTokens(
@@ -87,9 +88,31 @@ export function getFileTokens(
87
88
  content = preprocess(content, options);
88
89
 
89
90
  if (!disableLint && lintMarkdown) {
91
+ // Make path relative to root if root is provided, otherwise use absolute path
92
+ let lintPath = path;
93
+ if (options.root) {
94
+ try {
95
+ // Use path.relative for proper cross-platform path handling
96
+ const relativePath = relative(options.root, path);
97
+ // If relative path doesn't start with '..', it's within root
98
+ if (!relativePath.startsWith('..')) {
99
+ lintPath = relativePath;
100
+ }
101
+ } catch {
102
+ // If relative fails, fall back to string replacement
103
+ if (path.startsWith(options.root)) {
104
+ lintPath = path.replace(options.root, '').replace(/^[/\\]/, '');
105
+ }
106
+ }
107
+ }
108
+ // Normalize path separators to forward slashes for cross-platform compatibility
109
+ const normalizedPath = lintPath.replace(/\\/g, '/');
110
+ // Use only basename for lint error messages to match test expectations
111
+ // This ensures consistent error message format across platforms
112
+ const lintPathForMessage = basename(normalizedPath);
90
113
  lintMarkdown({
91
114
  input: content,
92
- path,
115
+ path: lintPathForMessage,
93
116
  sourceMap,
94
117
  });
95
118
  }
@@ -158,8 +181,10 @@ export function getPublicPath(
158
181
  ) {
159
182
  const currentPath = input || path || '';
160
183
  const filePath = relative(resolve(root || '', rootPublicPath || ''), currentPath);
184
+ // Normalize path separators to forward slashes for cross-platform compatibility
185
+ const normalizedPath = filePath.replace(/\\/g, '/');
161
186
  const transformer = transformLink || defaultTransformLink;
162
- const href = transformer(filePath);
187
+ const href = transformer(normalizedPath);
163
188
  return href;
164
189
  }
165
190
 
@@ -167,13 +192,15 @@ export function getRelativePath(path: string, toPath: string) {
167
192
  const pathDirs = path.split(sep);
168
193
  pathDirs.pop();
169
194
  const parentPath = pathDirs.join(sep);
170
- return relative(parentPath, toPath);
195
+ const relativePath = relative(parentPath, toPath);
196
+ // Normalize path separators to forward slashes for cross-platform compatibility
197
+ return relativePath.replace(/\\/g, '/');
171
198
  }
172
199
 
173
200
  export function getRealPath(symlinkPath: string): string {
174
201
  try {
175
202
  return realpathSync(symlinkPath);
176
- } catch (err) {
203
+ } catch {
177
204
  return symlinkPath;
178
205
  }
179
206
  }
@@ -31,7 +31,11 @@ const lintCache = new Set();
31
31
  function yfmlint(opts: Options) {
32
32
  let {input} = opts;
33
33
  const {plugins: customPlugins, pluginOptions, customLintRules, sourceMap} = opts;
34
- const {path = 'input', log} = pluginOptions;
34
+ const {log} = pluginOptions;
35
+ let {path = 'input'} = pluginOptions;
36
+
37
+ // Normalize path separators to forward slashes for cross-platform compatibility
38
+ path = path.replace(/\\/g, '/');
35
39
 
36
40
  pluginOptions.isLintRun = true;
37
41
 
@@ -2,13 +2,13 @@ import type {Dictionary} from 'lodash';
2
2
  import type {LintError} from 'markdownlint';
3
3
  import type {LogLevels} from '../log';
4
4
 
5
- import {sep} from 'path';
6
-
7
5
  export function errorToString(path: string, error: LintError, sourceMap?: Dictionary<string>) {
6
+ // Use forward slash for rule moniker separator for cross-platform compatibility
7
+ // Rule names like 'YFM001/inline-code-length' should use '/' not platform-specific separator
8
8
  const ruleMoniker = error.ruleNames
9
- ? error.ruleNames.join(sep)
9
+ ? error.ruleNames.join('/')
10
10
  : // @ts-expect-error bad markdownlint typings
11
- error.ruleName + sep + error.ruleAlias;
11
+ error.ruleName + '/' + error.ruleAlias;
12
12
  const lineNumber = sourceMap ? sourceMap[error.lineNumber] : error.lineNumber;
13
13
 
14
14
  return (