INNER CODE UNIT · TypeScript

h2Regex

philschmid/clipper.js · src/clipper.ts:89

    const h2Regex = /<h2[^>]*>(.*?)<\/h2>/;
    const match = article.content.match(h2Regex);
    if (match?.[0].includes(article.title)) {
      // replace fist h2 with h1
      article.content = article.content.replace("<h2", "<h1").replace("</h2", "</h1")
    } else {
      // add title as h1
      article.content = `<h1>${article.title}</h1>\n${article.content}`
    }
  }
  // contert to markdown
  let res = turndownService.turndown(article.content);

  // replace weird header refs
  const pattern = /\[\]\(#[^)]*\)/g;
  res = res.replace(pattern, '')
  return res
}

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…