gt 2.14.35 → 2.14.37

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.
Files changed (430) hide show
  1. package/CHANGELOG.md +22 -1
  2. package/dist/api/collectUserEditDiffs.js +112 -155
  3. package/dist/api/collectUserEditDiffs.js.map +1 -0
  4. package/dist/api/downloadFileBatch.js +164 -241
  5. package/dist/api/downloadFileBatch.js.map +1 -0
  6. package/dist/api/saveLocalEdits.js +37 -41
  7. package/dist/api/saveLocalEdits.js.map +1 -0
  8. package/dist/bin/bin-entry.js +17 -7
  9. package/dist/bin/bin-entry.js.map +1 -0
  10. package/dist/bin/bin-main.js +43 -61
  11. package/dist/bin/bin-main.js.map +1 -0
  12. package/dist/cli/base.js +382 -497
  13. package/dist/cli/base.js.map +1 -0
  14. package/dist/cli/commands/download.js +41 -49
  15. package/dist/cli/commands/download.js.map +1 -0
  16. package/dist/cli/commands/enqueue.js +26 -25
  17. package/dist/cli/commands/enqueue.js.map +1 -0
  18. package/dist/cli/commands/setupProject.js +33 -36
  19. package/dist/cli/commands/setupProject.js.map +1 -0
  20. package/dist/cli/commands/stage.js +53 -61
  21. package/dist/cli/commands/stage.js.map +1 -0
  22. package/dist/cli/commands/translate.js +75 -112
  23. package/dist/cli/commands/translate.js.map +1 -0
  24. package/dist/cli/commands/upload.js +185 -213
  25. package/dist/cli/commands/upload.js.map +1 -0
  26. package/dist/cli/commands/utils/validation.js +39 -34
  27. package/dist/cli/commands/utils/validation.js.map +1 -0
  28. package/dist/cli/flags.js +35 -62
  29. package/dist/cli/flags.js.map +1 -0
  30. package/dist/cli/inline.js +112 -137
  31. package/dist/cli/inline.js.map +1 -0
  32. package/dist/cli/next.js +17 -12
  33. package/dist/cli/next.js.map +1 -0
  34. package/dist/cli/node.js +19 -15
  35. package/dist/cli/node.js.map +1 -0
  36. package/dist/cli/python.js +13 -8
  37. package/dist/cli/python.js.map +1 -0
  38. package/dist/cli/react.js +61 -78
  39. package/dist/cli/react.js.map +1 -0
  40. package/dist/config/defaults.js +16 -11
  41. package/dist/config/defaults.js.map +1 -0
  42. package/dist/config/generateSettings.js +167 -269
  43. package/dist/config/generateSettings.js.map +1 -0
  44. package/dist/config/optionPresets.js +78 -96
  45. package/dist/config/optionPresets.js.map +1 -0
  46. package/dist/config/resolveConfig.js +27 -32
  47. package/dist/config/resolveConfig.js.map +1 -0
  48. package/dist/config/utils.js +7 -3
  49. package/dist/config/utils.js.map +1 -0
  50. package/dist/config/validateSettings.js +19 -30
  51. package/dist/config/validateSettings.js.map +1 -0
  52. package/dist/console/colors.js +18 -13
  53. package/dist/console/colors.js.map +1 -0
  54. package/dist/console/displayTranslateSummary.js +40 -37
  55. package/dist/console/displayTranslateSummary.js.map +1 -0
  56. package/dist/console/formatting.js +8 -5
  57. package/dist/console/formatting.js.map +1 -0
  58. package/dist/console/index.d.ts +11 -9
  59. package/dist/console/index.js +53 -50
  60. package/dist/console/index.js.map +1 -0
  61. package/dist/console/inkFields.d.ts +23 -0
  62. package/dist/console/inkFields.js +87 -0
  63. package/dist/console/inkFields.js.map +1 -0
  64. package/dist/console/inkLayout.d.ts +7 -0
  65. package/dist/console/inkLayout.js +139 -0
  66. package/dist/console/inkLayout.js.map +1 -0
  67. package/dist/console/inkLocaleData.d.ts +4 -0
  68. package/dist/console/inkLocaleData.js +32 -0
  69. package/dist/console/inkLocaleData.js.map +1 -0
  70. package/dist/console/inkPrompts.d.ts +8 -0
  71. package/dist/console/inkPrompts.js +496 -0
  72. package/dist/console/inkPrompts.js.map +1 -0
  73. package/dist/console/inkSession.d.ts +3 -0
  74. package/dist/console/inkSession.js +42 -0
  75. package/dist/console/inkSession.js.map +1 -0
  76. package/dist/console/inkTerminal.d.ts +4 -0
  77. package/dist/console/inkTerminal.js +15 -0
  78. package/dist/console/inkTerminal.js.map +1 -0
  79. package/dist/console/inkTypes.d.ts +66 -0
  80. package/dist/console/inkTypes.js +1 -0
  81. package/dist/console/inkUtils.d.ts +24 -0
  82. package/dist/console/inkUtils.js +87 -0
  83. package/dist/console/inkUtils.js.map +1 -0
  84. package/dist/console/logger.js +209 -249
  85. package/dist/console/logger.js.map +1 -0
  86. package/dist/console/logging.d.ts +14 -0
  87. package/dist/console/logging.js +203 -162
  88. package/dist/console/logging.js.map +1 -0
  89. package/dist/console/promptParsing.d.ts +5 -0
  90. package/dist/console/promptParsing.js +28 -0
  91. package/dist/console/promptParsing.js.map +1 -0
  92. package/dist/console/terminalSession.d.ts +5 -0
  93. package/dist/console/terminalSession.js +38 -0
  94. package/dist/console/terminalSession.js.map +1 -0
  95. package/dist/extraction/index.js +3 -2
  96. package/dist/extraction/mapToUpdates.js +19 -18
  97. package/dist/extraction/mapToUpdates.js.map +1 -0
  98. package/dist/extraction/postProcess.js +68 -86
  99. package/dist/extraction/postProcess.js.map +1 -0
  100. package/dist/formats/files/aggregateFiles.js +223 -304
  101. package/dist/formats/files/aggregateFiles.js.map +1 -0
  102. package/dist/formats/files/collectFiles.js +53 -54
  103. package/dist/formats/files/collectFiles.js.map +1 -0
  104. package/dist/formats/files/convertToFileTranslationData.js +21 -19
  105. package/dist/formats/files/convertToFileTranslationData.js.map +1 -0
  106. package/dist/formats/files/fileMapping.js +82 -119
  107. package/dist/formats/files/fileMapping.js.map +1 -0
  108. package/dist/formats/files/preprocess/mdx.js +15 -12
  109. package/dist/formats/files/preprocess/mdx.js.map +1 -0
  110. package/dist/formats/files/preprocess/mintlify.js +15 -13
  111. package/dist/formats/files/preprocess/mintlify.js.map +1 -0
  112. package/dist/formats/files/preprocessContent.js +20 -21
  113. package/dist/formats/files/preprocessContent.js.map +1 -0
  114. package/dist/formats/files/save.js +18 -15
  115. package/dist/formats/files/save.js.map +1 -0
  116. package/dist/formats/files/supportedFiles.js +27 -22
  117. package/dist/formats/files/supportedFiles.js.map +1 -0
  118. package/dist/formats/files/transformFormat.js +93 -100
  119. package/dist/formats/files/transformFormat.js.map +1 -0
  120. package/dist/formats/json/extractJson.js +83 -110
  121. package/dist/formats/json/extractJson.js.map +1 -0
  122. package/dist/formats/json/flattenJson.js +41 -48
  123. package/dist/formats/json/flattenJson.js.map +1 -0
  124. package/dist/formats/json/jsonPath.js +20 -15
  125. package/dist/formats/json/jsonPath.js.map +1 -0
  126. package/dist/formats/json/jsonPointer.js +17 -17
  127. package/dist/formats/json/jsonPointer.js.map +1 -0
  128. package/dist/formats/json/mergeJson.js +230 -371
  129. package/dist/formats/json/mergeJson.js.map +1 -0
  130. package/dist/formats/json/parseJson.js +74 -111
  131. package/dist/formats/json/parseJson.js.map +1 -0
  132. package/dist/formats/json/transformJson.js +53 -61
  133. package/dist/formats/json/transformJson.js.map +1 -0
  134. package/dist/formats/json/utils.js +158 -187
  135. package/dist/formats/json/utils.js.map +1 -0
  136. package/dist/formats/parseKeyedMetadata.js +85 -106
  137. package/dist/formats/parseKeyedMetadata.js.map +1 -0
  138. package/dist/formats/utils.js +13 -23
  139. package/dist/formats/utils.js.map +1 -0
  140. package/dist/formats/yaml/extractYaml.js +32 -31
  141. package/dist/formats/yaml/extractYaml.js.map +1 -0
  142. package/dist/formats/yaml/mergeYaml.js +43 -60
  143. package/dist/formats/yaml/mergeYaml.js.map +1 -0
  144. package/dist/formats/yaml/parseYaml.js +34 -23
  145. package/dist/formats/yaml/parseYaml.js.map +1 -0
  146. package/dist/formats/yaml/utils.js +19 -21
  147. package/dist/formats/yaml/utils.js.map +1 -0
  148. package/dist/fs/clearLocaleDirs.js +82 -114
  149. package/dist/fs/clearLocaleDirs.js.map +1 -0
  150. package/dist/fs/config/downloadedVersions.js +174 -188
  151. package/dist/fs/config/downloadedVersions.js.map +1 -0
  152. package/dist/fs/config/loadConfig.js +12 -8
  153. package/dist/fs/config/loadConfig.js.map +1 -0
  154. package/dist/fs/config/parseFilesConfig.js +166 -227
  155. package/dist/fs/config/parseFilesConfig.js.map +1 -0
  156. package/dist/fs/config/setupConfig.js +43 -52
  157. package/dist/fs/config/setupConfig.js.map +1 -0
  158. package/dist/fs/config/updateConfig.js +44 -56
  159. package/dist/fs/config/updateConfig.js.map +1 -0
  160. package/dist/fs/config/updateVersions.js +27 -28
  161. package/dist/fs/config/updateVersions.js.map +1 -0
  162. package/dist/fs/copyFile.js +33 -37
  163. package/dist/fs/copyFile.js.map +1 -0
  164. package/dist/fs/createLoadTranslationsFile.js +32 -48
  165. package/dist/fs/createLoadTranslationsFile.js.map +1 -0
  166. package/dist/fs/determineFramework/detectPythonLibrary.js +30 -34
  167. package/dist/fs/determineFramework/detectPythonLibrary.js.map +1 -0
  168. package/dist/fs/determineFramework/index.js +46 -64
  169. package/dist/fs/determineFramework/index.js.map +1 -0
  170. package/dist/fs/determineFramework/matchPyprojectDependency.js +65 -78
  171. package/dist/fs/determineFramework/matchPyprojectDependency.js.map +1 -0
  172. package/dist/fs/determineFramework/matchRequirementsTxtDependency.js +21 -19
  173. package/dist/fs/determineFramework/matchRequirementsTxtDependency.js.map +1 -0
  174. package/dist/fs/determineFramework/matchSetupPyDependency.js +60 -81
  175. package/dist/fs/determineFramework/matchSetupPyDependency.js.map +1 -0
  176. package/dist/fs/determineFramework/resolveGtDependency.js +15 -15
  177. package/dist/fs/determineFramework/resolveGtDependency.js.map +1 -0
  178. package/dist/fs/findFilepath.js +63 -78
  179. package/dist/fs/findFilepath.js.map +1 -0
  180. package/dist/fs/loadJSON.js +18 -15
  181. package/dist/fs/loadJSON.js.map +1 -0
  182. package/dist/fs/matchFiles.js +12 -7
  183. package/dist/fs/matchFiles.js.map +1 -0
  184. package/dist/fs/saveJSON.js +10 -6
  185. package/dist/fs/saveJSON.js.map +1 -0
  186. package/dist/fs/utils.js +19 -15
  187. package/dist/fs/utils.js.map +1 -0
  188. package/dist/functions.d.ts +2 -1
  189. package/dist/functions.js +3 -6
  190. package/dist/generated/version.d.ts +1 -1
  191. package/dist/generated/version.js +6 -2
  192. package/dist/generated/version.js.map +1 -0
  193. package/dist/git/branches.js +77 -83
  194. package/dist/git/branches.js.map +1 -0
  195. package/dist/hooks/postProcess.js +97 -114
  196. package/dist/hooks/postProcess.js.map +1 -0
  197. package/dist/index.js +23 -31
  198. package/dist/index.js.map +1 -0
  199. package/dist/locadex/setupFlow.js +11 -8
  200. package/dist/locadex/setupFlow.js.map +1 -0
  201. package/dist/main.js +17 -7
  202. package/dist/main.js.map +1 -0
  203. package/dist/next/config/parseNextConfig.js +32 -51
  204. package/dist/next/config/parseNextConfig.js.map +1 -0
  205. package/dist/next/jsx/utils.js +25 -37
  206. package/dist/next/jsx/utils.js.map +1 -0
  207. package/dist/next/parse/handleInitGT.js +87 -154
  208. package/dist/next/parse/handleInitGT.js.map +1 -0
  209. package/dist/next/parse/wrapContent.js +136 -158
  210. package/dist/next/parse/wrapContent.js.map +1 -0
  211. package/dist/python/parse/createPythonInlineUpdates.js +36 -33
  212. package/dist/python/parse/createPythonInlineUpdates.js.map +1 -0
  213. package/dist/react/config/createESBuildConfig.js +115 -115
  214. package/dist/react/config/createESBuildConfig.js.map +1 -0
  215. package/dist/react/jsx/evaluateJsx.js +90 -124
  216. package/dist/react/jsx/evaluateJsx.js.map +1 -0
  217. package/dist/react/jsx/utils/buildImportMap.js +24 -28
  218. package/dist/react/jsx/utils/buildImportMap.js.map +1 -0
  219. package/dist/react/jsx/utils/constants.js +79 -87
  220. package/dist/react/jsx/utils/constants.js.map +1 -0
  221. package/dist/react/jsx/utils/extractSourceCode.js +36 -37
  222. package/dist/react/jsx/utils/extractSourceCode.js.map +1 -0
  223. package/dist/react/jsx/utils/getCalleeNameFromExpression.js +30 -30
  224. package/dist/react/jsx/utils/getCalleeNameFromExpression.js.map +1 -0
  225. package/dist/react/jsx/utils/getPathsAndAliases.js +70 -105
  226. package/dist/react/jsx/utils/getPathsAndAliases.js.map +1 -0
  227. package/dist/react/jsx/utils/isNumberLiteral.js +13 -11
  228. package/dist/react/jsx/utils/isNumberLiteral.js.map +1 -0
  229. package/dist/react/jsx/utils/jsxParsing/addGTIdentifierToSyntaxTree.js +103 -148
  230. package/dist/react/jsx/utils/jsxParsing/addGTIdentifierToSyntaxTree.js.map +1 -0
  231. package/dist/react/jsx/utils/jsxParsing/autoInsertion.js +305 -389
  232. package/dist/react/jsx/utils/jsxParsing/autoInsertion.js.map +1 -0
  233. package/dist/react/jsx/utils/jsxParsing/handleChildrenWhitespace.js +122 -193
  234. package/dist/react/jsx/utils/jsxParsing/handleChildrenWhitespace.js.map +1 -0
  235. package/dist/react/jsx/utils/jsxParsing/multiplication/findMultiplicationNode.js +50 -64
  236. package/dist/react/jsx/utils/jsxParsing/multiplication/findMultiplicationNode.js.map +1 -0
  237. package/dist/react/jsx/utils/jsxParsing/multiplication/multiplyJsxTree.js +41 -68
  238. package/dist/react/jsx/utils/jsxParsing/multiplication/multiplyJsxTree.js.map +1 -0
  239. package/dist/react/jsx/utils/jsxParsing/parseJsx.js +760 -1107
  240. package/dist/react/jsx/utils/jsxParsing/parseJsx.js.map +1 -0
  241. package/dist/react/jsx/utils/jsxParsing/parseTProps.js +35 -71
  242. package/dist/react/jsx/utils/jsxParsing/parseTProps.js.map +1 -0
  243. package/dist/react/jsx/utils/jsxParsing/removeNullChildrenFields.js +39 -58
  244. package/dist/react/jsx/utils/jsxParsing/removeNullChildrenFields.js.map +1 -0
  245. package/dist/react/jsx/utils/jsxParsing/types.js +10 -24
  246. package/dist/react/jsx/utils/jsxParsing/types.js.map +1 -0
  247. package/dist/react/jsx/utils/mapAttributeName.js +13 -13
  248. package/dist/react/jsx/utils/mapAttributeName.js.map +1 -0
  249. package/dist/react/jsx/utils/parseAst.js +142 -272
  250. package/dist/react/jsx/utils/parseAst.js.map +1 -0
  251. package/dist/react/jsx/utils/parseString.js +726 -1090
  252. package/dist/react/jsx/utils/parseString.js.map +1 -0
  253. package/dist/react/jsx/utils/parseStringFunction.js +274 -401
  254. package/dist/react/jsx/utils/parseStringFunction.js.map +1 -0
  255. package/dist/react/jsx/utils/resolveImportPath.d.ts +1 -1
  256. package/dist/react/jsx/utils/resolveImportPath.js +125 -108
  257. package/dist/react/jsx/utils/resolveImportPath.js.map +1 -0
  258. package/dist/react/jsx/utils/stringParsing/derivation/containsDeriveCall.js +18 -24
  259. package/dist/react/jsx/utils/stringParsing/derivation/containsDeriveCall.js.map +1 -0
  260. package/dist/react/jsx/utils/stringParsing/derivation/handleDerivation.js +412 -579
  261. package/dist/react/jsx/utils/stringParsing/derivation/handleDerivation.js.map +1 -0
  262. package/dist/react/jsx/utils/stringParsing/derivation/index.js +57 -67
  263. package/dist/react/jsx/utils/stringParsing/derivation/index.js.map +1 -0
  264. package/dist/react/jsx/utils/stringParsing/derivation/isDeriveCall.js +26 -36
  265. package/dist/react/jsx/utils/stringParsing/derivation/isDeriveCall.js.map +1 -0
  266. package/dist/react/jsx/utils/stringParsing/processTaggedTemplateCall/handleTaggedTemplateTranslationCall.js +29 -24
  267. package/dist/react/jsx/utils/stringParsing/processTaggedTemplateCall/handleTaggedTemplateTranslationCall.js.map +1 -0
  268. package/dist/react/jsx/utils/stringParsing/processTaggedTemplateCall/index.js +34 -32
  269. package/dist/react/jsx/utils/stringParsing/processTaggedTemplateCall/index.js.map +1 -0
  270. package/dist/react/jsx/utils/stringParsing/processTranslationCall/extractStringEntryMetadata.js +80 -117
  271. package/dist/react/jsx/utils/stringParsing/processTranslationCall/extractStringEntryMetadata.js.map +1 -0
  272. package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleDeriveTranslationCall.js +24 -19
  273. package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleDeriveTranslationCall.js.map +1 -0
  274. package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleInvalidTranslationCall.js +18 -21
  275. package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleInvalidTranslationCall.js.map +1 -0
  276. package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleLiteralTranslationCall.js +45 -50
  277. package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleLiteralTranslationCall.js.map +1 -0
  278. package/dist/react/jsx/utils/stringParsing/processTranslationCall/index.js +54 -59
  279. package/dist/react/jsx/utils/stringParsing/processTranslationCall/index.js.map +1 -0
  280. package/dist/react/jsx/utils/stringParsing/processTranslationCall/routeTranslationCall.js +56 -69
  281. package/dist/react/jsx/utils/stringParsing/processTranslationCall/routeTranslationCall.js.map +1 -0
  282. package/dist/react/jsx/utils/validateStringFunction.js +21 -29
  283. package/dist/react/jsx/utils/validateStringFunction.js.map +1 -0
  284. package/dist/react/jsx/wrapJsx.js +192 -375
  285. package/dist/react/jsx/wrapJsx.js.map +1 -0
  286. package/dist/react/parse/addVitePlugin/index.js +40 -34
  287. package/dist/react/parse/addVitePlugin/index.js.map +1 -0
  288. package/dist/react/parse/addVitePlugin/installCompiler.js +18 -20
  289. package/dist/react/parse/addVitePlugin/installCompiler.js.map +1 -0
  290. package/dist/react/parse/addVitePlugin/updateViteConfig.js +107 -111
  291. package/dist/react/parse/addVitePlugin/updateViteConfig.js.map +1 -0
  292. package/dist/react/parse/addVitePlugin/utils/addCompilerImport.js +23 -26
  293. package/dist/react/parse/addVitePlugin/utils/addCompilerImport.js.map +1 -0
  294. package/dist/react/parse/addVitePlugin/utils/addPluginInvocation.js +29 -43
  295. package/dist/react/parse/addVitePlugin/utils/addPluginInvocation.js.map +1 -0
  296. package/dist/react/parse/addVitePlugin/utils/checkCompilerImport.js +70 -104
  297. package/dist/react/parse/addVitePlugin/utils/checkCompilerImport.js.map +1 -0
  298. package/dist/react/parse/addVitePlugin/utils/checkPluginInvocation.js +23 -29
  299. package/dist/react/parse/addVitePlugin/utils/checkPluginInvocation.js.map +1 -0
  300. package/dist/react/parse/createDictionaryUpdates.js +121 -185
  301. package/dist/react/parse/createDictionaryUpdates.js.map +1 -0
  302. package/dist/react/parse/createInlineUpdates.js +123 -139
  303. package/dist/react/parse/createInlineUpdates.js.map +1 -0
  304. package/dist/react/parse/wrapContent.js +131 -156
  305. package/dist/react/parse/wrapContent.js.map +1 -0
  306. package/dist/react/utils/flattenDictionary.js +55 -70
  307. package/dist/react/utils/flattenDictionary.js.map +1 -0
  308. package/dist/react/utils/getEntryAndMetadata.js +14 -10
  309. package/dist/react/utils/getEntryAndMetadata.js.map +1 -0
  310. package/dist/react/utils/getVariableName.js +36 -33
  311. package/dist/react/utils/getVariableName.js.map +1 -0
  312. package/dist/setup/detectFramework.js +85 -102
  313. package/dist/setup/detectFramework.js.map +1 -0
  314. package/dist/setup/frameworkUtils.js +17 -28
  315. package/dist/setup/frameworkUtils.js.map +1 -0
  316. package/dist/setup/userInput.js +24 -31
  317. package/dist/setup/userInput.js.map +1 -0
  318. package/dist/setup/wizard.js +141 -143
  319. package/dist/setup/wizard.js.map +1 -0
  320. package/dist/state/mintlifyRefMap.js +12 -9
  321. package/dist/state/mintlifyRefMap.js.map +1 -0
  322. package/dist/state/recentDownloads.js +26 -23
  323. package/dist/state/recentDownloads.js.map +1 -0
  324. package/dist/state/translateWarnings.js +17 -8
  325. package/dist/state/translateWarnings.js.map +1 -0
  326. package/dist/translation/parse.js +77 -98
  327. package/dist/translation/parse.js.map +1 -0
  328. package/dist/translation/stage.js +28 -43
  329. package/dist/translation/stage.js.map +1 -0
  330. package/dist/translation/validate.js +68 -91
  331. package/dist/translation/validate.js.map +1 -0
  332. package/dist/types/libraries.js +93 -91
  333. package/dist/types/libraries.js.map +1 -0
  334. package/dist/types/parsing.js +19 -10
  335. package/dist/types/parsing.js.map +1 -0
  336. package/dist/utils/addExplicitAnchorIds.js +270 -389
  337. package/dist/utils/addExplicitAnchorIds.js.map +1 -0
  338. package/dist/utils/calculateTimeoutMs.js +11 -6
  339. package/dist/utils/calculateTimeoutMs.js.map +1 -0
  340. package/dist/utils/constants.js +15 -12
  341. package/dist/utils/constants.js.map +1 -0
  342. package/dist/utils/credentials.js +67 -114
  343. package/dist/utils/credentials.js.map +1 -0
  344. package/dist/utils/fetch.js +22 -20
  345. package/dist/utils/fetch.js.map +1 -0
  346. package/dist/utils/flattenJsonFiles.js +27 -34
  347. package/dist/utils/flattenJsonFiles.js.map +1 -0
  348. package/dist/utils/gitDiff.js +30 -32
  349. package/dist/utils/gitDiff.js.map +1 -0
  350. package/dist/utils/gt.js +7 -2
  351. package/dist/utils/gt.js.map +1 -0
  352. package/dist/utils/hash.js +14 -9
  353. package/dist/utils/hash.js.map +1 -0
  354. package/dist/utils/headers.js +10 -13
  355. package/dist/utils/headers.js.map +1 -0
  356. package/dist/utils/installPackage.js +70 -75
  357. package/dist/utils/installPackage.js.map +1 -0
  358. package/dist/utils/localizeRelativeAssets.js +114 -157
  359. package/dist/utils/localizeRelativeAssets.js.map +1 -0
  360. package/dist/utils/localizeStaticImports.js +229 -371
  361. package/dist/utils/localizeStaticImports.js.map +1 -0
  362. package/dist/utils/localizeStaticUrls.js +241 -424
  363. package/dist/utils/localizeStaticUrls.js.map +1 -0
  364. package/dist/utils/mintlifyTitleFallback.js +64 -72
  365. package/dist/utils/mintlifyTitleFallback.js.map +1 -0
  366. package/dist/utils/monorepoVersionCheck.js +177 -215
  367. package/dist/utils/monorepoVersionCheck.js.map +1 -0
  368. package/dist/utils/packageInfo.js +17 -16
  369. package/dist/utils/packageInfo.js.map +1 -0
  370. package/dist/utils/packageJson.js +51 -66
  371. package/dist/utils/packageJson.js.map +1 -0
  372. package/dist/utils/packageManager.js +237 -260
  373. package/dist/utils/packageManager.js.map +1 -0
  374. package/dist/utils/parse/needsCJS.js +36 -69
  375. package/dist/utils/parse/needsCJS.js.map +1 -0
  376. package/dist/utils/persistPostprocessHashes.js +30 -32
  377. package/dist/utils/persistPostprocessHashes.js.map +1 -0
  378. package/dist/utils/processAnchorIds.js +32 -54
  379. package/dist/utils/processAnchorIds.js.map +1 -0
  380. package/dist/utils/processOpenApi.js +469 -578
  381. package/dist/utils/processOpenApi.js.map +1 -0
  382. package/dist/utils/resolveMintlifyRefs.js +89 -105
  383. package/dist/utils/resolveMintlifyRefs.js.map +1 -0
  384. package/dist/utils/resolvePublish.js +46 -54
  385. package/dist/utils/resolvePublish.js.map +1 -0
  386. package/dist/utils/sanitizeFileContent.js +20 -27
  387. package/dist/utils/sanitizeFileContent.js.map +1 -0
  388. package/dist/utils/sharedStaticAssets.js +248 -366
  389. package/dist/utils/sharedStaticAssets.js.map +1 -0
  390. package/dist/utils/splitMintlifyLanguageRefs.js +208 -282
  391. package/dist/utils/splitMintlifyLanguageRefs.js.map +1 -0
  392. package/dist/utils/validateMdx.js +26 -23
  393. package/dist/utils/validateMdx.js.map +1 -0
  394. package/dist/utils/wrapPlainUrls.js +58 -70
  395. package/dist/utils/wrapPlainUrls.js.map +1 -0
  396. package/dist/workflows/download.js +92 -126
  397. package/dist/workflows/download.js.map +1 -0
  398. package/dist/workflows/enqueue.js +47 -54
  399. package/dist/workflows/enqueue.js.map +1 -0
  400. package/dist/workflows/publish.js +29 -29
  401. package/dist/workflows/publish.js.map +1 -0
  402. package/dist/workflows/setupProject.js +39 -40
  403. package/dist/workflows/setupProject.js.map +1 -0
  404. package/dist/workflows/stage.js +61 -65
  405. package/dist/workflows/stage.js.map +1 -0
  406. package/dist/workflows/steps/BranchStep.js +118 -163
  407. package/dist/workflows/steps/BranchStep.js.map +1 -0
  408. package/dist/workflows/steps/DownloadStep.js +107 -137
  409. package/dist/workflows/steps/DownloadStep.js.map +1 -0
  410. package/dist/workflows/steps/EnqueueStep.js +32 -32
  411. package/dist/workflows/steps/EnqueueStep.js.map +1 -0
  412. package/dist/workflows/steps/PollJobsStep.js +208 -292
  413. package/dist/workflows/steps/PollJobsStep.js.map +1 -0
  414. package/dist/workflows/steps/PublishStep.js +33 -38
  415. package/dist/workflows/steps/PublishStep.js.map +1 -0
  416. package/dist/workflows/steps/SetupStep.js +71 -72
  417. package/dist/workflows/steps/SetupStep.js.map +1 -0
  418. package/dist/workflows/steps/TagStep.js +39 -44
  419. package/dist/workflows/steps/TagStep.js.map +1 -0
  420. package/dist/workflows/steps/UploadSourcesStep.js +108 -140
  421. package/dist/workflows/steps/UploadSourcesStep.js.map +1 -0
  422. package/dist/workflows/steps/UploadTranslationsStep.js +61 -71
  423. package/dist/workflows/steps/UploadTranslationsStep.js.map +1 -0
  424. package/dist/workflows/steps/UserEditDiffsStep.js +32 -34
  425. package/dist/workflows/steps/UserEditDiffsStep.js.map +1 -0
  426. package/dist/workflows/steps/WorkflowStep.js +6 -2
  427. package/dist/workflows/steps/WorkflowStep.js.map +1 -0
  428. package/dist/workflows/upload.js +45 -46
  429. package/dist/workflows/upload.js.map +1 -0
  430. package/package.json +14 -7
