Skip to content

Commit 451e48e

Browse files
committed
Refactoring code
1 parent a54c03b commit 451e48e

File tree

1 file changed

+8
-4
lines changed
  • packages/core/src/codewhispererChat/controllers/chat/messenger

1 file changed

+8
-4
lines changed

packages/core/src/codewhispererChat/controllers/chat/messenger/messenger.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import { FeatureAuthState } from '../../../../codewhisperer/util/authUtil'
3131
import { AuthFollowUpType, expiredText, enableQText, reauthenticateText } from '../../../../amazonq/auth/model'
3232
import { userGuideURL } from '../../../../amazonq/webview/ui/texts/constants'
3333
import { marked } from 'marked'
34+
import { JSDOM } from 'jsdom'
3435

3536
export type StaticTextResponseType = 'quick-action-help' | 'onboarding-help' | 'transform' | 'help'
3637

@@ -95,13 +96,16 @@ export class Messenger {
9596
return 0
9697
}
9798

98-
// To Convert Markdown text to HTML using marked library
99+
// // To Convert Markdown text to HTML using marked library
99100
const html = await marked(message)
100101

101-
// Count the number of <pre> tags in the HTML to find the total number of code blocks
102-
const totalNumberOfCodeBlocks = (html.match(/<pre>/g) || []).length
102+
const dom = new JSDOM(html)
103+
const document = dom.window.document
103104

104-
return totalNumberOfCodeBlocks
105+
// Search for <pre> elements containing <code> elements
106+
const codeBlocks = document.querySelectorAll('pre > code')
107+
108+
return codeBlocks.length
105109
}
106110

107111
public async sendAIResponse(

0 commit comments

Comments
 (0)