Skip to content

Commit

Permalink
Refactoring code
Browse files Browse the repository at this point in the history
  • Loading branch information
laileni-aws committed Apr 22, 2024
1 parent a54c03b commit 451e48e
Showing 1 changed file with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { FeatureAuthState } from '../../../../codewhisperer/util/authUtil'
import { AuthFollowUpType, expiredText, enableQText, reauthenticateText } from '../../../../amazonq/auth/model'
import { userGuideURL } from '../../../../amazonq/webview/ui/texts/constants'
import { marked } from 'marked'
import { JSDOM } from 'jsdom'

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

Expand Down Expand Up @@ -95,13 +96,16 @@ export class Messenger {
return 0
}

// To Convert Markdown text to HTML using marked library
// // To Convert Markdown text to HTML using marked library
const html = await marked(message)

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

return totalNumberOfCodeBlocks
// Search for <pre> elements containing <code> elements
const codeBlocks = document.querySelectorAll('pre > code')

return codeBlocks.length
}

public async sendAIResponse(
Expand Down

0 comments on commit 451e48e

Please sign in to comment.