gtx-cli 2.1.18 → 2.1.20

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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # gtx-cli
2
2
 
3
+ ## 2.1.20
4
+
5
+ ### Patch Changes
6
+
7
+ - [#643](https://github.com/generaltranslation/gt/pull/643) [`4f553c0`](https://github.com/generaltranslation/gt/commit/4f553c00c119f272edc5ccb3616f2d0effec8586) Thanks [@fernando-aviles](https://github.com/fernando-aviles)! - Removing custom configuration on remarkStringify
8
+
9
+ ## 2.1.19
10
+
11
+ ### Patch Changes
12
+
13
+ - [#641](https://github.com/generaltranslation/gt/pull/641) [`4c67f77`](https://github.com/generaltranslation/gt/commit/4c67f775ee892b47eebcc3178c00ad6547a84d84) Thanks [@fernando-aviles](https://github.com/fernando-aviles)! - Encoding placeholders that break MDX parse
14
+
3
15
  ## 2.1.18
4
16
 
5
17
  ### Patch Changes
@@ -5,6 +5,7 @@ import remarkFrontmatter from 'remark-frontmatter';
5
5
  import remarkStringify from 'remark-stringify';
6
6
  import { visit } from 'unist-util-visit';
7
7
  import { logWarning } from '../console/logging.js';
8
+ import { encodeAnglePlaceholders } from './encodePlaceholders.js';
8
9
  /**
9
10
  * Generates a slug from heading text
10
11
  */
@@ -158,13 +159,13 @@ function applyInlineIds(translatedContent, idMappings) {
158
159
  // Add the ID to the heading
159
160
  const lastChild = heading.children[heading.children.length - 1];
160
161
  if (lastChild?.type === 'text') {
161
- lastChild.value += ` {#${id}}`;
162
+ lastChild.value += ` \\{#${id}\\}`;
162
163
  }
163
164
  else {
164
165
  // If last child is not text, add a new text node
165
166
  heading.children.push({
166
167
  type: 'text',
167
- value: ` {#${id}}`,
168
+ value: ` \\{#${id}\\}`,
168
169
  });
169
170
  }
170
171
  }
@@ -173,23 +174,19 @@ function applyInlineIds(translatedContent, idMappings) {
173
174
  // Convert the modified AST back to MDX string
174
175
  try {
175
176
  const stringifyProcessor = unified()
177
+ .use(remarkFrontmatter, ['yaml', 'toml'])
178
+ .use(remarkMdx)
179
+ .use(encodeAnglePlaceholders)
176
180
  .use(remarkStringify, {
177
- bullet: '-',
178
- emphasis: '_',
179
- strong: '*',
180
- rule: '-',
181
- ruleRepetition: 3,
182
- ruleSpaces: false,
183
181
  handlers: {
184
182
  // Custom handler to prevent escaping of {#id} syntax
185
183
  text(node) {
186
184
  return node.value;
187
185
  },
188
186
  },
189
- })
190
- .use(remarkFrontmatter, ['yaml', 'toml'])
191
- .use(remarkMdx);
192
- let content = stringifyProcessor.stringify(processedAst);
187
+ });
188
+ const outTree = stringifyProcessor.runSync(processedAst);
189
+ let content = stringifyProcessor.stringify(outTree);
193
190
  // Handle newline formatting to match original input
194
191
  if (content.endsWith('\n') && !translatedContent.endsWith('\n')) {
195
192
  content = content.slice(0, -1);
@@ -0,0 +1,11 @@
1
+ import type { Plugin } from 'unified';
2
+ import type { Root } from 'mdast';
3
+ /**
4
+ * Re-encode angle-bracket placeholders like <accountName> -> &lt;accountName&gt;
5
+ * in plain text, to prevent MDX JSX parsing on re-parse.
6
+ *
7
+ * - Only touches Text nodes.
8
+ * - Idempotent: already-encoded entities are left unchanged.
9
+ * - Does NOT affect actual MDX/JSX elements because those are not text nodes.
10
+ */
11
+ export declare const encodeAnglePlaceholders: Plugin<[], Root>;
@@ -0,0 +1,30 @@
1
+ import { findAndReplace } from 'mdast-util-find-and-replace';
2
+ const IGNORE_PARENTS = [
3
+ 'code',
4
+ 'inlineCode',
5
+ 'mdxFlowExpression',
6
+ 'mdxTextExpression',
7
+ 'mdxjsEsm',
8
+ 'yaml',
9
+ 'toml',
10
+ 'math',
11
+ 'inlineMath',
12
+ ];
13
+ /**
14
+ * Re-encode angle-bracket placeholders like <accountName> -> &lt;accountName&gt;
15
+ * in plain text, to prevent MDX JSX parsing on re-parse.
16
+ *
17
+ * - Only touches Text nodes.
18
+ * - Idempotent: already-encoded entities are left unchanged.
19
+ * - Does NOT affect actual MDX/JSX elements because those are not text nodes.
20
+ */
21
+ export const encodeAnglePlaceholders = function () {
22
+ return (tree) => {
23
+ findAndReplace(tree, [
24
+ [
25
+ /<([A-Za-z][\w.-]*)>/g, // <content>, <con-tent>, <con.tent>, <con_tent>
26
+ (_match, name) => `&lt;${name}&gt;`,
27
+ ],
28
+ ], { ignore: IGNORE_PARENTS });
29
+ };
30
+ };
@@ -7,6 +7,7 @@ import remarkMdx from 'remark-mdx';
7
7
  import remarkFrontmatter from 'remark-frontmatter';
8
8
  import remarkStringify from 'remark-stringify';
9
9
  import { visit } from 'unist-util-visit';
10
+ import { encodeAnglePlaceholders } from './encodePlaceholders.js';
10
11
  const { isMatch } = micromatch;
11
12
  /**
12
13
  * Localizes static urls in content files.
@@ -370,17 +371,19 @@ function transformMdxUrls(mdxContent, defaultLocale, targetLocale, hideDefaultLo
370
371
  let content;
371
372
  try {
372
373
  const stringifyProcessor = unified()
373
- .use(remarkStringify, {
374
- bullet: '-',
375
- emphasis: '_',
376
- strong: '*',
377
- rule: '-',
378
- ruleRepetition: 3,
379
- ruleSpaces: false,
380
- })
381
374
  .use(remarkFrontmatter, ['yaml', 'toml'])
382
- .use(remarkMdx);
383
- content = stringifyProcessor.stringify(processedAst);
375
+ .use(remarkMdx)
376
+ .use(encodeAnglePlaceholders)
377
+ .use(remarkStringify, {
378
+ handlers: {
379
+ // Handler to prevent escaping (avoids '&lt;' -> '\&lt;')
380
+ text(node) {
381
+ return node.value;
382
+ },
383
+ },
384
+ });
385
+ const outTree = stringifyProcessor.runSync(processedAst);
386
+ content = stringifyProcessor.stringify(outTree);
384
387
  }
385
388
  catch (error) {
386
389
  console.warn(`Failed to stringify MDX content: ${error instanceof Error ? error.message : String(error)}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gtx-cli",
3
- "version": "2.1.18",
3
+ "version": "2.1.20",
4
4
  "main": "dist/index.js",
5
5
  "bin": "dist/main.js",
6
6
  "files": [
@@ -91,6 +91,7 @@
91
91
  "json-pointer": "^0.6.2",
92
92
  "jsonpath-plus": "^10.3.0",
93
93
  "jsonpointer": "^5.0.1",
94
+ "mdast-util-find-and-replace": "^3.0.2",
94
95
  "micromatch": "^4.0.8",
95
96
  "open": "^10.1.1",
96
97
  "ora": "^8.2.0",