Skip to Content
  • Website
Codsen
  • Home
  • Open Source
  • Articles
  • About

prevOpen Source→html-table-patchernext

html-table-patcher6.2.1

Visual helper to place templating code around table tags into correct places

Downloads per monthChangelogMIT Licenselibera manifesto
  • the top
  • Installation
  • Quick Take
  • Examples
  • IDEA
  • API — PATCHER()
  • API — DEFAULTS
  • API — VERSION
  • API — TYPES
  • THE ALGORITH…
  • Changelog

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:

patching HTML tables
patching HTML tables

API — patcher()

The main function patcher() is imported like this:

It’s a function which takes two input arguments:

Input argumentTypeObligatoryDescription
str
Type: String
Obligatory: yes
strStringyesHTML source code.
opts
Type: Plain object
Obligatory: no
optsPlain objectnoAn Optional Options Object.

The optional options object has the following shape:

KeyValue’s typeDefault valueDescription
cssStylesContent
cssStylesContentstring"" (empty string)Whatever you put here, will end up on every newly-added TD’s inline style tag’s value
alwaysCenter
alwaysCenterbooleanfalseEvery 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 nameTypeDescription
result
Type: String
resultStringResult 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:

TypeDescription
Obj
Type: Obj
ObjA plain object with string keys and values of any type.
Opts
Type: Opts
OptsThe Optional Options Object of patcher(), documented above.
Res
Type: Res
ResWhat 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.

Changelog

Open Changelog
↑ back to top
prev next

Copyright

All rights reserved © Roy Revelt 2026
All our open source packages are under MIT licenceopens in a new tab

Activities

🐛 See a bug? Raise an issueopens in a new tab
💘 Check out the Indiewebopens in a new tab and Libera manifestoopens in a new tab