MCPcopy Index your code
hub / github.com/codeaashu/claude-code / stripHtmlCommentsFromTokens

Function stripHtmlCommentsFromTokens

src/utils/claudemd.ts:303–334  ·  view source on GitHub ↗
(tokens: ReturnType<Lexer['lex']>)

Source from the content-addressed store, hash-verified

301}
302
303function stripHtmlCommentsFromTokens(tokens: ReturnType<Lexer['lex']>): {
304 content: string
305 stripped: boolean
306} {
307 let result = ''
308 let stripped = false
309
310 // A well-formed HTML comment span. Non-greedy so multiple comments on the
311 // same line are matched independently; [\s\S] to span newlines.
312 const commentSpan = /<!--[\s\S]*?-->/g
313
314 for (const token of tokens) {
315 if (token.type === 'html') {
316 const trimmed = token.raw.trimStart()
317 if (trimmed.startsWith('<!--') && trimmed.includes('-->')) {
318 // Per CommonMark, a type-2 HTML block ends at the *line* containing
319 // `-->`, so text after `-->` on that line is part of this token.
320 // Strip only the comment spans and keep any residual content.
321 const residue = token.raw.replace(commentSpan, '')
322 stripped = true
323 if (residue.trim().length > 0) {
324 // Residual content exists (e.g. `<!-- note --> Use bun`): keep it.
325 result += residue
326 }
327 continue
328 }
329 }
330 result += token.raw
331 }
332
333 return { content: result, stripped }
334}
335
336/**
337 * Parses raw memory file content into a MemoryFileInfo. Pure function — no I/O.

Callers 2

stripHtmlCommentsFunction · 0.85
parseMemoryFileContentFunction · 0.85

Calls 1

trimStartMethod · 0.80

Tested by

no test coverage detected