gtx-cli 2.5.45 → 2.5.46

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,11 @@
1
1
  # gtx-cli
2
2
 
3
+ ## 2.5.46
4
+
5
+ ### Patch Changes
6
+
7
+ - [#945](https://github.com/generaltranslation/gt/pull/945) [`3f0da49`](https://github.com/generaltranslation/gt/commit/3f0da498beaff2fe697cbf785bd1cc5fa069d93d) Thanks [@fernando-aviles](https://github.com/fernando-aviles)! - Add escaping of anchor ID syntax to all files passed in as MDX via gt.config.json
8
+
3
9
  ## 2.5.45
4
10
 
5
11
  ### Patch Changes
@@ -1 +1 @@
1
- export declare const PACKAGE_VERSION = "2.5.45";
1
+ export declare const PACKAGE_VERSION = "2.5.46";
@@ -1,2 +1,2 @@
1
1
  // This file is auto-generated. Do not edit manually.
2
- export const PACKAGE_VERSION = '2.5.45';
2
+ export const PACKAGE_VERSION = '2.5.46';
@@ -14,7 +14,7 @@ export declare function extractHeadingInfo(mdxContent: string): HeadingInfo[];
14
14
  /**
15
15
  * Applies anchor IDs to translated content based on source heading mapping
16
16
  */
17
- export declare function addExplicitAnchorIds(translatedContent: string, sourceHeadingMap: HeadingInfo[], settings?: any, sourcePath?: string, translatedPath?: string): {
17
+ export declare function addExplicitAnchorIds(translatedContent: string, sourceHeadingMap: HeadingInfo[], settings?: any, sourcePath?: string, translatedPath?: string, fileTypeHint?: 'md' | 'mdx'): {
18
18
  content: string;
19
19
  hasChanges: boolean;
20
20
  addedIds: Array<{
@@ -137,7 +137,7 @@ export function extractHeadingInfo(mdxContent) {
137
137
  /**
138
138
  * Applies anchor IDs to translated content based on source heading mapping
139
139
  */
140
- export function addExplicitAnchorIds(translatedContent, sourceHeadingMap, settings, sourcePath, translatedPath) {
140
+ export function addExplicitAnchorIds(translatedContent, sourceHeadingMap, settings, sourcePath, translatedPath, fileTypeHint) {
141
141
  const addedIds = [];
142
142
  const useDivWrapping = settings?.options?.experimentalAddHeaderAnchorIds === 'mintlify';
143
143
  // Extract headings from translated content
@@ -177,13 +177,18 @@ export function addExplicitAnchorIds(translatedContent, sourceHeadingMap, settin
177
177
  const translatedIsMdx = translatedPath
178
178
  ? translatedPath.toLowerCase().endsWith('.mdx')
179
179
  : true; // default to mdx-style escaping when unknown
180
+ const shouldEscapeAnchors = fileTypeHint === 'mdx'
181
+ ? true
182
+ : fileTypeHint === 'md'
183
+ ? false
184
+ : translatedIsMdx;
180
185
  // Apply IDs to translated content
181
186
  let content;
182
187
  if (useDivWrapping) {
183
188
  content = applyDivWrappedIds(translatedContent, translatedHeadings, idMappings);
184
189
  }
185
190
  else {
186
- content = applyInlineIds(translatedContent, idMappings, translatedIsMdx);
191
+ content = applyInlineIds(translatedContent, idMappings, shouldEscapeAnchors);
187
192
  }
188
193
  return {
189
194
  content,
@@ -1,5 +1,5 @@
1
1
  import { addExplicitAnchorIds, extractHeadingInfo, } from './addExplicitAnchorIds.js';
2
- import { readFile } from '../fs/findFilepath.js';
2
+ import { getRelative, readFile } from '../fs/findFilepath.js';
3
3
  import { createFileMapping } from '../formats/files/fileMapping.js';
4
4
  import * as fs from 'fs';
5
5
  /**
@@ -11,31 +11,38 @@ export default async function processAnchorIds(settings, includeFiles) {
11
11
  return;
12
12
  const { resolvedPaths, placeholderPaths, transformPaths } = settings.files;
13
13
  const fileMapping = createFileMapping(resolvedPaths, placeholderPaths, transformPaths, settings.locales, settings.defaultLocale);
14
+ const sourceTypeByPath = new Map();
15
+ if (resolvedPaths.md) {
16
+ for (const filePath of resolvedPaths.md) {
17
+ sourceTypeByPath.set(getRelative(filePath), 'md');
18
+ }
19
+ }
20
+ if (resolvedPaths.mdx) {
21
+ for (const filePath of resolvedPaths.mdx) {
22
+ sourceTypeByPath.set(getRelative(filePath), 'mdx');
23
+ }
24
+ }
14
25
  // Process each locale's translated files
15
26
  const processPromises = Object.entries(fileMapping)
16
27
  .filter(([locale, filesMap]) => locale !== settings.defaultLocale) // Skip default locale
17
28
  .map(async ([locale, filesMap]) => {
18
- // Get all translated files that are md or mdx
19
- const translatedFiles = Object.values(filesMap).filter((p) => p &&
20
- (p.endsWith('.md') || p.endsWith('.mdx')) &&
21
- (!includeFiles || includeFiles.has(p)));
22
- for (const translatedPath of translatedFiles) {
29
+ // Get all translated files whose sources are md or mdx
30
+ const mdFiles = Object.entries(filesMap).filter(([sourcePath, translatedPath]) => translatedPath &&
31
+ sourceTypeByPath.has(sourcePath) &&
32
+ (!includeFiles || includeFiles.has(translatedPath)));
33
+ for (const [sourcePath, translatedPath] of mdFiles) {
23
34
  try {
24
35
  // Check if translated file exists before processing
25
36
  if (!fs.existsSync(translatedPath)) {
26
37
  continue;
27
38
  }
28
- // Find the corresponding source file
29
- const sourcePath = Object.keys(filesMap).find((key) => filesMap[key] === translatedPath);
30
- if (!sourcePath) {
31
- continue;
32
- }
33
39
  // Extract heading info from source file
34
40
  const sourceContent = readFile(sourcePath);
35
41
  const sourceHeadingMap = extractHeadingInfo(sourceContent);
42
+ const fileTypeHint = sourceTypeByPath.get(sourcePath);
36
43
  // Read translated file and apply anchor IDs
37
44
  const translatedContent = readFile(translatedPath);
38
- const result = addExplicitAnchorIds(translatedContent, sourceHeadingMap, settings, sourcePath, translatedPath);
45
+ const result = addExplicitAnchorIds(translatedContent, sourceHeadingMap, settings, sourcePath, translatedPath, fileTypeHint);
39
46
  if (result.hasChanges) {
40
47
  fs.writeFileSync(translatedPath, result.content, 'utf8');
41
48
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gtx-cli",
3
- "version": "2.5.45",
3
+ "version": "2.5.46",
4
4
  "main": "dist/index.js",
5
5
  "bin": "dist/main.js",
6
6
  "files": [