How to use the cheerio.html function in cheerio

To help you get started, we’ve selected a few cheerio 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 foundation / inky / lib / renderer.js View on Github external
return element => {
    // Get the tag name and find the corresponding component
    const tagName = element[0].name;
    const Component = library.get(tagName);

    // If no component exists for this tag, return the HTML wrapped in a table row
    if (!Component) {
      return `${$.html(element, opts.cheerio)}`;
    }

    const props = {
      children: () => element.html()
    };
    const attributes = element.attr();
    const restAttrs = [];

    if (Component.props) {
      Object.keys(Component.props).forEach(key => {
        props[key] = Component.props[key];
      });
    }

    // Find attributes on the input HTML that matches defined component props
    // Other attributes are collected in a string called `props.rest`
github ethantw / hanio / src / locale / ruby.js View on Github external
export const createZhuyinRu = ( $$rb, $rt ) => {
  // - 
  // -   
  // -   
  // -     
  // -     
  // -   
  // - 
  const html = (
    `${
      $.html( $$rb ) +
      getZhuyinHTML( $rt )
    }`
  )
  return $( html )
}
github artsy / reaction / src / DevTools / __tests__ / MockRelayRendererFixtures.tsx View on Github external
export function renderToString(element: JSX.Element) {
  return cheerio.html(render(element))
}
github ethantw / hanio / src / fn / dom.js View on Github external
if ( !parent || !Array.isArray( parent.children )) {
      return
    }

    const idxBefore = parent.children.indexOf( this )
    const idxAfter  = idxBefore + content.contents().length

    this::dom.replaceWith(
      `${
        $.html( content ) +
        $.html( this )
      }`
    )

    parent.children = Array.from($(
      $.html( parent ).replace( /<\/?hanio\-fake>/gi, '' )
    ).contents())

    return parent.children[ idxAfter ]
  },
github ladjs / custom-fonts-in-emails / src / index.js View on Github external
return customFontsCache[hash];
  }

  const textToSvg = await load(options.fontPath);
  const str = textToSvg.getSVG(options.text, options.textToSvg);
  let $svg = $(str);
  const $rect = $('
github ethantw / hanio / src / locale / ruby.js View on Github external
$$rb.map( $rb => {
        if ( !$rb )  return ''
        return $.html( $rb )
      }).join( '' ) + $.html( $rt )
    )
github ethantw / hanio / src / fn / dom.js View on Github external
  html()   {  return $.html( this )  },
  isElmt() {  return this::dom.prop( 'type' ) === 'tag'  },
github dynatrace-oss / barista / tools / barista / src / builder / icons.ts View on Github external
function getSvgWithoutFill(filePath: string): string {
  const iconSvg = readFileSync(filePath, { encoding: 'utf-8' });
  const cheerioIcon = loadWithCheerio(iconSvg);
  const svg = cheerioIcon('svg');
  svg.removeAttr('fill');
  svg.children().removeAttr('fill');
  return html(svg) || '';
}
github octokit / routes / lib / endpoint / tags / ul.js View on Github external
parse(el) {
    return {
      type: "description",
      text: turndown(cheerio.html(el))
    };
  }
};
github ladjs / custom-fonts-in-emails / src / index.js View on Github external
$img.attr('width', $svg.attr('width'));
  $img.attr('height', $svg.attr('height'));
  $img.attr(
    'src',
    `data:image/svg+xml;base64,${Buffer.from(str, 'utf8').toString('base64')}`
  );
  if (options.supportsFallback)
    options.attrs = renderFallback(
      options.text,
      $svg.attr('height'),
      options.fontColor,
      options.backgroundColor,
      options.attrs
    );
  $img = applyAttributes($img, options.attrs);
  const result = $.html($img);
  customFontsCache[hash] = result;
  debug(`caching result for ${hash}`, result);
  return result;
}