Installation
Quick Take
Examples
- Add inline CSS to inserted table cells
- Center every inserted table cell
- Leave table-like markup inside an HTML comment untouched
- Span inserted table cells across the existing columns
- Move loose row text into its own cell and row
Idea
ESP template tags (anything, from Mailchimp to Salesforce) or templating languages (like Nunjucks), when previewed in browser, appear at wrong places. It’s because templating tags are often placed between table, tr or td tags.
This program patches table structures, so you can visually check them easier:

API — patcher()
The main function patcher() is imported like this:
It’s a function which takes two input arguments:
| Input argument | Type | Obligatory | Description |
|---|---|---|---|
strType: String Obligatory: yes | |||
str | String | yes | HTML source code. |
optsType: Plain object Obligatory: no | |||
opts | Plain object | no | An Optional Options Object. |
The optional options object has the following shape:
| Key | Value’s type | Default value | Description |
|---|---|---|---|
cssStylesContent | |||
cssStylesContent | string | "" (empty string) | Whatever you put here, will end up on every newly-added TD’s inline style tag’s value |
alwaysCenter | |||
alwaysCenter | boolean | false | Every newly-added TD should have its contents centered (via an inline align="center" HTML attribute) |
Here are all defaults in one place for copying:
Function returns a plain object:
| Key’s name | Type | Description |
|---|---|---|
resultType: String | ||
result | String | Result string containing patched code |
API — defaults
You can import defaults:
It's a plain object:
The main function calculates the options to be used by merging the options you passed with these defaults.
API — version
You can import version:
API — types
This package is written in TypeScript and exports the following types:
| Type | Description |
|---|---|
ObjType: Obj | |
Obj | A plain object with string keys and values of any type. |
OptsType: Opts | |
Opts | The Optional Options Object of patcher(), documented above. |
ResType: Res | |
Res | What patcher() returns — a single result key. |
import type { Obj, Opts, Res } from "html-table-patcher";
The algorithm
The program parses using codsen-parser, then traverses using ast-monkey-traverse-with-lookahead and record what needs to be amended using ranges-push and finally, apply all changes in one go using ranges-apply.