Skip to content

Commit 291796c

Browse files
authored
Merge pull request #76 from contentstack/next
Next
2 parents f9a891a + 7bac2ae commit 291796c

File tree

6 files changed

+26
-249
lines changed

6 files changed

+26
-249
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## [1.3.7](https://github.com/contentstack/contentstack-utils-javascript/tree/v1.3.7) (2024-06-18)
4+
- Fix: Cheerio and DOMPurify packages removed
5+
6+
37
## [1.3.6](https://github.com/contentstack/contentstack-utils-javascript/tree/v1.3.6) (2024-05-31)
48
- Fix: handle case of td or th nodes with attr void:true
59

package-lock.json

Lines changed: 4 additions & 186 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@contentstack/utils",
3-
"version": "1.3.6",
3+
"version": "1.3.7",
44
"description": "Contentstack utilities for Javascript",
55
"main": "dist/index.es.js",
66
"types": "dist/types/index.d.ts",
@@ -37,7 +37,6 @@
3737
"@babel/preset-env": "^7.22.20",
3838
"@commitlint/cli": "^17.7.1",
3939
"@commitlint/config-conventional": "^17.7.0",
40-
"@types/dompurify": "^3.0.5",
4140
"@types/jest": "^26.0.24",
4241
"babel-core": "^4.7.16",
4342
"babel-jest": "^29.7.0",
@@ -79,9 +78,5 @@
7978
"presets": [
8079
"es2015"
8180
]
82-
},
83-
"dependencies": {
84-
"cheerio": "^1.0.0-rc.12",
85-
"dompurify": "^3.1.1"
8681
}
8782
}

src/helper/regex-match.ts

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,11 @@
1+
const FigureTagRegex = /<\s*figure[^>]*>([^]*?)<\s*\/\s*figure>/g;
2+
13
export function containsFigureTag(content: string): boolean {
2-
const openingTag = '<figure';
3-
const closingTag = '</figure>';
4-
const openingIndex = content.indexOf(openingTag);
5-
const closingIndex = content.indexOf(closingTag);
6-
return openingIndex !== -1 && closingIndex !== -1 && closingIndex > openingIndex;
4+
return countFigureTags(content) > 0;
75
}
86

9-
export function matchFigureTag(content: string): string[] | null {
10-
const matches: string[] = [];
11-
const openingTag = '<figure';
12-
const closingTag = '</figure>';
13-
let startIndex = content.indexOf(openingTag);
14-
while (startIndex !== -1) {
15-
const endIndex = content.indexOf(closingTag, startIndex);
16-
if (endIndex !== -1 && endIndex > startIndex) {
17-
matches.push(content.substring(startIndex, endIndex + closingTag.length));
18-
startIndex = content.indexOf(openingTag, endIndex + closingTag.length);
19-
} else {
20-
console.error('Malformed figure tag found in content');
21-
break;
22-
}
23-
}
24-
return matches.length > 0 ? matches : null;
7+
export function matchFigureTag(content: string): RegExpMatchArray {
8+
return content.match(FigureTagRegex);
259
}
2610

2711
export function countFigureTags(content: string): number {

0 commit comments

Comments
 (0)