gtx-cli 2.1.20 → 2.1.21
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 +6 -0
- package/dist/utils/addExplicitAnchorIds.js +2 -2
- package/dist/utils/escapeHtml.d.ts +8 -0
- package/dist/utils/escapeHtml.js +32 -0
- package/dist/utils/localizeStaticUrls.js +2 -2
- package/package.json +1 -1
- package/dist/utils/encodePlaceholders.d.ts +0 -11
- package/dist/utils/encodePlaceholders.js +0 -30
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# gtx-cli
|
|
2
2
|
|
|
3
|
+
## 2.1.21
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#645](https://github.com/generaltranslation/gt/pull/645) [`58cfaee`](https://github.com/generaltranslation/gt/commit/58cfaee5cc1dcd187f0b72b2761f96c19b4f313e) Thanks [@fernando-aviles](https://github.com/fernando-aviles)! - Escaping HTML to avoid parsing issues from MDX consumers
|
|
8
|
+
|
|
3
9
|
## 2.1.20
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
|
@@ -5,7 +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 {
|
|
8
|
+
import { escapeHtmlInTextNodes } from './escapeHtml.js';
|
|
9
9
|
/**
|
|
10
10
|
* Generates a slug from heading text
|
|
11
11
|
*/
|
|
@@ -176,7 +176,7 @@ function applyInlineIds(translatedContent, idMappings) {
|
|
|
176
176
|
const stringifyProcessor = unified()
|
|
177
177
|
.use(remarkFrontmatter, ['yaml', 'toml'])
|
|
178
178
|
.use(remarkMdx)
|
|
179
|
-
.use(
|
|
179
|
+
.use(escapeHtmlInTextNodes)
|
|
180
180
|
.use(remarkStringify, {
|
|
181
181
|
handlers: {
|
|
182
182
|
// Custom handler to prevent escaping of {#id} syntax
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Plugin } from 'unified';
|
|
2
|
+
import type { Root } from 'mdast';
|
|
3
|
+
/**
|
|
4
|
+
* Escape HTML-sensitive characters (`&`, `<`, `>`, `"`, `'`) in text nodes,
|
|
5
|
+
* leaving code, math, MDX expressions, and front-matter untouched.
|
|
6
|
+
* Ensures literals render safely without altering already-escaped entities.
|
|
7
|
+
*/
|
|
8
|
+
export declare const escapeHtmlInTextNodes: Plugin<[], Root>;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { findAndReplace } from 'mdast-util-find-and-replace';
|
|
2
|
+
const IGNORE_PARENTS = [
|
|
3
|
+
'code',
|
|
4
|
+
'inlineCode',
|
|
5
|
+
'mdxFlowExpression',
|
|
6
|
+
'mdxTextExpression',
|
|
7
|
+
'mdxjsEsm',
|
|
8
|
+
'heading',
|
|
9
|
+
'yaml',
|
|
10
|
+
'toml',
|
|
11
|
+
'math',
|
|
12
|
+
'inlineMath',
|
|
13
|
+
];
|
|
14
|
+
// & that is NOT already an entity: &word; { ᨫ
|
|
15
|
+
const AMP_NOT_ENTITY = /&(?![a-zA-Z][a-zA-Z0-9]*;|#\d+;|#x[0-9A-Fa-f]+;)/g;
|
|
16
|
+
/**
|
|
17
|
+
* Escape HTML-sensitive characters (`&`, `<`, `>`, `"`, `'`) in text nodes,
|
|
18
|
+
* leaving code, math, MDX expressions, and front-matter untouched.
|
|
19
|
+
* Ensures literals render safely without altering already-escaped entities.
|
|
20
|
+
*/
|
|
21
|
+
export const escapeHtmlInTextNodes = function () {
|
|
22
|
+
return (tree) => {
|
|
23
|
+
findAndReplace(tree, [
|
|
24
|
+
// Order matters: & first (idempotency), then the rest
|
|
25
|
+
[AMP_NOT_ENTITY, '&'],
|
|
26
|
+
[/</g, '<'],
|
|
27
|
+
[/>/g, '>'],
|
|
28
|
+
[/"/g, '"'],
|
|
29
|
+
[/'/g, '''],
|
|
30
|
+
], { ignore: IGNORE_PARENTS });
|
|
31
|
+
};
|
|
32
|
+
};
|
|
@@ -7,7 +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 {
|
|
10
|
+
import { escapeHtmlInTextNodes } from './escapeHtml.js';
|
|
11
11
|
const { isMatch } = micromatch;
|
|
12
12
|
/**
|
|
13
13
|
* Localizes static urls in content files.
|
|
@@ -373,7 +373,7 @@ function transformMdxUrls(mdxContent, defaultLocale, targetLocale, hideDefaultLo
|
|
|
373
373
|
const stringifyProcessor = unified()
|
|
374
374
|
.use(remarkFrontmatter, ['yaml', 'toml'])
|
|
375
375
|
.use(remarkMdx)
|
|
376
|
-
.use(
|
|
376
|
+
.use(escapeHtmlInTextNodes)
|
|
377
377
|
.use(remarkStringify, {
|
|
378
378
|
handlers: {
|
|
379
379
|
// Handler to prevent escaping (avoids '<' -> '\<')
|
package/package.json
CHANGED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { Plugin } from 'unified';
|
|
2
|
-
import type { Root } from 'mdast';
|
|
3
|
-
/**
|
|
4
|
-
* Re-encode angle-bracket placeholders like <accountName> -> <accountName>
|
|
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>;
|
|
@@ -1,30 +0,0 @@
|
|
|
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> -> <accountName>
|
|
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) => `<${name}>`,
|
|
27
|
-
],
|
|
28
|
-
], { ignore: IGNORE_PARENTS });
|
|
29
|
-
};
|
|
30
|
-
};
|