INNER CODE UNIT · JavaScript

inlineImg

danmindru/responsive-html-email-signature · tasks/check-for-image-url.js:18

function inlineImg(options = {}) {
  const selector = options.selector || 'img[src]';
  const attribute = options.attribute || 'src';
  const getHTTP = options.getHTTP || false;

  return through.obj(function(file, encoding, callback) {
    if (file.isStream()) {
      this.emit('error', new PluginError(PLUGIN_NAME, 'Streams are not supported!'));
      return callback();
    }

    if (file.isBuffer()) {
      const contents = file.contents.toString(encoding);
      // Load it into cheerio's virtual DOM for easy manipulation
      const $ = cheerio.load(contents);
      const inlineFlag = $(`img[${INLINE_ATTR}]`);
      // If images with an inline attr are found that is the selection we want
      const imgTags = inlineFlag.length ? inlineFlag : $(selector);

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…