Skip to content
Draft
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
11 changes: 8 additions & 3 deletions netlify/edge-functions/markdown-negotiation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const NOISE_SELECTORS = [
"style",
"noscript",
"template",
"svg",
"header",
"footer",
"nav",
Expand Down Expand Up @@ -127,8 +126,7 @@ function htmlToMarkdownFallback(html: string, baseUrl: URL): string {
.replace(/<!--[\s\S]*?-->/g, "")
.replace(/<script\b[^>]*>[\s\S]*?<\/script>/gi, "")
.replace(/<style\b[^>]*>[\s\S]*?<\/style>/gi, "")
.replace(/<noscript\b[^>]*>[\s\S]*?<\/noscript>/gi, "")
.replace(/<svg\b[^>]*>[\s\S]*?<\/svg>/gi, "");
.replace(/<noscript\b[^>]*>[\s\S]*?<\/noscript>/gi, "");

const titleMatch = sanitized.match(/<title\b[^>]*>([\s\S]*?)<\/title>/i);
const title = titleMatch ? normalizeWhitespace(decodeHtmlEntities(stripTags(titleMatch[1]))) : "";
Expand Down Expand Up @@ -469,11 +467,13 @@ function selectContentRoot(doc: { querySelector: (selector: string) => any; body
const preferredSelectors = [
"#main article",
"main article",
".main article",
"article.guide",
"article",
"#main",
"[role='main']",
"main",
".main",
"body",
];

Expand All @@ -496,6 +496,11 @@ function extractPrimaryHtmlFragment(html: string): string {
return mainHtml;
}

const guideArticleMatch = html.match(/<article\b[^>]*class=("')[^"']*\bguide\b[^"']*\1[^>]*>([\s\S]*?)<\/article>/i);
if (guideArticleMatch) {
return guideArticleMatch[2];
}

const articleMatch = html.match(/<article\b[^>]*>([\s\S]*?)<\/article>/i);
if (articleMatch) {
return articleMatch[1];
Expand Down