@diplodoc/transform 4.32.4 → 4.34.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.
@@ -0,0 +1 @@
1
+ import './term';
package/src/js/base.ts ADDED
@@ -0,0 +1,2 @@
1
+ import './polyfill';
2
+ import './code';
package/src/js/index.ts CHANGED
@@ -1,8 +1,7 @@
1
1
  import '@diplodoc/cut-extension/runtime';
2
2
  import '@diplodoc/tabs-extension/runtime';
3
3
 
4
- import './polyfill';
5
- import './code';
6
- import './term';
4
+ import './base';
5
+ import './_yfm-only';
7
6
  import './wide-mode';
8
7
  import './patch';
@@ -0,0 +1,12 @@
1
+ /**
2
+ Note: This file excludes "cut" and "tabs" as they are handled separately
3
+ in dedicated extensions (packages). In the future, "note", "file", "term"
4
+ and "table" will also be excluded from this file and moved to yfm.scss,
5
+ once they are moved to separate packages. Direct usage is not recommended,
6
+ as the file is subject to changes without prior notice.
7
+ */
8
+
9
+ @import 'note';
10
+ @import 'file';
11
+ @import 'table';
12
+ @import 'term';
@@ -0,0 +1,4 @@
1
+ @import 'common';
2
+ @import 'anchor';
3
+ @import 'highlight';
4
+ @import 'code';
package/src/scss/yfm.scss CHANGED
@@ -1,12 +1,5 @@
1
- @import 'common';
2
- @import 'note';
3
- @import 'anchor';
4
- @import 'highlight';
5
- @import 'code';
6
- @import 'file';
7
- @import 'term';
8
- @import 'table';
1
+ @import 'base';
2
+ @import 'yfm-only';
9
3
  @import 'modal';
10
-
11
4
  @import '@diplodoc/cut-extension/runtime';
12
5
  @import '@diplodoc/tabs-extension/runtime';
@@ -12,7 +12,6 @@ function processRecursive(
12
12
  includePath: string,
13
13
  targetDestPath: string,
14
14
  options: IncludeCollectOpts,
15
- appendix: Map<string, string>,
16
15
  ) {
17
16
  const {path, log, copyFile, includedParentPath: includedParentPathNullable, included} = options;
18
17
  const includedParentPath = includedParentPathNullable || path;
@@ -34,20 +33,16 @@ function processRecursive(
34
33
  const includedRelativePath = getRelativePath(includedParentPath, includePath);
35
34
 
36
35
  // The appendix is the map that protects from multiple include files
37
- if (!appendix.has(includedRelativePath)) {
36
+ if (!options.appendix?.has(includedRelativePath)) {
38
37
  // Recursive function to include the depth structure
39
- const includeContent = collectRecursive(
40
- content,
41
- {
42
- ...options,
43
- path: includePath,
44
- includedParentPath,
45
- },
46
- appendix,
47
- );
38
+ const includeContent = collectRecursive(content, {
39
+ ...options,
40
+ path: includePath,
41
+ includedParentPath,
42
+ });
48
43
 
49
44
  // Add to appendix set structure
50
- appendix.set(
45
+ options.appendix?.set(
51
46
  includedRelativePath,
52
47
  `{% included (${includedRelativePath}) %}\n${includeContent}\n{% endincluded %}`,
53
48
  );
@@ -59,11 +54,7 @@ function processRecursive(
59
54
  }
60
55
  }
61
56
 
62
- function collectRecursive(
63
- result: string,
64
- options: IncludeCollectOpts,
65
- appendix: Map<string, string>,
66
- ) {
57
+ function collectRecursive(result: string, options: IncludeCollectOpts) {
67
58
  const {root, path, destPath = '', log, singlePage} = options;
68
59
 
69
60
  const INCLUDE_REGEXP = /{%\s*include\s*(notitle)?\s*\[(.+?)]\((.+?)\)\s*%}/g;
@@ -100,7 +91,7 @@ function collectRecursive(
100
91
 
101
92
  includesPaths.push(includePath);
102
93
 
103
- processRecursive(includePath, targetDestPath, options, appendix);
94
+ processRecursive(includePath, targetDestPath, options);
104
95
 
105
96
  includesPaths.pop();
106
97
  }
@@ -109,14 +100,16 @@ function collectRecursive(
109
100
  }
110
101
 
111
102
  function collect(input: string, options: IncludeCollectOpts) {
112
- const appendix: Map<string, string> = new Map();
103
+ const shouldWriteAppendix = !options.appendix;
104
+
105
+ options.appendix = options.appendix ?? new Map();
113
106
 
114
- input = collectRecursive(input, options, appendix);
107
+ input = collectRecursive(input, options);
115
108
 
116
- if (!options.path.includes('_includes')) {
109
+ if (shouldWriteAppendix) {
117
110
  // Appendix should be appended to the end of the file (it supports depth structure, so the included files will have included as well)
118
- if (appendix.size > 0) {
119
- input += '\n' + [...appendix.values()].join('\n');
111
+ if (options.appendix.size > 0) {
112
+ input += '\n' + [...options.appendix.values()].join('\n');
120
113
  }
121
114
  }
122
115
 
@@ -14,4 +14,5 @@ export type IncludeCollectOpts = MarkdownItPluginOpts & {
14
14
  included: Boolean;
15
15
  includedParentPath?: string;
16
16
  additionalIncludedList?: string[];
17
+ appendix?: Map<string, string>;
17
18
  };
@@ -74,7 +74,7 @@ const index: MarkdownItPreprocessorCb<{
74
74
 
75
75
  // To reduce file reading we can include the file content into the generated content
76
76
  if (included) {
77
- const lines = input.split('\n') || [];
77
+ const lines = input?.split('\n') || [];
78
78
 
79
79
  // The finction reads the files from bottom to top(!). It stops the loop if it does not have anything to swap.
80
80
  // If the function finds something to process then it restarts the loop because the position of the last element has been moved.