|
| 1 | +const FigureTagRegex = /<\s*figure[^>]*>([^]*?)<\s*\/\s*figure>/g; |
| 2 | + |
1 | 3 | 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; |
7 | 5 | } |
8 | 6 |
|
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); |
25 | 9 | } |
26 | 10 |
|
27 | 11 | export function countFigureTags(content: string): number { |
|
0 commit comments