@@ -1,416 +1,297 @@
1
- import { unified } from 'unified';
2
- import remarkParse from 'remark-parse';
3
- import remarkMdx from 'remark-mdx';
4
- import remarkFrontmatter from 'remark-frontmatter';
5
- import remarkStringify from 'remark-stringify';
6
- import { visit } from 'unist-util-visit';
7
- import { logger } from '../console/logger.js';
8
- import { escapeHtmlInTextNodes, normalizeCJKCharacters } from 'gt-remark';
9
- import { decode } from 'html-entities';
1
+ import { logger } from "../console/logger.js";
2
+ import { unified } from "unified";
3
+ import remarkParse from "remark-parse";
4
+ import remarkMdx from "remark-mdx";
5
+ import remarkFrontmatter from "remark-frontmatter";
6
+ import { visit } from "unist-util-visit";
7
+ import remarkStringify from "remark-stringify";
8
+ import { escapeHtmlInTextNodes, normalizeCJKCharacters } from "gt-remark";
9
+ import { decode } from "html-entities";
10
+ //#region src/utils/addExplicitAnchorIds.ts
10
11
  /**
11
- * Generates a slug from heading text
12
- */
12
+ * Generates a slug from heading text
13
+ */
13
14
  function generateSlug(text) {
14
- return text
15
- .toLowerCase()
16
- .replace(/[^\w\s-]/g, '') // Remove special chars except spaces and hyphens
17
- .trim()
18
- .replace(/\s+/g, '-') // Replace spaces with hyphens
19
- .replace(/-+/g, '-') // Replace multiple hyphens with single hyphen
20
- .replace(/^-|-$/g, ''); // Remove leading/trailing hyphens
15
+ return text.toLowerCase().replace(/[^\w\s-]/g, "").trim().replace(/\s+/g, "-").replace(/-+/g, "-").replace(/^-|-$/g, "");
21
16
  }
