Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/benjamincharity/rehype-enhanced-tables
A Rehype plugin that modifies HTML tables, with support for caption, footer, custom classes, scroll-wrappers, and scopes.
https://github.com/benjamincharity/rehype-enhanced-tables
Last synced: 11 days ago
JSON representation
A Rehype plugin that modifies HTML tables, with support for caption, footer, custom classes, scroll-wrappers, and scopes.
- Host: GitHub
- URL: https://github.com/benjamincharity/rehype-enhanced-tables
- Owner: benjamincharity
- License: mit
- Created: 2024-02-10T20:28:37.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2024-02-10T21:24:07.000Z (9 months ago)
- Last Synced: 2024-10-26T13:27:05.324Z (13 days ago)
- Language: TypeScript
- Size: 8.79 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# rehype-enhanced-tables
![test workflow](https://github.com/benjamincharity/rehype-enhanced-tables/actions/workflows/test.yml/badge.svg)
[![codecov](https://codecov.io/gh/benjamincharity/rehype-enhanced-tables/branch/main/graph/badge.svg?token=T3Z18P56LV)](https://codecov.io/gh/benjamincharity/rehype-enhanced-tables)
![NPM Version](https://img.shields.io/npm/v/@benjc/rehype-enhanced-tables)A Rehype plugin that modifies HTML tables, with support for caption, footer, custom classes, scroll-wrappers, and scopes.
## Install
```
npm i -D @benjc/rehype-enhanced-tables
```## Usage
```typescript
import rehypeEnhancedTables from "@benjc/rehype-enhanced-tables";
import rehype from "rehype";
import rehypeParse from "rehype-parse";
import { unified } from "unified";const tableStruct = `
| heading | b | c | d |
| -: | -: | -: | :-: |
| cell 1 | cell 2 | 3 | 4 |
`;unified()
.use(rehypeParse, { fragment: true })
.use(rehypeEnhancedTables)
.process(tableStruct);// Or with options:
unified()
.use(rehypeParse, { fragment: true })
.use(rehypeEnhancedTables, {
disableWrapper: true,
classes: {
table: "custom-class",
cell: "custom-cell",
...
},
})
.process(tableStruct);
```### Input
```html
One
Two
Cell 1
Cell 2
Cell 3
Cell 4
```
### Output
```html
One
Two
Cell 1
Cell 2
Cell 3
Cell 4
```## Options
The `rehype-enhanced-tables` plugin accepts an `options` object with the following properties:
| Option | Type | Description |
| ---------------- | -------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `disableWrapper` | `boolean` | If set to `true`, the plugin will not wrap the table with a div. |
| `classes` | `Partial` | An object that maps element types to class names. The keys can be any of the following: `caption`, `footer`, `table`, `tbody`, `td`, `th`, `thead`, `tr`, `wrapper`. |These options can be passed to the `rehype-enhanced-tables` plugin as part of the `options` object. For example:
```typescript
import rehypeEnhancedTables from "./index";rehypeEnhancedTables({
disableWrapper: true,
classes: {
caption: "custom-caption",
table: "custom-table",
tbody: "custom-tbody",
td: "custom-td",
tfoot: "custom-tfoot",
th: "custom-th",
thead: "custom-thead",
tr: "custom-tr",
wrapper: "custom-wrapper",
},
});
```## License
[MIT][license] © [benjamincharity][author]
[license]: license
[author]: https://www.benjamincharity.com