MCPcopy Create free account
hub / github.com/Noumena-Network/code / loadNativeRenderer

Function loadNativeRenderer

src/utils/markdown/nativeFencedCodeRenderer.ts:156–207  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

154}
155
156function loadNativeRenderer(): NativeFencedCodeRendererFn | null {
157 if (cachedRendererFn !== undefined) {
158 return cachedRendererFn
159 }
160 // The current native fence path is still an experimental performance seam.
161 // Until it preserves the existing highlighted ANSI semantics, keep it
162 // opt-in so normal markdown/code-fence rendering stays behavior-compatible.
163 if (
164 !NATIVE_FENCED_CODE_ENV_KEYS.some(key =>
165 isEnvTruthy(process.env[key]),
166 )
167 ) {
168 cachedRendererFn = null
169 return null
170 }
171 debugState.loadAttempts += 1
172 const requireFn = getRequireFunction()
173 if (!requireFn) {
174 cachedRendererFn = null
175 return null
176 }
177 const moduleIds = [
178 ...(isInBundledMode() ? [BUNDLED_MODULE_ID] : []),
179 ...getNativeRendererModuleIds(),
180 ]
181 debugState.moduleIds = [...moduleIds]
182 debugState.resolvedModuleId = null
183 const loadFailures: NativeRendererLoadFailure[] = []
184 for (const moduleId of moduleIds) {
185 try {
186 const imported = requireFn(moduleId)
187 const rendererFn = resolveRendererFunction(imported)
188 if (rendererFn) {
189 cachedRendererFn = rendererFn
190 debugState.loadSuccesses += 1
191 debugState.resolvedModuleId = moduleId
192 debugState.lastLoadFailures = loadFailures
193 return rendererFn
194 }
195 } catch {
196 // Fail-open by trying the next candidate module id.
197 loadFailures.push({
198 moduleId,
199 message: 'require_failed',
200 })
201 }
202 }
203 debugState.loadFailures += 1
204 debugState.lastLoadFailures = loadFailures
205 cachedRendererFn = null
206 return null
207}
208
209function isStringArray(value: unknown): value is NativeFencedCodeRendererLines {
210 return (

Callers 1

renderNativeFencedCodeFunction · 0.85

Calls 5

isEnvTruthyFunction · 0.90
getRequireFunctionFunction · 0.85
isInBundledModeFunction · 0.85
resolveRendererFunctionFunction · 0.85

Tested by

no test coverage detected