Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/helpers/detect-markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function stripCode(text: string): string {
* from markdown that mentions HTML tags in code examples.
*/
export function looksLikeHtml(body: string): boolean {
const sample = stripCode(body.slice(0, 2000));
const sample = stripCode(body).slice(0, 2000);
return HTML_PATTERNS.some((p) => p.test(sample));
}

Expand Down
6 changes: 6 additions & 0 deletions test/unit/helpers/detect-markdown.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ describe('looksLikeHtml', () => {
expect(looksLikeHtml(md)).toBe(false);
});

it('ignores HTML in code blocks longer than 2000 characters', () => {
const md =
'# Setup\n\n```html\n<html>\n<body>\n' + 'x'.repeat(3000) + '\n</body>\n</html>\n```\n';
expect(looksLikeHtml(md)).toBe(false);
});

it('still detects real HTML outside of code blocks', () => {
const html = '<!DOCTYPE html>\n<html>\n```not a code block\n```\n</html>';
expect(looksLikeHtml(html)).toBe(true);
Expand Down