Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: escape heading on user message item #4301

Merged
merged 1 commit into from
Dec 19, 2024
Merged

fix: escape heading on user message item #4301

merged 1 commit into from
Dec 19, 2024

Conversation

urmauur
Copy link
Member

@urmauur urmauur commented Dec 19, 2024

Describe Your Changes

The changes in the provided git diff involve two TypeScript files and focus on modifying how markdown text is processed and rendered. Here's a breakdown of what has been changed:

  1. MarkdownTextMessage.tsx:

    • Function Parameter Modification:

      • The MarkdownTextMessage component's props have been modified to include an isUser boolean property alongside the existing id and text properties. This is indicated by the change to the function signature from:
        ({ text }: { id: string; text: string })
        to:
        ({ text, isUser }: { id: string; text: string; isUser: boolean })
    • Markdown Preprocessing:

      • Introduced a new function preprocessMarkdown to modify the markdown text if the isUser flag is true. The function escapes markdown headings by prefixing them with a backslash. This is done using a replace method:
        text.replace(/^#{1,6} /gm, (match) => `\\${match}`)
      • Condition: The preprocessing only occurs if the isUser prop is true.
    • Markdown Component Usage:

      • The markdown content now uses the preprocessed markdown text:
        {preprocessMarkdown(text)}
      • Replacing the previous direct usage of text:
        {text}
  2. index.tsx:

    • Props Update in Component Usage:
      • Updated the MarkdownTextMessage component instantiation to include the isUser prop:
        <MarkdownTextMessage
          id={props.id}
          text={text}
          isUser={isUser}
        />
      • Previously, it was:
        <MarkdownTextMessage id={props.id} text={text} />

In summary, these changes introduce a conditional preprocessing of markdown messages based on the user context (isUser), specifically to escape headings in markdown content originating from users.

Fixes Issues

CleanShot 2024-12-19 at 21 33 56

CleanShot 2024-12-19 at 21 33 53

  • Closes #
  • Closes #

Self Checklist

  • Added relevant comments, esp in complex areas
  • Updated docs (for bug fixes / features)
  • Created issues for follow-up changes or refactoring needed

@github-actions github-actions bot added the type: bug Something isn't working label Dec 19, 2024
Copy link
Contributor

Barecheck - Code coverage report

Total: 69.04%

Your code coverage diff: -0.03% ▾

Uncovered files and lines
FileLines
web/screens/Thread/ThreadCenterPanel/TextMessage/MarkdownTextMessage.tsx23, 27-28, 32, 40-43, 45, 49, 56-58, 64, 67-69, 71, 76-77, 80, 130, 132-133, 138-139, 198
web/screens/Thread/ThreadCenterPanel/TextMessage/index.tsx31-36, 38, 40, 44, 46, 50

Copy link
Contributor

This is the build for this pull request. You can download it from the Artifacts section here: Build URL.

@urmauur urmauur merged commit 7140978 into dev Dec 19, 2024
21 checks passed
@urmauur urmauur deleted the fix/escape-heading branch December 19, 2024 15:38
@github-actions github-actions bot added this to the v0.5.12 milestone Dec 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants