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.
- package/CHANGELOG.md +22 -1
- package/dist/api/collectUserEditDiffs.js +112 -155
- package/dist/api/collectUserEditDiffs.js.map +1 -0
- package/dist/api/downloadFileBatch.js +164 -241
- package/dist/api/downloadFileBatch.js.map +1 -0
- package/dist/api/saveLocalEdits.js +37 -41
- package/dist/api/saveLocalEdits.js.map +1 -0
- package/dist/bin/bin-entry.js +17 -7
- package/dist/bin/bin-entry.js.map +1 -0
- package/dist/bin/bin-main.js +43 -61
- package/dist/bin/bin-main.js.map +1 -0
- package/dist/cli/base.js +382 -497
- package/dist/cli/base.js.map +1 -0
- package/dist/cli/commands/download.js +41 -49
- package/dist/cli/commands/download.js.map +1 -0
- package/dist/cli/commands/enqueue.js +26 -25
- package/dist/cli/commands/enqueue.js.map +1 -0
- package/dist/cli/commands/setupProject.js +33 -36
- package/dist/cli/commands/setupProject.js.map +1 -0
- package/dist/cli/commands/stage.js +53 -61
- package/dist/cli/commands/stage.js.map +1 -0
- package/dist/cli/commands/translate.js +75 -112
- package/dist/cli/commands/translate.js.map +1 -0
- package/dist/cli/commands/upload.js +185 -213
- package/dist/cli/commands/upload.js.map +1 -0
- package/dist/cli/commands/utils/validation.js +39 -34
- package/dist/cli/commands/utils/validation.js.map +1 -0
- package/dist/cli/flags.js +35 -62
- package/dist/cli/flags.js.map +1 -0
- package/dist/cli/inline.js +112 -137
- package/dist/cli/inline.js.map +1 -0
- package/dist/cli/next.js +17 -12
- package/dist/cli/next.js.map +1 -0
- package/dist/cli/node.js +19 -15
- package/dist/cli/node.js.map +1 -0
- package/dist/cli/python.js +13 -8
- package/dist/cli/python.js.map +1 -0
- package/dist/cli/react.js +61 -78
- package/dist/cli/react.js.map +1 -0
- package/dist/config/defaults.js +16 -11
- package/dist/config/defaults.js.map +1 -0
- package/dist/config/generateSettings.js +167 -269
- package/dist/config/generateSettings.js.map +1 -0
- package/dist/config/optionPresets.js +78 -96
- package/dist/config/optionPresets.js.map +1 -0
- package/dist/config/resolveConfig.js +27 -32
- package/dist/config/resolveConfig.js.map +1 -0
- package/dist/config/utils.js +7 -3
- package/dist/config/utils.js.map +1 -0
- package/dist/config/validateSettings.js +19 -30
- package/dist/config/validateSettings.js.map +1 -0
- package/dist/console/colors.js +18 -13
- package/dist/console/colors.js.map +1 -0
- package/dist/console/displayTranslateSummary.js +40 -37
- package/dist/console/displayTranslateSummary.js.map +1 -0
- package/dist/console/formatting.js +8 -5
- package/dist/console/formatting.js.map +1 -0
- package/dist/console/index.d.ts +11 -9
- package/dist/console/index.js +53 -50
- package/dist/console/index.js.map +1 -0
- package/dist/console/inkFields.d.ts +23 -0
- package/dist/console/inkFields.js +87 -0
- package/dist/console/inkFields.js.map +1 -0
- package/dist/console/inkLayout.d.ts +7 -0
- package/dist/console/inkLayout.js +139 -0
- package/dist/console/inkLayout.js.map +1 -0
- package/dist/console/inkLocaleData.d.ts +4 -0
- package/dist/console/inkLocaleData.js +32 -0
- package/dist/console/inkLocaleData.js.map +1 -0
- package/dist/console/inkPrompts.d.ts +8 -0
- package/dist/console/inkPrompts.js +496 -0
- package/dist/console/inkPrompts.js.map +1 -0
- package/dist/console/inkSession.d.ts +3 -0
- package/dist/console/inkSession.js +42 -0
- package/dist/console/inkSession.js.map +1 -0
- package/dist/console/inkTerminal.d.ts +4 -0
- package/dist/console/inkTerminal.js +15 -0
- package/dist/console/inkTerminal.js.map +1 -0
- package/dist/console/inkTypes.d.ts +66 -0
- package/dist/console/inkTypes.js +1 -0
- package/dist/console/inkUtils.d.ts +24 -0
- package/dist/console/inkUtils.js +87 -0
- package/dist/console/inkUtils.js.map +1 -0
- package/dist/console/logger.js +209 -249
- package/dist/console/logger.js.map +1 -0
- package/dist/console/logging.d.ts +14 -0
- package/dist/console/logging.js +203 -162
- package/dist/console/logging.js.map +1 -0
- package/dist/console/promptParsing.d.ts +5 -0
- package/dist/console/promptParsing.js +28 -0
- package/dist/console/promptParsing.js.map +1 -0
- package/dist/console/terminalSession.d.ts +5 -0
- package/dist/console/terminalSession.js +38 -0
- package/dist/console/terminalSession.js.map +1 -0
- package/dist/extraction/index.js +3 -2
- package/dist/extraction/mapToUpdates.js +19 -18
- package/dist/extraction/mapToUpdates.js.map +1 -0
- package/dist/extraction/postProcess.js +68 -86
- package/dist/extraction/postProcess.js.map +1 -0
- package/dist/formats/files/aggregateFiles.js +223 -304
- package/dist/formats/files/aggregateFiles.js.map +1 -0
- package/dist/formats/files/collectFiles.js +53 -54
- package/dist/formats/files/collectFiles.js.map +1 -0
- package/dist/formats/files/convertToFileTranslationData.js +21 -19
- package/dist/formats/files/convertToFileTranslationData.js.map +1 -0
- package/dist/formats/files/fileMapping.js +82 -119
- package/dist/formats/files/fileMapping.js.map +1 -0
- package/dist/formats/files/preprocess/mdx.js +15 -12
- package/dist/formats/files/preprocess/mdx.js.map +1 -0
- package/dist/formats/files/preprocess/mintlify.js +15 -13
- package/dist/formats/files/preprocess/mintlify.js.map +1 -0
- package/dist/formats/files/preprocessContent.js +20 -21
- package/dist/formats/files/preprocessContent.js.map +1 -0
- package/dist/formats/files/save.js +18 -15
- package/dist/formats/files/save.js.map +1 -0
- package/dist/formats/files/supportedFiles.js +27 -22
- package/dist/formats/files/supportedFiles.js.map +1 -0
- package/dist/formats/files/transformFormat.js +93 -100
- package/dist/formats/files/transformFormat.js.map +1 -0
- package/dist/formats/json/extractJson.js +83 -110
- package/dist/formats/json/extractJson.js.map +1 -0
- package/dist/formats/json/flattenJson.js +41 -48
- package/dist/formats/json/flattenJson.js.map +1 -0
- package/dist/formats/json/jsonPath.js +20 -15
- package/dist/formats/json/jsonPath.js.map +1 -0
- package/dist/formats/json/jsonPointer.js +17 -17
- package/dist/formats/json/jsonPointer.js.map +1 -0
- package/dist/formats/json/mergeJson.js +230 -371
- package/dist/formats/json/mergeJson.js.map +1 -0
- package/dist/formats/json/parseJson.js +74 -111
- package/dist/formats/json/parseJson.js.map +1 -0
- package/dist/formats/json/transformJson.js +53 -61
- package/dist/formats/json/transformJson.js.map +1 -0
- package/dist/formats/json/utils.js +158 -187
- package/dist/formats/json/utils.js.map +1 -0
- package/dist/formats/parseKeyedMetadata.js +85 -106
- package/dist/formats/parseKeyedMetadata.js.map +1 -0
- package/dist/formats/utils.js +13 -23
- package/dist/formats/utils.js.map +1 -0
- package/dist/formats/yaml/extractYaml.js +32 -31
- package/dist/formats/yaml/extractYaml.js.map +1 -0
- package/dist/formats/yaml/mergeYaml.js +43 -60
- package/dist/formats/yaml/mergeYaml.js.map +1 -0
- package/dist/formats/yaml/parseYaml.js +34 -23
- package/dist/formats/yaml/parseYaml.js.map +1 -0
- package/dist/formats/yaml/utils.js +19 -21
- package/dist/formats/yaml/utils.js.map +1 -0
- package/dist/fs/clearLocaleDirs.js +82 -114
- package/dist/fs/clearLocaleDirs.js.map +1 -0
- package/dist/fs/config/downloadedVersions.js +174 -188
- package/dist/fs/config/downloadedVersions.js.map +1 -0
- package/dist/fs/config/loadConfig.js +12 -8
- package/dist/fs/config/loadConfig.js.map +1 -0
- package/dist/fs/config/parseFilesConfig.js +166 -227
- package/dist/fs/config/parseFilesConfig.js.map +1 -0
- package/dist/fs/config/setupConfig.js +43 -52
- package/dist/fs/config/setupConfig.js.map +1 -0
- package/dist/fs/config/updateConfig.js +44 -56
- package/dist/fs/config/updateConfig.js.map +1 -0
- package/dist/fs/config/updateVersions.js +27 -28
- package/dist/fs/config/updateVersions.js.map +1 -0
- package/dist/fs/copyFile.js +33 -37
- package/dist/fs/copyFile.js.map +1 -0
- package/dist/fs/createLoadTranslationsFile.js +32 -48
- package/dist/fs/createLoadTranslationsFile.js.map +1 -0
- package/dist/fs/determineFramework/detectPythonLibrary.js +30 -34
- package/dist/fs/determineFramework/detectPythonLibrary.js.map +1 -0
- package/dist/fs/determineFramework/index.js +46 -64
- package/dist/fs/determineFramework/index.js.map +1 -0
- package/dist/fs/determineFramework/matchPyprojectDependency.js +65 -78
- package/dist/fs/determineFramework/matchPyprojectDependency.js.map +1 -0
- package/dist/fs/determineFramework/matchRequirementsTxtDependency.js +21 -19
- package/dist/fs/determineFramework/matchRequirementsTxtDependency.js.map +1 -0
- package/dist/fs/determineFramework/matchSetupPyDependency.js +60 -81
- package/dist/fs/determineFramework/matchSetupPyDependency.js.map +1 -0
- package/dist/fs/determineFramework/resolveGtDependency.js +15 -15
- package/dist/fs/determineFramework/resolveGtDependency.js.map +1 -0
- package/dist/fs/findFilepath.js +63 -78
- package/dist/fs/findFilepath.js.map +1 -0
- package/dist/fs/loadJSON.js +18 -15
- package/dist/fs/loadJSON.js.map +1 -0
- package/dist/fs/matchFiles.js +12 -7
- package/dist/fs/matchFiles.js.map +1 -0
- package/dist/fs/saveJSON.js +10 -6
- package/dist/fs/saveJSON.js.map +1 -0
- package/dist/fs/utils.js +19 -15
- package/dist/fs/utils.js.map +1 -0
- package/dist/functions.d.ts +2 -1
- package/dist/functions.js +3 -6
- package/dist/generated/version.d.ts +1 -1
- package/dist/generated/version.js +6 -2
- package/dist/generated/version.js.map +1 -0
- package/dist/git/branches.js +77 -83
- package/dist/git/branches.js.map +1 -0
- package/dist/hooks/postProcess.js +97 -114
- package/dist/hooks/postProcess.js.map +1 -0
- package/dist/index.js +23 -31
- package/dist/index.js.map +1 -0
- package/dist/locadex/setupFlow.js +11 -8
- package/dist/locadex/setupFlow.js.map +1 -0
- package/dist/main.js +17 -7
- package/dist/main.js.map +1 -0
- package/dist/next/config/parseNextConfig.js +32 -51
- package/dist/next/config/parseNextConfig.js.map +1 -0
- package/dist/next/jsx/utils.js +25 -37
- package/dist/next/jsx/utils.js.map +1 -0
- package/dist/next/parse/handleInitGT.js +87 -154
- package/dist/next/parse/handleInitGT.js.map +1 -0
- package/dist/next/parse/wrapContent.js +136 -158
- package/dist/next/parse/wrapContent.js.map +1 -0
- package/dist/python/parse/createPythonInlineUpdates.js +36 -33
- package/dist/python/parse/createPythonInlineUpdates.js.map +1 -0
- package/dist/react/config/createESBuildConfig.js +115 -115
- package/dist/react/config/createESBuildConfig.js.map +1 -0
- package/dist/react/jsx/evaluateJsx.js +90 -124
- package/dist/react/jsx/evaluateJsx.js.map +1 -0
- package/dist/react/jsx/utils/buildImportMap.js +24 -28
- package/dist/react/jsx/utils/buildImportMap.js.map +1 -0
- package/dist/react/jsx/utils/constants.js +79 -87
- package/dist/react/jsx/utils/constants.js.map +1 -0
- package/dist/react/jsx/utils/extractSourceCode.js +36 -37
- package/dist/react/jsx/utils/extractSourceCode.js.map +1 -0
- package/dist/react/jsx/utils/getCalleeNameFromExpression.js +30 -30
- package/dist/react/jsx/utils/getCalleeNameFromExpression.js.map +1 -0
- package/dist/react/jsx/utils/getPathsAndAliases.js +70 -105
- package/dist/react/jsx/utils/getPathsAndAliases.js.map +1 -0
- package/dist/react/jsx/utils/isNumberLiteral.js +13 -11
- package/dist/react/jsx/utils/isNumberLiteral.js.map +1 -0
- package/dist/react/jsx/utils/jsxParsing/addGTIdentifierToSyntaxTree.js +103 -148
- package/dist/react/jsx/utils/jsxParsing/addGTIdentifierToSyntaxTree.js.map +1 -0
- package/dist/react/jsx/utils/jsxParsing/autoInsertion.js +305 -389
- package/dist/react/jsx/utils/jsxParsing/autoInsertion.js.map +1 -0
- package/dist/react/jsx/utils/jsxParsing/handleChildrenWhitespace.js +122 -193
- package/dist/react/jsx/utils/jsxParsing/handleChildrenWhitespace.js.map +1 -0
- package/dist/react/jsx/utils/jsxParsing/multiplication/findMultiplicationNode.js +50 -64
- package/dist/react/jsx/utils/jsxParsing/multiplication/findMultiplicationNode.js.map +1 -0
- package/dist/react/jsx/utils/jsxParsing/multiplication/multiplyJsxTree.js +41 -68
- package/dist/react/jsx/utils/jsxParsing/multiplication/multiplyJsxTree.js.map +1 -0
- package/dist/react/jsx/utils/jsxParsing/parseJsx.js +760 -1107
- package/dist/react/jsx/utils/jsxParsing/parseJsx.js.map +1 -0
- package/dist/react/jsx/utils/jsxParsing/parseTProps.js +35 -71
- package/dist/react/jsx/utils/jsxParsing/parseTProps.js.map +1 -0
- package/dist/react/jsx/utils/jsxParsing/removeNullChildrenFields.js +39 -58
- package/dist/react/jsx/utils/jsxParsing/removeNullChildrenFields.js.map +1 -0
- package/dist/react/jsx/utils/jsxParsing/types.js +10 -24
- package/dist/react/jsx/utils/jsxParsing/types.js.map +1 -0
- package/dist/react/jsx/utils/mapAttributeName.js +13 -13
- package/dist/react/jsx/utils/mapAttributeName.js.map +1 -0
- package/dist/react/jsx/utils/parseAst.js +142 -272
- package/dist/react/jsx/utils/parseAst.js.map +1 -0
- package/dist/react/jsx/utils/parseString.js +726 -1090
- package/dist/react/jsx/utils/parseString.js.map +1 -0
- package/dist/react/jsx/utils/parseStringFunction.js +274 -401
- package/dist/react/jsx/utils/parseStringFunction.js.map +1 -0
- package/dist/react/jsx/utils/resolveImportPath.d.ts +1 -1
- package/dist/react/jsx/utils/resolveImportPath.js +125 -108
- package/dist/react/jsx/utils/resolveImportPath.js.map +1 -0
- package/dist/react/jsx/utils/stringParsing/derivation/containsDeriveCall.js +18 -24
- package/dist/react/jsx/utils/stringParsing/derivation/containsDeriveCall.js.map +1 -0
- package/dist/react/jsx/utils/stringParsing/derivation/handleDerivation.js +412 -579
- package/dist/react/jsx/utils/stringParsing/derivation/handleDerivation.js.map +1 -0
- package/dist/react/jsx/utils/stringParsing/derivation/index.js +57 -67
- package/dist/react/jsx/utils/stringParsing/derivation/index.js.map +1 -0
- package/dist/react/jsx/utils/stringParsing/derivation/isDeriveCall.js +26 -36
- package/dist/react/jsx/utils/stringParsing/derivation/isDeriveCall.js.map +1 -0
- package/dist/react/jsx/utils/stringParsing/processTaggedTemplateCall/handleTaggedTemplateTranslationCall.js +29 -24
- package/dist/react/jsx/utils/stringParsing/processTaggedTemplateCall/handleTaggedTemplateTranslationCall.js.map +1 -0
- package/dist/react/jsx/utils/stringParsing/processTaggedTemplateCall/index.js +34 -32
- package/dist/react/jsx/utils/stringParsing/processTaggedTemplateCall/index.js.map +1 -0
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/extractStringEntryMetadata.js +80 -117
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/extractStringEntryMetadata.js.map +1 -0
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleDeriveTranslationCall.js +24 -19
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleDeriveTranslationCall.js.map +1 -0
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleInvalidTranslationCall.js +18 -21
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleInvalidTranslationCall.js.map +1 -0
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleLiteralTranslationCall.js +45 -50
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleLiteralTranslationCall.js.map +1 -0
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/index.js +54 -59
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/index.js.map +1 -0
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/routeTranslationCall.js +56 -69
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/routeTranslationCall.js.map +1 -0
- package/dist/react/jsx/utils/validateStringFunction.js +21 -29
- package/dist/react/jsx/utils/validateStringFunction.js.map +1 -0
- package/dist/react/jsx/wrapJsx.js +192 -375
- package/dist/react/jsx/wrapJsx.js.map +1 -0
- package/dist/react/parse/addVitePlugin/index.js +40 -34
- package/dist/react/parse/addVitePlugin/index.js.map +1 -0
- package/dist/react/parse/addVitePlugin/installCompiler.js +18 -20
- package/dist/react/parse/addVitePlugin/installCompiler.js.map +1 -0
- package/dist/react/parse/addVitePlugin/updateViteConfig.js +107 -111
- package/dist/react/parse/addVitePlugin/updateViteConfig.js.map +1 -0
- package/dist/react/parse/addVitePlugin/utils/addCompilerImport.js +23 -26
- package/dist/react/parse/addVitePlugin/utils/addCompilerImport.js.map +1 -0
- package/dist/react/parse/addVitePlugin/utils/addPluginInvocation.js +29 -43
- package/dist/react/parse/addVitePlugin/utils/addPluginInvocation.js.map +1 -0
- package/dist/react/parse/addVitePlugin/utils/checkCompilerImport.js +70 -104
- package/dist/react/parse/addVitePlugin/utils/checkCompilerImport.js.map +1 -0
- package/dist/react/parse/addVitePlugin/utils/checkPluginInvocation.js +23 -29
- package/dist/react/parse/addVitePlugin/utils/checkPluginInvocation.js.map +1 -0
- package/dist/react/parse/createDictionaryUpdates.js +121 -185
- package/dist/react/parse/createDictionaryUpdates.js.map +1 -0
- package/dist/react/parse/createInlineUpdates.js +123 -139
- package/dist/react/parse/createInlineUpdates.js.map +1 -0
- package/dist/react/parse/wrapContent.js +131 -156
- package/dist/react/parse/wrapContent.js.map +1 -0
- package/dist/react/utils/flattenDictionary.js +55 -70
- package/dist/react/utils/flattenDictionary.js.map +1 -0
- package/dist/react/utils/getEntryAndMetadata.js +14 -10
- package/dist/react/utils/getEntryAndMetadata.js.map +1 -0
- package/dist/react/utils/getVariableName.js +36 -33
- package/dist/react/utils/getVariableName.js.map +1 -0
- package/dist/setup/detectFramework.js +85 -102
- package/dist/setup/detectFramework.js.map +1 -0
- package/dist/setup/frameworkUtils.js +17 -28
- package/dist/setup/frameworkUtils.js.map +1 -0
- package/dist/setup/userInput.js +24 -31
- package/dist/setup/userInput.js.map +1 -0
- package/dist/setup/wizard.js +141 -143
- package/dist/setup/wizard.js.map +1 -0
- package/dist/state/mintlifyRefMap.js +12 -9
- package/dist/state/mintlifyRefMap.js.map +1 -0
- package/dist/state/recentDownloads.js +26 -23
- package/dist/state/recentDownloads.js.map +1 -0
- package/dist/state/translateWarnings.js +17 -8
- package/dist/state/translateWarnings.js.map +1 -0
- package/dist/translation/parse.js +77 -98
- package/dist/translation/parse.js.map +1 -0
- package/dist/translation/stage.js +28 -43
- package/dist/translation/stage.js.map +1 -0
- package/dist/translation/validate.js +68 -91
- package/dist/translation/validate.js.map +1 -0
- package/dist/types/libraries.js +93 -91
- package/dist/types/libraries.js.map +1 -0
- package/dist/types/parsing.js +19 -10
- package/dist/types/parsing.js.map +1 -0
- package/dist/utils/addExplicitAnchorIds.js +270 -389
- package/dist/utils/addExplicitAnchorIds.js.map +1 -0
- package/dist/utils/calculateTimeoutMs.js +11 -6
- package/dist/utils/calculateTimeoutMs.js.map +1 -0
- package/dist/utils/constants.js +15 -12
- package/dist/utils/constants.js.map +1 -0
- package/dist/utils/credentials.js +67 -114
- package/dist/utils/credentials.js.map +1 -0
- package/dist/utils/fetch.js +22 -20
- package/dist/utils/fetch.js.map +1 -0
- package/dist/utils/flattenJsonFiles.js +27 -34
- package/dist/utils/flattenJsonFiles.js.map +1 -0
- package/dist/utils/gitDiff.js +30 -32
- package/dist/utils/gitDiff.js.map +1 -0
- package/dist/utils/gt.js +7 -2
- package/dist/utils/gt.js.map +1 -0
- package/dist/utils/hash.js +14 -9
- package/dist/utils/hash.js.map +1 -0
- package/dist/utils/headers.js +10 -13
- package/dist/utils/headers.js.map +1 -0
- package/dist/utils/installPackage.js +70 -75
- package/dist/utils/installPackage.js.map +1 -0
- package/dist/utils/localizeRelativeAssets.js +114 -157
- package/dist/utils/localizeRelativeAssets.js.map +1 -0
- package/dist/utils/localizeStaticImports.js +229 -371
- package/dist/utils/localizeStaticImports.js.map +1 -0
- package/dist/utils/localizeStaticUrls.js +241 -424
- package/dist/utils/localizeStaticUrls.js.map +1 -0
- package/dist/utils/mintlifyTitleFallback.js +64 -72
- package/dist/utils/mintlifyTitleFallback.js.map +1 -0
- package/dist/utils/monorepoVersionCheck.js +177 -215
- package/dist/utils/monorepoVersionCheck.js.map +1 -0
- package/dist/utils/packageInfo.js +17 -16
- package/dist/utils/packageInfo.js.map +1 -0
- package/dist/utils/packageJson.js +51 -66
- package/dist/utils/packageJson.js.map +1 -0
- package/dist/utils/packageManager.js +237 -260
- package/dist/utils/packageManager.js.map +1 -0
- package/dist/utils/parse/needsCJS.js +36 -69
- package/dist/utils/parse/needsCJS.js.map +1 -0
- package/dist/utils/persistPostprocessHashes.js +30 -32
- package/dist/utils/persistPostprocessHashes.js.map +1 -0
- package/dist/utils/processAnchorIds.js +32 -54
- package/dist/utils/processAnchorIds.js.map +1 -0
- package/dist/utils/processOpenApi.js +469 -578
- package/dist/utils/processOpenApi.js.map +1 -0
- package/dist/utils/resolveMintlifyRefs.js +89 -105
- package/dist/utils/resolveMintlifyRefs.js.map +1 -0
- package/dist/utils/resolvePublish.js +46 -54
- package/dist/utils/resolvePublish.js.map +1 -0
- package/dist/utils/sanitizeFileContent.js +20 -27
- package/dist/utils/sanitizeFileContent.js.map +1 -0
- package/dist/utils/sharedStaticAssets.js +248 -366
- package/dist/utils/sharedStaticAssets.js.map +1 -0
- package/dist/utils/splitMintlifyLanguageRefs.js +208 -282
- package/dist/utils/splitMintlifyLanguageRefs.js.map +1 -0
- package/dist/utils/validateMdx.js +26 -23
- package/dist/utils/validateMdx.js.map +1 -0
- package/dist/utils/wrapPlainUrls.js +58 -70
- package/dist/utils/wrapPlainUrls.js.map +1 -0
- package/dist/workflows/download.js +92 -126
- package/dist/workflows/download.js.map +1 -0
- package/dist/workflows/enqueue.js +47 -54
- package/dist/workflows/enqueue.js.map +1 -0
- package/dist/workflows/publish.js +29 -29
- package/dist/workflows/publish.js.map +1 -0
- package/dist/workflows/setupProject.js +39 -40
- package/dist/workflows/setupProject.js.map +1 -0
- package/dist/workflows/stage.js +61 -65
- package/dist/workflows/stage.js.map +1 -0
- package/dist/workflows/steps/BranchStep.js +118 -163
- package/dist/workflows/steps/BranchStep.js.map +1 -0
- package/dist/workflows/steps/DownloadStep.js +107 -137
- package/dist/workflows/steps/DownloadStep.js.map +1 -0
- package/dist/workflows/steps/EnqueueStep.js +32 -32
- package/dist/workflows/steps/EnqueueStep.js.map +1 -0
- package/dist/workflows/steps/PollJobsStep.js +208 -292
- package/dist/workflows/steps/PollJobsStep.js.map +1 -0
- package/dist/workflows/steps/PublishStep.js +33 -38
- package/dist/workflows/steps/PublishStep.js.map +1 -0
- package/dist/workflows/steps/SetupStep.js +71 -72
- package/dist/workflows/steps/SetupStep.js.map +1 -0
- package/dist/workflows/steps/TagStep.js +39 -44
- package/dist/workflows/steps/TagStep.js.map +1 -0
- package/dist/workflows/steps/UploadSourcesStep.js +108 -140
- package/dist/workflows/steps/UploadSourcesStep.js.map +1 -0
- package/dist/workflows/steps/UploadTranslationsStep.js +61 -71
- package/dist/workflows/steps/UploadTranslationsStep.js.map +1 -0
- package/dist/workflows/steps/UserEditDiffsStep.js +32 -34
- package/dist/workflows/steps/UserEditDiffsStep.js.map +1 -0
- package/dist/workflows/steps/WorkflowStep.js +6 -2
- package/dist/workflows/steps/WorkflowStep.js.map +1 -0
- package/dist/workflows/upload.js +45 -46
- package/dist/workflows/upload.js.map +1 -0
- package/package.json +14 -7
|
@@ -1,416 +1,297 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import { visit } from
|
|
7
|
-
import
|
|
8
|
-
import { escapeHtmlInTextNodes, normalizeCJKCharacters } from
|
|
9
|
-
import { decode } from
|
|
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
|
-
|
|
12
|
-
|
|
12
|
+
* Generates a slug from heading text
|
|
13
|
+
*/
|
|
13
14
|
function generateSlug(text) {
|
|
14
|
-
|
|
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
|
-
|
|
24
|
-
|
|
18
|
+
* Extracts text content from heading nodes
|
|
19
|
+
*/
|
|
25
20
|
function extractHeadingText(heading) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
-
|
|
36
|
-
|
|
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
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
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
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
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
|
-
|
|
93
|
-
|
|
75
|
+
* Checks if a heading is already wrapped in a div with id
|
|
76
|
+
*/
|
|
94
77
|
function hasExplicitId(heading, _ast) {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
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
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
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
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
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
|
-
|
|
200
|
-
|
|
150
|
+
* Adds inline {#id} syntax to headings (standard markdown approach)
|
|
151
|
+
*/
|
|
201
152
|
function applyInlineIds(translatedContent, idMappings, escapeAnchors) {
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
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
|
-
|
|
304
|
-
|
|
214
|
+
* Fallback string-based inline ID application when AST parsing fails
|
|
215
|
+
*/
|
|
305
216
|
function applyInlineIdsStringFallback(translatedContent, idMappings, escapeAnchors) {
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
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
|
-
|
|
356
|
-
|
|
251
|
+
* Wraps headings in divs with IDs (Mintlify approach)
|
|
252
|
+
*/
|
|
357
253
|
function applyDivWrappedIds(translatedContent, translatedHeadings, idMappings) {
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
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
|