@diplodoc/transform 4.68.1 → 4.68.3

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.
@@ -17,11 +17,17 @@ export const CheckboxTokenType = {
17
17
 
18
18
  type ParsedCheckbox = {
19
19
  tokens: Token[];
20
+ content: string;
20
21
  startLine: number;
21
22
  endLine: number;
22
23
  checked: boolean;
23
24
  };
24
25
 
26
+ type ContentLine = {
27
+ tokens: Token[];
28
+ content: string;
29
+ };
30
+
25
31
  function matchOpenToken(tokens: Token[], i: number) {
26
32
  if (tokens[i].type !== 'paragraph_open' || tokens[i + 1].type !== 'inline') {
27
33
  return false;
@@ -90,7 +96,11 @@ export const checkboxReplace = function (_md: MarkdownIt, opts?: CheckboxOptions
90
96
  /**
91
97
  * content of label tag
92
98
  */
93
- nodes.push(...checkbox.tokens);
99
+ token = new state.Token('inline', '', 0);
100
+ token.content = checkbox.content;
101
+ token.children = checkbox.tokens;
102
+ token.map = [checkbox.startLine, checkbox.endLine];
103
+ nodes.push(token);
94
104
 
95
105
  /**
96
106
  * closing tags
@@ -123,6 +133,7 @@ export const checkboxReplace = function (_md: MarkdownIt, opts?: CheckboxOptions
123
133
  const first = checkbox.tokens[0];
124
134
  // remove checkbox markup [X]␣ at start of text content
125
135
  first.content = first.content.slice(4);
136
+ checkbox.content = checkbox.content.trim().slice(4);
126
137
  checkboxTokens.push(...createTokens(state, checkbox));
127
138
  }
128
139
 
@@ -136,17 +147,22 @@ export const checkboxReplace = function (_md: MarkdownIt, opts?: CheckboxOptions
136
147
  };
137
148
 
138
149
  function parseInlineContent(inlineToken: Token, startLine: number): ParsedCheckbox[] {
139
- const children = inlineToken.children || [];
140
- const lines = splitInlineTokensByBreaks(children);
150
+ const lines = splitInlineTokensByBreaks(inlineToken);
141
151
  return parseCheckboxesByLines(lines, startLine);
142
152
  }
143
153
 
144
- function splitInlineTokensByBreaks(tokens: Token[]): Token[][] {
145
- const lines: Token[][] = [];
154
+ function splitInlineTokensByBreaks(inlineToken: Token): ContentLine[] {
155
+ const tokens = inlineToken.children || [];
156
+ const contentLines = inlineToken.content.split('\n');
157
+
158
+ const lines: ContentLine[] = [];
146
159
  let lineIdx = 0;
147
160
  for (const token of tokens) {
148
- lines[lineIdx] ||= [];
149
- lines[lineIdx].push(token);
161
+ lines[lineIdx] ||= {
162
+ tokens: [],
163
+ content: contentLines[lineIdx],
164
+ };
165
+ lines[lineIdx].tokens.push(token);
150
166
 
151
167
  if (isBreakToken(token)) {
152
168
  lineIdx += 1;
@@ -156,13 +172,13 @@ function splitInlineTokensByBreaks(tokens: Token[]): Token[][] {
156
172
  return lines;
157
173
  }
158
174
 
159
- function parseCheckboxesByLines(lines: Token[][], startLine: number): ParsedCheckbox[] {
175
+ function parseCheckboxesByLines(lines: ContentLine[], startLine: number): ParsedCheckbox[] {
160
176
  const checkboxes: ParsedCheckbox[] = [];
161
177
 
162
178
  let checkboxIdx = -1;
163
179
  for (let lineIdx = 0; lineIdx < lines.length; lineIdx++) {
164
180
  const line = lines[lineIdx];
165
- const first = line?.[0];
181
+ const first = line?.tokens[0];
166
182
  if (!first) {
167
183
  continue;
168
184
  }
@@ -178,13 +194,15 @@ function parseCheckboxesByLines(lines: Token[][], startLine: number): ParsedChec
178
194
  checkboxIdx += 1;
179
195
  checkboxes[checkboxIdx] ||= {
180
196
  tokens: [],
197
+ content: '',
181
198
  checked: isChecked(match[1]),
182
199
  startLine: startLine + lineIdx,
183
200
  endLine: startLine + lineIdx + 1,
184
201
  };
185
202
  }
186
203
 
187
- checkboxes[checkboxIdx].tokens.push(...line);
204
+ checkboxes[checkboxIdx].tokens.push(...line.tokens);
205
+ checkboxes[checkboxIdx].content += line.content + '\n';
188
206
  checkboxes[checkboxIdx].endLine = startLine + lineIdx + 1;
189
207
  }
190
208
 
@@ -49,15 +49,26 @@ interface SVGOpts extends MarkdownItPluginOpts {
49
49
 
50
50
  function getSvgContent(file: string, from: string, {rawContent, notFoundCb, log, root = ''}: Opts) {
51
51
  try {
52
- return rawContent(file);
52
+ const content = rawContent(file);
53
+
54
+ if (!content || typeof content !== 'string') {
55
+ return null;
56
+ }
57
+
58
+ return content;
53
59
  } catch {
54
60
  const path = file.replace(root, '');
55
61
  // Normalize path separators to forward slashes for cross-platform compatibility
56
62
  const normalizedPath = path.replace(/\\/g, '/');
57
63
  log.error(`SVG ${normalizedPath} from ${from} not found`);
58
64
 
59
- if (notFoundCb) {
60
- notFoundCb(normalizedPath);
65
+ try {
66
+ if (notFoundCb) {
67
+ notFoundCb(normalizedPath);
68
+ }
69
+ } catch {
70
+ // notFoundCb may throw in some backends (e.g. memcache)
71
+ // to signal that the file needs to be fetched
61
72
  }
62
73
 
63
74
  return null;