npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

html-to-table

v0.1.4

Published

Convert HTML to Email Compatible Layout

Downloads

4

Readme

HTML To Email-Compatible Table

cover

DEMO: https://w99910.github.io/html-to-table/

It's zero dependency and light-weight.

I have been trying to send emails using html layout but there are lots of html elements and styles that email clients don't support.

So I am working on this library to convert almost html layout to email-compatible table layout.

Note: I don't guarantee that this library can convert any html element to your desired layout all the time. Feel free to tune the result as you want.

Installation

Choose one of the following methods.

  • NPM
npm i html-to-table
  • Github ESM Module
import HTML2Table from 'https://github.com/w99910/html-to-table/blob/master/dist/html-to-table.js'
  • Github CJS
const HTML2Table = require('https://github.com/w99910/html-to-table/blob/master/dist/html-to-table.cjs')

Usage

It is pretty straight-forward to use.

  • Initialise the class
let html2table = new HTML2Table();
  • (Optional) - You can filter the elements you don't want to include in the output using Regex Expression This checks the class name and id.
html2table.excludeElementByPattern('toolbar')
  • Convert the element you want by calling convert and passing the element as parameter.
html2table.convert(document.querySelector('your-element-to-convert'));

Tips

  • I suggest you target mobile device layout first so that the layout will work both on mobile and desktop.
  • Base64 image data does not work. So host the image on cloud and use it.
  • Don't use linear-gradient css function in inline css. Instead, create the gradient as an image and load it using url.
    style="background: url('link-to-your-image')"
  • Use background-color as a fall-back background color if image would not be working in some email clients.
  • Skip using height property if possible since it can prevent uninteneded padding or margin.

To-DO

  • [ ] Converting rem doesn't render exactly as it is.
  • [x] even if only border-top is provided, all border is being rendered.
  • [x] Change the logic for v-align as it is giving unnecessary vertical space.

LICENSE

MIT License

Articles

CHANGELOG

  • 0.1.4
    • Drop setting height css property for the parent.
    • Remove v-align in the output. Please tweak the output as you want.
    • Height property is converted to auto for child nodes unless you unexplictly set it as inlined css.
    • Append the bounding rect width as the width style when tranversing the child nodes.
    • Consider the styles of the embedding classes before get the window's computed styles.
  • 0.1.2
    • Add bgcolor attribute for fall-back background css style.
    • align and valign of table now consider the css properties of parent element. if there is no parent element, default value will be used.
    • Deprecated feature that convert SVG to Base64 PNG.
  • 0.1.1
    • Add alt and title to allowed attribute when it is cloned.
    • Fix width being 0 in some cases.
  • 0.1.0 - Rewrite the logic by using bounding client rect to determine the layout