How to use the @postlight/mercury-parser.addExtractor function in @postlight/mercury-parser

To help you get started, we’ve selected a few @postlight/mercury-parser examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github albertincx / formatbot1 / src / api / utils / ivMaker.js View on Github external
const parse = async (userUrl, paramsObj) => {
  const parseHelper = new ParseHelper(userUrl, paramsObj);
  userUrl = parseHelper.link;
  const opts = {};
  if (parseHelper.custom) {
    const html = await parseHelper.fetchHtml();
    logger(html, 'fixedFetched.html');
    opts.html = Buffer.from(html);
  }
  const extractor = parseHelper.getExtractor();
  if (extractor) {
    logger(extractor);
    Mercury.addExtractor(extractor);
  }
  let result = await mercury(userUrl, opts);
  logger(result.content, 'mercury.html');
  let { content } = result;
  const preContent = sanitizeHtml(content).trim();
  logger(preContent, 'preContent.html');
  if (preContent.length === 0) {
    const html = await parseHelper.puppet(userUrl);
    if (html) {
      logger(html, 'asyncContent.html');
      result = await mercury(userUrl, { html: Buffer.from(html) });
      logger(result.content, 'mercuryAsyncContent.html');
    }
  }
  let { title = '', url: source, iframe } = result;
  logger(iframe, 'iframes.html');

@postlight/mercury-parser

Mercury transforms web pages into clean text. Publishers and programmers use it to make the web make sense, and readers use it to read any web article comfortably.

Apache-2.0
Latest version published 3 years ago

Package Health Score

56 / 100
Full package analysis