JSPM

  • Created
  • Published
  • Downloads 16
  • Score
    100M100P100Q84875F
  • License MIT

Wraps any content between TR/TD tags in additional rows/columns to appear in browser correctly

Package Exports

  • html-table-patcher

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (html-table-patcher) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

html-table-patcher

Wraps any content between TR/TD tags in additional rows/columns to appear in browser correctly

Minimum Node version required Repository is on BitBucket Coverage View dependencies as 2D chart Downloads/Month Test in browser Code style: prettier MIT License

Table of Contents

Install

npm i html-table-patcher
const patcher = require("html-table-patcher");

var res1 = patcher(`<table width="100%">
  zzz
  <tr>
    <td>
      something
    </td>
  </tr>
</table>`);
console.log("res1 = " + res1);
// res1 = <table width="100%"><tr><td>zzz</td></tr><tr>
//     <td>
//       something
//     </td>
//   </tr>
// </table>

Here's what you'll get:

Type Key in package.json Path Size
Main export - CommonJS version, transpiled to ES5, contains require and module.exports main dist/html-table-patcher.cjs.js 7 KB
ES module build that Webpack/Rollup understands. Untranspiled ES6 code with import/export. module dist/html-table-patcher.esm.js 8 KB
UMD build for browsers, transpiled, minified, containing iife's and has all dependencies baked-in browser dist/html-table-patcher.umd.js 37 KB

⬆ back to top

Idea

Very often, templating languages (or PHP or Email Service Providers' back-end code) is inserted in-between the HTML table tags: between table and tr, between tr and td and so on. If you open such HTML in a browser, that inserted code will appear at wrong places because the browser will try to patch it up (but will do it incorrectly).

This library patches the HTML, so the browser in the correct places renders that code between the table cells.

The patched code is not meant for production by any means - it's for visual display in a browser only!

This library takes string and outputs string, so it's not an end tool, it's rather an API for a feature in other tools and browser plugins.

⬆ back to top

features

  • non-parsing - accepts any HTML, broken, mixed programming languages — anything
  • wraps the code between TABLE and TR tags or between two TR tags with TR+TD

upcoming features

  • colspan/rowspan detection
  • automatic whitespace detection
  • ignoring HTML comments between tags

API

String-in, string-out.

The algorithm

This library does not use any parser. It traverses the input string, makes notes where relevant tags start and end, count the <td>'s per-row and wraps any code between <table> and <tr> with new rows with a correct colspan value. That's why we can aim to support any programming or templating languages embedded within the input HTML.

It should work on any ESP code (from MailChimp to Cheetah to Salesforce Marketing Cloud) or back-end programming language (from Jinja to Nunjucks to Java JSP's).

⬆ back to top

Contributing

  • If you want a new feature in this package or you would like us to change some of its functionality, raise an issue on this repo.

  • If you tried to use this library but it misbehaves, or you need advice setting it up, and its readme doesn't make sense, just document it and raise an issue on this repo.

  • If you would like to add or change some features, just fork it, hack away, and file a pull request. We'll do our best to merge it quickly. Prettier is enabled, so you don't need to worry about the code style.

⬆ back to top

Licence

MIT License (MIT)

Copyright © 2018 Codsen Ltd, Roy Revelt