22
17
  /**
23
- * Extracts text content from heading nodes
24
- */
18
+ * Extracts text content from heading nodes
19
+ */
25
20
  function extractHeadingText(heading) {
26
- let text = '';
27
- visit(heading, ['text', 'inlineCode'], (node) => {
28
- if ('value' in node && typeof node.value === 'string') {
29
- text += node.value;
30
- }
31
- });
32
- return text;
21
+ let text = "";
22
+ visit(heading, ["text", "inlineCode"], (node) => {
23
+ if ("value" in node && typeof node.value === "string") text += node.value;
24
+ });
25
+ return text;
33
26
  }
34
27
  /**
35
- * Simple line-by-line heading extractor that skips fenced code blocks.
36
- * Used as a fallback when MDX parsing fails.
37
- */
28
+ * Simple line-by-line heading extractor that skips fenced code blocks.
29
+ * Used as a fallback when MDX parsing fails.
30
+ */
38
31
  function extractHeadingsWithFallback(mdxContent) {
39
- const headings = [];
40
- const lines = mdxContent.split('\n');
41
- let position = 0;
42
- let inFence = false;
43
- let fenceChar = null;
44
- for (const line of lines) {
45
- const fenceMatch = line.match(/^(\s*)(`{3,}|~{3,})/);
46
- if (fenceMatch) {
47
- const fenceString = fenceMatch[2];
48
- if (!inFence) {
49
- inFence = true;
50
- fenceChar = fenceString;
51
- }
52
- else if (fenceChar &&
53
- fenceString[0] === fenceChar[0] &&
54
- fenceString.length >= fenceChar.length) {
55
- inFence = false;
56
- fenceChar = null;
57
- }
58
- continue;
59
- }
60
- if (inFence) {
61
- continue;
62
- }
63
- const headingMatch = line.match(/^(#{1,6})\s+(.*)$/);
64
- if (!headingMatch) {
65
- continue;
66
- }
67
- const hashes = headingMatch[1];
68
- const rawText = headingMatch[2];
69
- const { cleanedText, explicitId } = parseHeadingContent(rawText);
70
- if (cleanedText || explicitId) {
71
- headings.push({
72
- text: cleanedText,
73
- level: hashes.length,
74
- slug: explicitId ?? generateSlug(cleanedText),
75
- position: position++,
76
- });
77
- }
78
- }
79
- return headings;
32
+ const headings = [];
33
+ const lines = mdxContent.split("\n");
34
+ let position = 0;
35
+ let inFence = false;
36
+ let fenceChar = null;
37
+ for (const line of lines) {
38
+ const fenceMatch = line.match(/^(\s*)(`{3,}|~{3,})/);
39
+ if (fenceMatch) {
40
+ const fenceString = fenceMatch[2];
41
+ if (!inFence) {
42
+ inFence = true;
43
+ fenceChar = fenceString;
44
+ } else if (fenceChar && fenceString[0] === fenceChar[0] && fenceString.length >= fenceChar.length) {
45
+ inFence = false;
46
+ fenceChar = null;
47
+ }
48
+ continue;
49
+ }
50
+ if (inFence) continue;
51
+ const headingMatch = line.match(/^(#{1,6})\s+(.*)$/);
52
+ if (!headingMatch) continue;
53
+ const hashes = headingMatch[1];
54
+ const rawText = headingMatch[2];
55
+ const { cleanedText, explicitId } = parseHeadingContent(rawText);
56
+ if (cleanedText || explicitId) headings.push({
57
+ text: cleanedText,
58
+ level: hashes.length,
59
+ slug: explicitId ?? generateSlug(cleanedText),
60
+ position: position++
61
+ });
62
+ }
63
+ return headings;
80
64
  }
81
65
  function parseHeadingContent(text) {
82
- // Support both {#id} and escaped \{#id\} forms
83
- const anchorMatch = text.match(/(\\\{#([^}]+)\\\}|\{#([^}]+)\})\s*$/);
84
- if (!anchorMatch) {
85
- return { cleanedText: text };
86
- }
87
- const explicitId = anchorMatch[2] || anchorMatch[3];
88
- const cleanedText = text.replace(anchorMatch[0], '').trimEnd();
89
- return { cleanedText, explicitId };
66
+ const anchorMatch = text.match(/(\\\{#([^}]+)\\\}|\{#([^}]+)\})\s*$/);
67
+ if (!anchorMatch) return { cleanedText: text };
68
+ const explicitId = anchorMatch[2] || anchorMatch[3];
69
+ return {
70
+ cleanedText: text.replace(anchorMatch[0], "").trimEnd(),
71
+ explicitId
72
+ };
90
73
  }
91
74
  /**
92
- * Checks if a heading is already wrapped in a div with id
93
- */
75
+ * Checks if a heading is already wrapped in a div with id
76
+ */
94
77
  function hasExplicitId(heading, _ast) {
95
- const lastChild = heading.children[heading.children.length - 1];
96
- if (lastChild?.type === 'text') {
97
- return /(\{#[^}]+\}|\\\{#[^}]+\\\}|\[[^\]]+\])\s*$/.test(lastChild.value);
98
- }
99
- return false;
78
+ const lastChild = heading.children[heading.children.length - 1];
79
+ if (lastChild?.type === "text") return /(\{#[^}]+\}|\\\{#[^}]+\\\}|\[[^\]]+\])\s*$/.test(lastChild.value);
80
+ return false;
100
81
  }
101
82
  /**
102
- * Extracts heading information from content (read-only, no modifications)
103
- */
104
- export function extractHeadingInfo(mdxContent) {
105
- const headings = [];
106
- // Parse the MDX content into an AST
107
- let processedAst;
108
- try {
109
- const parseProcessor = unified()
110
- .use(remarkParse)
111
- .use(remarkFrontmatter, ['yaml', 'toml'])
112
- .use(remarkMdx);
113
- const ast = parseProcessor.parse(mdxContent);
114
- processedAst = parseProcessor.runSync(ast);
115
- }
116
- catch {
117
- // Fallback: line-by-line extraction skipping fenced code blocks
118
- return extractHeadingsWithFallback(mdxContent);
119
- }
120
- let position = 0;
121
- visit(processedAst, 'heading', (heading) => {
122
- const headingText = extractHeadingText(heading);
123
- const { cleanedText, explicitId } = parseHeadingContent(headingText);
124
- if (cleanedText || explicitId) {
125
- const slug = explicitId ?? generateSlug(cleanedText);
126
- headings.push({
127
- text: cleanedText,
128
- level: heading.depth,
129
- slug,
130
- position: position++,
131
- });
132
- }
133
- });
134
- return headings;
83
+ * Extracts heading information from content (read-only, no modifications)
84
+ */
85
+ function extractHeadingInfo(mdxContent) {
86
+ const headings = [];
87
+ let processedAst;
88
+ try {
89
+ const parseProcessor = unified().use(remarkParse).use(remarkFrontmatter, ["yaml", "toml"]).use(remarkMdx);
90
+ const ast = parseProcessor.parse(mdxContent);
91
+ processedAst = parseProcessor.runSync(ast);
92
+ } catch {
93
+ return extractHeadingsWithFallback(mdxContent);
94
+ }
95
+ let position = 0;
96
+ visit(processedAst, "heading", (heading) => {
97
+ const { cleanedText, explicitId } = parseHeadingContent(extractHeadingText(heading));
98
+ if (cleanedText || explicitId) {
99
+ const slug = explicitId ?? generateSlug(cleanedText);
100
+ headings.push({
101
+ text: cleanedText,
102
+ level: heading.depth,
103
+ slug,
104
+ position: position++
105
+ });
106
+ }
107
+ });
108
+ return headings;
135
109
  }
136
110
  /**
137
- * Applies anchor IDs to translated content based on source heading mapping
138
- */
139
- export function addExplicitAnchorIds(translatedContent, sourceHeadingMap, settings, sourcePath, translatedPath, fileTypeHint) {
140
- const addedIds = [];
141
- const useDivWrapping = settings?.options?.experimentalAddHeaderAnchorIds === 'mintlify';
142
- // Extract headings from translated content
143
- const translatedHeadings = extractHeadingInfo(translatedContent);
144
- // Pre-processing validation: check if header counts match
145
- if (sourceHeadingMap.length !== translatedHeadings.length) {
146
- const sourceFile = sourcePath
147
- ? `Source file: ${sourcePath}`
148
- : 'Source file';
149
- const translatedFile = translatedPath
150
- ? `translated file: ${translatedPath}`
151
- : 'translated file';
152
- logger.warn(`Header count mismatch detected! ${sourceFile} has ${sourceHeadingMap.length} headers but ${translatedFile} has ${translatedHeadings.length} headers. ` +
153
- `This likely means your source file was edited after translation was requested, causing a mismatch between ` +
154
- `the number of headers in your source file vs the translated file. Re-translate this file to resolve the issue.`);
155
- }
156
- // Create ID mapping based on positional matching
157
- const idMappings = new Map();
158
- sourceHeadingMap.forEach((sourceHeading, index) => {
159
- const translatedHeading = translatedHeadings[index];
160
- // Match by position and level for safety
161
- if (translatedHeading && translatedHeading.level === sourceHeading.level) {
162
- idMappings.set(index, sourceHeading.slug);
163
- addedIds.push({
164
- heading: translatedHeading.text,
165
- id: sourceHeading.slug,
166
- });
167
- }
168
- });
169
- if (idMappings.size === 0) {
170
- return {
171
- content: translatedContent,
172
- hasChanges: false,
173
- addedIds: [],
174
- };
175
- }
176
- const translatedIsMdx = translatedPath
177
- ? translatedPath.toLowerCase().endsWith('.mdx')
178
- : true; // default to mdx-style escaping when unknown
179
- const shouldEscapeAnchors = fileTypeHint === 'mdx'
180
- ? true
181
- : fileTypeHint === 'md'
182
- ? false
183
- : translatedIsMdx;
184
- // Apply IDs to translated content
185
- let content;
186
- if (useDivWrapping) {
187
- content = applyDivWrappedIds(translatedContent, translatedHeadings, idMappings);
188
- }
189
- else {
190
- content = applyInlineIds(translatedContent, idMappings, shouldEscapeAnchors);
191
- }
192
- return {
193
- content,
194
- hasChanges: content !== translatedContent,
195
- addedIds,
196
- };
111
+ * Applies anchor IDs to translated content based on source heading mapping
112
+ */
113
+ function addExplicitAnchorIds(translatedContent, sourceHeadingMap, settings, sourcePath, translatedPath, fileTypeHint) {
114
+ const addedIds = [];
115
+ const useDivWrapping = settings?.options?.experimentalAddHeaderAnchorIds === "mintlify";
116
+ const translatedHeadings = extractHeadingInfo(translatedContent);
117
+ if (sourceHeadingMap.length !== translatedHeadings.length) {
118
+ const sourceFile = sourcePath ? `Source file: ${sourcePath}` : "Source file";
119
+ const translatedFile = translatedPath ? `translated file: ${translatedPath}` : "translated file";
120
+ logger.warn(`Header count mismatch detected! ${sourceFile} has ${sourceHeadingMap.length} headers but ${translatedFile} has ${translatedHeadings.length} headers. This likely means your source file was edited after translation was requested, causing a mismatch between the number of headers in your source file vs the translated file. Re-translate this file to resolve the issue.`);
121
+ }
122
+ const idMappings = /* @__PURE__ */ new Map();
123
+ sourceHeadingMap.forEach((sourceHeading, index) => {
124
+ const translatedHeading = translatedHeadings[index];
125
+ if (translatedHeading && translatedHeading.level === sourceHeading.level) {
126
+ idMappings.set(index, sourceHeading.slug);
127
+ addedIds.push({
128
+ heading: translatedHeading.text,
129
+ id: sourceHeading.slug
130
+ });
131
+ }
132
+ });
133
+ if (idMappings.size === 0) return {
134
+ content: translatedContent,
135
+ hasChanges: false,
136
+ addedIds: []
137
+ };
138
+ const translatedIsMdx = translatedPath ? translatedPath.toLowerCase().endsWith(".mdx") : true;
139
+ const shouldEscapeAnchors = fileTypeHint === "mdx" ? true : fileTypeHint === "md" ? false : translatedIsMdx;
140
+ let content;
141
+ if (useDivWrapping) content = applyDivWrappedIds(translatedContent, translatedHeadings, idMappings);
142
+ else content = applyInlineIds(translatedContent, idMappings, shouldEscapeAnchors);
143
+ return {
144
+ content,
145
+ hasChanges: content !== translatedContent,
146
+ addedIds
147
+ };
197
148
  }
198
149
  /**
199
- * Adds inline {#id} syntax to headings (standard markdown approach)
200
- */
150
+ * Adds inline {#id} syntax to headings (standard markdown approach)
151
+ */
201
152
  function applyInlineIds(translatedContent, idMappings, escapeAnchors) {
202
- const escapeInlineAnchors = (content) => {
203
- if (!escapeAnchors)
204
- return content;
205
- return content.replace(/\{#([A-Za-z0-9-_]+)\}/g, (match, id, offset, str) => {
206
- if (offset > 0 && str[offset - 1] === '\\') {
207
- return match;
208
- }
209
- return `\\{#${id}\\}`;
210
- });
211
- };
212
- // Parse the translated content
213
- let processedAst;
214
- try {
215
- const parseProcessor = unified()
216
- .use(remarkParse)
217
- .use(remarkFrontmatter, ['yaml', 'toml'])
218
- .use(remarkMdx);
219
- const ast = parseProcessor.parse(translatedContent);
220
- processedAst = parseProcessor.runSync(ast);
221
- }
222
- catch {
223
- return applyInlineIdsStringFallback(translatedContent, idMappings, escapeAnchors);
224
- }
225
- // Apply IDs to headings based on position
226
- let headingIndex = 0;
227
- let actuallyModifiedContent = false;
228
- visit(processedAst, 'heading', (heading) => {
229
- const id = idMappings.get(headingIndex);
230
- if (id) {
231
- // Skip if heading already has explicit ID
232
- if (hasExplicitId(heading, processedAst)) {
233
- if (escapeAnchors) {
234
- // Normalize existing inline IDs to escaped form
235
- const lastChild = heading.children[heading.children.length - 1];
236
- if (lastChild?.type === 'text') {
237
- const match = lastChild.value.match(/\{#([^}]+)\}\s*$/);
238
- const alreadyEscaped = lastChild.value.match(/\\\{#[^}]+\\\}\s*$/);
239
- if (match && !alreadyEscaped) {
240
- const anchorId = match[1];
241
- const base = lastChild.value.replace(/\s*\{#[^}]+\}\s*$/, '');
242
- lastChild.value = `${base} \\{#${anchorId}\\}`;
243
- actuallyModifiedContent = true;
244
- }
245
- }
246
- }
247
- headingIndex++;
248
- return;
249
- }
250
- // Add the ID to the heading
251
- const lastChild = heading.children[heading.children.length - 1];
252
- if (lastChild?.type === 'text') {
253
- lastChild.value += escapeAnchors ? ` \\{#${id}\\}` : ` {#${id}}`;
254
- }
255
- else {
256
- // If last child is not text, add a new text node
257
- heading.children.push({
258
- type: 'text',
259
- value: escapeAnchors ? ` \\{#${id}\\}` : ` {#${id}}`,
260
- });
261
- }
262
- actuallyModifiedContent = true;
263
- }
264
- headingIndex++;
265
- });
266
- // If we didn't modify any headings, return original content
267
- if (!actuallyModifiedContent) {
268
- const escaped = escapeInlineAnchors(translatedContent);
269
- return escaped;
270
- }
271
- // Convert the modified AST back to MDX string
272
- try {
273
- const stringifyProcessor = unified()
274
- .use(remarkFrontmatter, ['yaml', 'toml'])
275
- .use(remarkMdx)
276
- .use(normalizeCJKCharacters)
277
- .use(escapeHtmlInTextNodes)
278
- .use(remarkStringify, {
279
- handlers: {
280
- // Custom handler to prevent escaping of {#id} syntax
281
- text(node) {
282
- return node.value;
283
- },
284
- },
285
- });
286
- const outTree = stringifyProcessor.runSync(processedAst);
287
- let content = stringifyProcessor.stringify(outTree);
288
- // Handle newline formatting to match original input
289
- if (content.endsWith('\n') && !translatedContent.endsWith('\n')) {
290
- content = content.slice(0, -1);
291
- }
292
- // Preserve leading newlines from original content
293
- if (translatedContent.startsWith('\n') && !content.startsWith('\n')) {
294
- content = '\n' + content;
295
- }
296
- return content;
297
- }
298
- catch {
299
- return translatedContent;
300
- }
153
+ const escapeInlineAnchors = (content) => {
154
+ if (!escapeAnchors) return content;
155
+ return content.replace(/\{#([A-Za-z0-9-_]+)\}/g, (match, id, offset, str) => {
156
+ if (offset > 0 && str[offset - 1] === "\\") return match;
157
+ return `\\{#${id}\\}`;
158
+ });
159
+ };
160
+ let processedAst;
161
+ try {
162
+ const parseProcessor = unified().use(remarkParse).use(remarkFrontmatter, ["yaml", "toml"]).use(remarkMdx);
163
+ const ast = parseProcessor.parse(translatedContent);
164
+ processedAst = parseProcessor.runSync(ast);
165
+ } catch {
166
+ return applyInlineIdsStringFallback(translatedContent, idMappings, escapeAnchors);
167
+ }
168
+ let headingIndex = 0;
169
+ let actuallyModifiedContent = false;
170
+ visit(processedAst, "heading", (heading) => {
171
+ const id = idMappings.get(headingIndex);
172
+ if (id) {
173
+ if (hasExplicitId(heading, processedAst)) {
174
+ if (escapeAnchors) {
175
+ const lastChild = heading.children[heading.children.length - 1];
176
+ if (lastChild?.type === "text") {
177
+ const match = lastChild.value.match(/\{#([^}]+)\}\s*$/);
178
+ const alreadyEscaped = lastChild.value.match(/\\\{#[^}]+\\\}\s*$/);
179
+ if (match && !alreadyEscaped) {
180
+ const anchorId = match[1];
181
+ lastChild.value = `${lastChild.value.replace(/\s*\{#[^}]+\}\s*$/, "")} \\{#${anchorId}\\}`;
182
+ actuallyModifiedContent = true;
183
+ }
184
+ }
185
+ }
186
+ headingIndex++;
187
+ return;
188
+ }
189
+ const lastChild = heading.children[heading.children.length - 1];
190
+ if (lastChild?.type === "text") lastChild.value += escapeAnchors ? ` \\{#${id}\\}` : ` {#${id}}`;
191
+ else heading.children.push({
192
+ type: "text",
193
+ value: escapeAnchors ? ` \\{#${id}\\}` : ` {#${id}}`
194
+ });
195
+ actuallyModifiedContent = true;
196
+ }
197
+ headingIndex++;
198
+ });
199
+ if (!actuallyModifiedContent) return escapeInlineAnchors(translatedContent);
200
+ try {
201
+ const stringifyProcessor = unified().use(remarkFrontmatter, ["yaml", "toml"]).use(remarkMdx).use(normalizeCJKCharacters).use(escapeHtmlInTextNodes).use(remarkStringify, { handlers: { text(node) {
202
+ return node.value;
203
+ } } });
204
+ const outTree = stringifyProcessor.runSync(processedAst);
205
+ let content = stringifyProcessor.stringify(outTree);
206
+ if (content.endsWith("\n") && !translatedContent.endsWith("\n")) content = content.slice(0, -1);
207
+ if (translatedContent.startsWith("\n") && !content.startsWith("\n")) content = "\n" + content;
208
+ return content;
209
+ } catch {
210
+ return translatedContent;
211
+ }
301
212
  }
302
213
  /**
303
- * Fallback string-based inline ID application when AST parsing fails
304
- */
214
+ * Fallback string-based inline ID application when AST parsing fails
215
+ */
305
216
  function applyInlineIdsStringFallback(translatedContent, idMappings, escapeAnchors) {
306
- let headingIndex = 0;
307
- let inFence = false;
308
- let fenceChar = null;
309
- const processedLines = translatedContent.split('\n').map((line) => {
310
- const fenceMatch = line.match(/^(\s*)(`{3,}|~{3,})/);
311
- if (fenceMatch) {
312
- const fenceString = fenceMatch[2];
313
- if (!inFence) {
314
- inFence = true;
315
- fenceChar = fenceString;
316
- }
317
- else if (fenceChar &&
318
- fenceString[0] === fenceChar[0] &&
319
- fenceString.length >= fenceChar.length) {
320
- inFence = false;
321
- fenceChar = null;
322
- }
323
- return line;
324
- }
325
- if (inFence) {
326
- return line;
327
- }
328
- const headingMatch = line.match(/^(#{1,6}\s+)(.*)$/);
329
- if (!headingMatch) {
330
- return line;
331
- }
332
- const prefix = headingMatch[1];
333
- const text = headingMatch[2];
334
- const id = idMappings.get(headingIndex++);
335
- if (!id) {
336
- return line;
337
- }
338
- const hasEscaped = /\\\{#[^}]+\\\}\s*$/.test(text);
339
- const hasUnescaped = /\{#[^}]+\}\s*$/.test(text);
340
- if (hasEscaped) {
341
- return line;
342
- }
343
- if (hasUnescaped) {
344
- if (!escapeAnchors) {
345
- return line;
346
- }
347
- return `${prefix}${text.replace(/\{#([^}]+)\}\s*$/, '\\{#$1\\}')}`;
348
- }
349
- const suffix = escapeAnchors ? ` \\{#${id}\\}` : ` {#${id}}`;
350
- return `${prefix}${text}${suffix}`;
351
- });
352
- return processedLines.join('\n');
217
+ let headingIndex = 0;
218
+ let inFence = false;
219
+ let fenceChar = null;
220
+ return translatedContent.split("\n").map((line) => {
221
+ const fenceMatch = line.match(/^(\s*)(`{3,}|~{3,})/);
222
+ if (fenceMatch) {
223
+ const fenceString = fenceMatch[2];
224
+ if (!inFence) {
225
+ inFence = true;
226
+ fenceChar = fenceString;
227
+ } else if (fenceChar && fenceString[0] === fenceChar[0] && fenceString.length >= fenceChar.length) {
228
+ inFence = false;
229
+ fenceChar = null;
230
+ }
231
+ return line;
232
+ }
233
+ if (inFence) return line;
234
+ const headingMatch = line.match(/^(#{1,6}\s+)(.*)$/);
235
+ if (!headingMatch) return line;
236
+ const prefix = headingMatch[1];
237
+ const text = headingMatch[2];
238
+ const id = idMappings.get(headingIndex++);
239
+ if (!id) return line;
240
+ const hasEscaped = /\\\{#[^}]+\\\}\s*$/.test(text);
241
+ const hasUnescaped = /\{#[^}]+\}\s*$/.test(text);
242
+ if (hasEscaped) return line;
243
+ if (hasUnescaped) {
244
+ if (!escapeAnchors) return line;
245
+ return `${prefix}${text.replace(/\{#([^}]+)\}\s*$/, "\\{#$1\\}")}`;
246
+ }
247
+ return `${prefix}${text}${escapeAnchors ? ` \\{#${id}\\}` : ` {#${id}}`}`;
248
+ }).join("\n");
353
249
  }
354
250
  /**
355
- * Wraps headings in divs with IDs (Mintlify approach)
356
- */
251
+ * Wraps headings in divs with IDs (Mintlify approach)
252
+ */
357
253
  function applyDivWrappedIds(translatedContent, translatedHeadings, idMappings) {
358
- // Extract all heading lines from the translated markdown
359
- const lines = translatedContent.split('\n');
360
- const headingLines = [];
361
- lines.forEach((line, index) => {
362
- const headingMatch = line.match(/^(#{1,6})\s+(.+)$/);
363
- if (headingMatch) {
364
- const level = headingMatch[1].length;
365
- headingLines.push({ line, level, index });
366
- }
367
- });
368
- // Use string-based approach to wrap headings in divs
369
- let content = translatedContent;
370
- const headingsToWrap = [];
371
- // Match translated headings with their corresponding lines by position and level
372
- translatedHeadings.forEach((heading, position) => {
373
- const id = idMappings.get(position);
374
- if (id) {
375
- // Find the corresponding original line for this heading
376
- const matchingLine = headingLines.find((hl) => {
377
- // Extract clean text from the original line for comparison
378
- const lineCleanText = hl.line.replace(/^#{1,6}\s+/, '').trim();
379
- // Create a version without markdown formatting for comparison
380
- const cleanLineText = lineCleanText
381
- .replace(/\*\*(.*?)\*\*/g, '$1') // Remove bold
382
- .replace(/\*(.*?)\*/g, '$1') // Remove italic
383
- .replace(/`(.*?)`/g, '$1') // Remove inline code
384
- .replace(/\[(.*?)\]\(.*?\)/g, '$1') // Remove links, keep text
385
- .trim();
386
- const normalizedLineText = decode(cleanLineText).trim();
387
- const normalizedHeadingText = decode(heading.text).trim();
388
- return (normalizedLineText === normalizedHeadingText &&
389
- hl.level === heading.level);
390
- });
391
- if (matchingLine) {
392
- headingsToWrap.push({
393
- originalLine: matchingLine.line,
394
- id,
395
- });
396
- }
397
- }
398
- });
399
- if (headingsToWrap.length > 0) {
400
- // Process headings from longest to shortest original line to avoid partial matches
401
- const sortedHeadings = headingsToWrap.sort((a, b) => b.originalLine.length - a.originalLine.length);
402
- for (const heading of sortedHeadings) {
403
- // If already wrapped with this id, skip (idempotent)
404
- if (content.includes(`<div id="${heading.id}">`)) {
405
- continue;
406
- }
407
- // Escape the original line for use in regex
408
- const escapedLine = heading.originalLine.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
409
- const headingPattern = new RegExp(`^${escapedLine}\\s*$`, 'gm');
410
- content = content.replace(headingPattern, (match) => {
411
- return `<div id="${heading.id}">\n ${match.trim()}\n</div>\n`;
412
- });
413
- }
414
- }
415
- return content;
254
+ const lines = translatedContent.split("\n");
255
+ const headingLines = [];
256
+ lines.forEach((line, index) => {
257
+ const headingMatch = line.match(/^(#{1,6})\s+(.+)$/);
258
+ if (headingMatch) {
259
+ const level = headingMatch[1].length;
260
+ headingLines.push({
261
+ line,
262
+ level,
263
+ index
264
+ });
265
+ }
266
+ });
267
+ let content = translatedContent;
268
+ const headingsToWrap = [];
269
+ translatedHeadings.forEach((heading, position) => {
270
+ const id = idMappings.get(position);
271
+ if (id) {
272
+ const matchingLine = headingLines.find((hl) => {
273
+ return decode(hl.line.replace(/^#{1,6}\s+/, "").trim().replace(/\*\*(.*?)\*\*/g, "$1").replace(/\*(.*?)\*/g, "$1").replace(/`(.*?)`/g, "$1").replace(/\[(.*?)\]\(.*?\)/g, "$1").trim()).trim() === decode(heading.text).trim() && hl.level === heading.level;
274
+ });
275
+ if (matchingLine) headingsToWrap.push({
276
+ originalLine: matchingLine.line,
277
+ id
278
+ });
279
+ }
280
+ });
281
+ if (headingsToWrap.length > 0) {
282
+ const sortedHeadings = headingsToWrap.sort((a, b) => b.originalLine.length - a.originalLine.length);
283
+ for (const heading of sortedHeadings) {
284
+ if (content.includes(`<div id="${heading.id}">`)) continue;
285
+ const escapedLine = heading.originalLine.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
286
+ const headingPattern = new RegExp(`^${escapedLine}\\s*$`, "gm");
287
+ content = content.replace(headingPattern, (match) => {
288
+ return `<div id="${heading.id}">\n ${match.trim()}\n</div>\n`;
289
+ });
290
+ }
291
+ }
292
+ return content;
416
293
  }
294
+ //#endregion
295
+ export { addExplicitAnchorIds, extractHeadingInfo };
296
+
297
+ //# sourceMappingURL=addExplicitAnchorIds.js.map