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

use innerText to escape htmlString when showRawCode is on #27

Closed
wants to merge 0 commits into from
Closed

use innerText to escape htmlString when showRawCode is on #27

wants to merge 0 commits into from

Conversation

CNSeniorious000
Copy link
Contributor

Description

fix #26

Linked Issues

fix #26

Additional context

I have to add a getClass() function to retain reactivity:

export default (props: Props) => {
  const htmlString = () => props.showRawCode ? props.text : parseMarkdown(props.text)
+ const getClass = () => `${props.class ?? ''} ${props.showRawCode ? 'whitespace-pre-wrap overflow-auto my-0' : ''}`

  return props.showRawCode
    ? <div class={getClass()} innerText={htmlString()} />
    : <div class={getClass()} innerHTML={htmlString()} />
}

or I have to write it twice, which is more repetitive:

export default (props: Props) => {
  const htmlString = () => props.showRawCode ? props.text : parseMarkdown(props.text)

  return (
    props.showRawCode
      ? <div
          class={`${props.class ?? ''} ${props.showRawCode ? 'whitespace-pre-wrap overflow-auto my-0' : ''}`}
          innerText={htmlString()}
        />
      : <div
          class={`${props.class ?? ''} ${props.showRawCode ? 'whitespace-pre-wrap overflow-auto my-0' : ''}`}
          innerHTML={htmlString()}
        />
  )
}

I wonder if there is a way to implement it more elegantly.

@netlify
Copy link

netlify bot commented May 15, 2023

Deploy Preview for chatgpt-demo-v2 ready!

Name Link
🔨 Latest commit bb59cdc
🔍 Latest deploy log https://app.netlify.com/sites/chatgpt-demo-v2/deploys/6462868cab607a0008574db6
😎 Deploy Preview https://deploy-preview-27--chatgpt-demo-v2.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Display unescaped HTML code when showRawCode is true.
1 participant