Skip to content

Commit a4d4129

Browse files
authored
fix: regex to match child content on block tags (#433)
* fix: regex to match child content on block tags * fix: comment review
1 parent 441ba6f commit a4d4129

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

src/blocks/Header/Header.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,21 +121,21 @@ export const HeaderBlock = (props: WithChildren<HeaderBlockFullProps>) => {
121121
>
122122
<Col sizes={titleSizes} className={b('content-inner')}>
123123
{overtitle && (
124-
<div className={b('overtitle')}>
124+
<p className={b('overtitle')}>
125125
<HTML>{overtitle}</HTML>
126-
</div>
126+
</p>
127127
)}
128128
<h1 className={b('title')}>
129129
{status}
130130
<HTML>{title}</HTML>
131131
</h1>
132132
{description && (
133-
<div className={b('description')}>
133+
<p className={b('description')}>
134134
<YFMWrapper
135135
content={description}
136136
modifiers={{constructor: true}}
137137
/>
138-
</div>
138+
</p>
139139
)}
140140
{buttons && (
141141
<div className={b('buttons')} data-qa="header-buttons">

src/utils/blocks.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ const BLOCK_ELEMENTS = [
3838
'td',
3939
];
4040

41+
const BLOCK_ELEMENTS_REGEX = `<(${BLOCK_ELEMENTS.join('|')})[^>]*>`;
42+
4143
export function getHeaderTag(size: TextSize) {
4244
switch (size) {
4345
case 'l':
@@ -53,10 +55,8 @@ export function getHeaderTag(size: TextSize) {
5355
}
5456

5557
export function hasBlockTag(content: string): boolean {
56-
const blockElementRegex = `/<(${BLOCK_ELEMENTS.join('|')})\b[^>]*>/gi`;
57-
const blockTags = content.match(blockElementRegex);
58-
59-
return Boolean(blockTags);
58+
const regex = new RegExp(BLOCK_ELEMENTS_REGEX, 'g');
59+
return regex.test(content);
6060
}
6161

6262
export function getBlockKey(block: ConstructorBlock, index: number) {

0 commit comments

Comments
 (0)