Skip to content

Commit

Permalink
fix(Intro): description check for HTML (#727)
Browse files Browse the repository at this point in the history
* fix: intro description check for HTML

* chore: add changeset
  • Loading branch information
alexcarpenter authored Sep 28, 2022
1 parent 802a596 commit eff7596
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/rare-plums-crash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@hashicorp/react-intro': patch
---

Use regex to detect HTML in the description
4 changes: 3 additions & 1 deletion packages/intro/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import type { IntroProps } from './types'
import Actions from '@hashicorp/react-actions'
import s from './style.module.css'

const containsHTML = (str: string) => /<[a-z][\s\S]*>/i.test(str)

export default function Intro({
appearance = 'light',
textAlignment = 'left',
Expand All @@ -29,7 +31,7 @@ export default function Intro({
<HeadingElement className={classNames(s.heading, headingSizeClassname)}>
{heading}
</HeadingElement>
{description.includes('<p>') ? (
{containsHTML(description) ? (
<div
dangerouslySetInnerHTML={{
__html: description,
Expand Down

1 comment on commit eff7596

@vercel
Copy link

@vercel vercel bot commented on eff7596 Sep 28, 2022

Choose a reason for hiding this comment

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

Please sign in to comment.