JSPM

  • Created
  • Published
  • Downloads 4
  • Score
    100M100P100Q84948F
  • 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 38 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 see an error, raise an issue.
  • If you want a new feature but can't code it up yourself, also raise an issue. Let's discuss it.
  • If you tried to use this package, but something didn't work out, also raise an issue. We'll try to help.
  • If you want to contribute some code, fork the monorepo via BitBucket, then write code, then file a pull request via BitBucket. We'll merge it in and release.

In monorepo, npm libraries are located in packages/ folder. Inside, the source code is located either in src/ folder (normal npm library) or in the root, cli.js (if it's a command line application).

The npm script "dev", the "dev": "rollup -c --dev --silent" builds the development version retaining all console.logs with row numbers. It's handy to have js-row-num-cli installed globally so you can automatically update the row numbers on all console.logs.

⬆ back to top

Licence

MIT License

Copyright (c) 2015-2019 Roy Revelt and other contributors