Skip to content

Conversation

@shaohuzhang1
Copy link
Contributor

fix: When voice playback is turned on, if the answer contains a link, there will be the following abnormal message

… there will be the following abnormal message
@f2c-ci-robot
Copy link

f2c-ci-robot bot commented Dec 10, 2025

Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@f2c-ci-robot
Copy link

f2c-ci-robot bot commented Dec 10, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

.replace(/<[^>]+>/g, '')
// 移除多余的换行符
.replace(/\n{2,}/g, '\n')
.trim()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your Markdown-to-plain text conversion function is generally well-written and efficient. However, there are a few things you can consider for optimization or improvement:

  1. Code Block Handling: The current code block removal logic should still work effectively, but it might be better to add comments explaining why this part of the regular expression works.

  2. HTML Tag Removal: The HTML tag removal regex /<[^>]+>/g will match all tags correctly, but since HTML is typically not used in Markdown (other than embedded URLs), if no HTML is expected in your input, you could optimize slightly by removing only non-whitespace characters inside <. This could prevent unexpected matches on some erroneous input patterns like <script>alert('XSS')</script>.

  3. Newline Optimization: While trimming excessive newlines with \n{2,} isn't necessary as long as the newline count is at least two after each other, it doesn't harm anything either.

  4. Comments:

    • Add comments above the .replace(/```[\s\S]*?```/g, '') line explaining that it removes multi-line code blocks.
    • Consider adding comments around the .replace(/<(?:[^"'>]|"[^"]*"|'[^']*')*>/g, '') line explaining its purpose.

Here's an updated version with these suggestions:

function markdownToPlainText(md: string) {
  return md
    .replace(/`(.*?)`/g, '$1')          // Remove inline code backticks
    .replace(/```[\s\S]*?```/g, '')     // Remove code blocks (multi-line)
    .replace(/<(?:[^"'>]|"[^"]*"|'[^']*')*>/g, '')  // Remove specific style attributes from HTML tags
    .trim();
}

This improved version maintains the functionality while being more explicit about what each replace operation does.

@shaohuzhang1 shaohuzhang1 merged commit cb977a7 into v2 Dec 10, 2025
3 of 5 checks passed
@shaohuzhang1 shaohuzhang1 deleted the pr@v2@fix_workflow branch December 10, 2025 08:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants