INNER CODE UNIT · TypeScript

extract_from_dom

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

function extract_from_dom(dom: JSDOM) {
  let article = new Readability(dom.window.document, {
    keepClasses: true,
    debug: false,
    charThreshold: 100,
  }).parse();

  if (!article) {
    throw new Error("Failed to parse article");
  }
  // remove HTML comments
  article.content = article.content.replace(/(\<!--.*?\-->)/g, "");

  // Try to add proper h1 if title is missing
  if (article.title.length > 0) {

    // check if first h2 is the same as title
    const h2Regex = /<h2[^>]*>(.*?)<\/h2>/;

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…