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 🙏

© 2026 – Pkg Stats / Ryan Hefner

rehype-table-align

v1.1.0

Published

rehype plugin to handle Markdown table alignment issues by converting align attributes to CSS styles

Downloads

213

Readme

rehype-table-align

npm version CI Status codecov License: MIT TypeScript

rehype-table-align is a rehype plugin that handles Markdown table text alignment issues by converting deprecated HTML5 align attributes to inline CSS style properties (e.g., text-align: center;).

Why this plugin?

In standard table generation (often paired with remark-gfm), alignment properties mapped from Markdown tables | :--- | :---: | ---: | generate align attributes on <th> and <td> elements:

<th align="center">Title</th>

However, the align attribute on table elements is officially deprecated in HTML5. This plugin ensures your html is compliant with modern web standards by transforming these into inline CSS correctly, whilst intelligently managing and appending to any existing styles:

<th style="text-align: center;">Title</th>

Installation

You can install this package using npm, pnpm, or yarn.

npm

npm install rehype-table-align

pnpm

pnpm add rehype-table-align

yarn

yarn add rehype-table-align

Usage

Here is a common unified processing pipeline using remark-parse, remark-gfm, remark-rehype, rehype-table-align, and rehype-stringify:

import { unified } from "unified"
import remarkParse from "remark-parse"
import remarkGfm from "remark-gfm"
import remarkRehype from "remark-rehype"
import rehypeTableAlign from "rehype-table-align"
import rehypeStringify from "rehype-stringify"

const processor = unified()
  .use(remarkParse)
  .use(remarkGfm)        // Supports markdown tables
  .use(remarkRehype)     // Converts Markdown AST to HTML AST
  .use(rehypeTableAlign) // Converts align attributes to styles
  .use(rehypeStringify)

const markdown = `
| Default | Left | Center | Right |
| ------- | :--- | :----: | ----: |
| 1       | 2    | 3      | 4     |
`

const file = await processor.process(markdown)
console.log(String(file))

Yields:

<table>
  <thead>
    <tr>
      <th>Default</th>
      <th style="text-align: left;">Left</th>
      <th style="text-align: center;">Center</th>
      <th style="text-align: right;">Right</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>1</td>
      <td style="text-align: left;">2</td>
      <td style="text-align: center;">3</td>
      <td style="text-align: right;">4</td>
    </tr>
  </tbody>
</table>

Options

rehype-table-align accepts an optional configuration object to customize its behavior.

import rehypeTableAlign, { type RehypeTableAlignOptions } from "rehype-table-align"

const options: RehypeTableAlignOptions = {
  method: "class",         // 'style' (default) or 'class'
  classes: {
    left: "text-left",     // default: 'left'
    center: "text-center", // default: 'center'
    right: "text-right",   // default: 'right'
  }
}

processor.use(rehypeTableAlign, options)

method

  • Type: "style" | "class"
  • Default: "style"

Controls how the alignment is applied:

  • "style": Uses inline CSS properties (e.g., style="text-align: center;").
  • "class": Uses CSS class names instead.

classes

  • Type: { left?: string; center?: string; right?: string }
  • Default: { left: "left", center: "center", right: "right" }

Specifies the exact class names to apply when method is set to "class". If the element already has existing classes, the new class will be appended gracefully without overwriting them.

Types

This package provides generic TypeScript definitions out-of-the-box. It correctly types the plugin as a Plugin<[RehypeTableAlignOptions?], Root> for the hast ecosystem.

License

MIT © Chiahong Hong