-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 3af440b
Showing
29 changed files
with
1,005 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
name: Publish Package to NPM | ||
|
||
on: | ||
release: | ||
types: [created] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
environment: | ||
name: production | ||
url: https://www.npmjs.com/package/@benjc/rehype-enhanced-tables | ||
|
||
permissions: | ||
id-token: write | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: "20.x" | ||
registry-url: "https://registry.npmjs.org" | ||
scope: "@benjc" | ||
|
||
- uses: pnpm/action-setup@v2 | ||
with: | ||
version: 8 | ||
|
||
- name: Run install | ||
run: pnpm i | ||
|
||
- name: Run build | ||
run: pnpm run build | ||
|
||
- name: Run publish | ||
run: npm publish --provenance --access=public | ||
env: | ||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
name: Test | ||
|
||
on: | ||
push: | ||
branches: [main] | ||
pull_request: | ||
branches: [main] | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
node-version: [18.x, 20.x] | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
|
||
- uses: pnpm/action-setup@v2 | ||
with: | ||
version: 8 | ||
|
||
- name: Run install | ||
run: pnpm i | ||
|
||
- name: Run lint | ||
run: pnpm lint | ||
|
||
- name: Run unit tests | ||
run: pnpm test | ||
|
||
- name: Run type coverage tests | ||
run: pnpm type-coverage | ||
|
||
- name: Run build | ||
run: pnpm run build | ||
|
||
- name: Generate coverage file | ||
run: pnpm run coverage | ||
|
||
- name: Upload coverage to Codecov | ||
uses: codecov/codecov-action@v4 | ||
env: | ||
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} | ||
with: | ||
files: ./coverage/coverage-final.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
*.lcov | ||
|
||
# Compiled binary addons (https://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directories | ||
node_modules/ | ||
|
||
# TypeScript cache | ||
*.tsbuildinfo | ||
.npm | ||
|
||
# Artifact | ||
dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
*.lcov | ||
|
||
# Compiled binary addons (https://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directories | ||
node_modules/ | ||
|
||
# TypeScript cache | ||
*.tsbuildinfo | ||
.npm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package-lock=false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/coverage/ | ||
/node_modules/ | ||
pnpm-lock.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"bracketSpacing": true, | ||
"importOrder": ["^@core/(.*)$", "^@server/(.*)$", "^@ui/(.*)$", "^~/(.*)$", "^[./]"], | ||
"importOrderSeparation": true, | ||
"importOrderSortSpecifiers": true, | ||
"plugins": ["@trivago/prettier-plugin-sort-imports"], | ||
"printWidth": 120, | ||
"quoteProps": "consistent", | ||
"semi": true, | ||
"singleQuote": false, | ||
"trailingComma": "es5", | ||
"useTabs": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"space": true, | ||
"rules": { | ||
"import/order": "off", | ||
"max-params": "off" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2024 Benjamin Charity | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
# 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 | ||
<table> | ||
<thead> | ||
<tr> | ||
<th>One</th> | ||
<th>Two</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<tr> | ||
<td>Cell 1</td> | ||
<td>Cell 2</td> | ||
</tr> | ||
<tr> | ||
<td>Cell 3</td> | ||
<td>Cell 4</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
``` | ||
|
||
### Output | ||
|
||
```html | ||
<div class="ret-table-wrapper"> | ||
<table class="ret-table"> | ||
<thead class="ret-table-thead"> | ||
<tr class="ret-table-row"> | ||
<th scope="col" class="ret-table-th">One</th> | ||
<th scope="col" class="ret-table-th">Two</th> | ||
</tr> | ||
</thead> | ||
<tbody class="ret-table-body"> | ||
<tr class="ret-table-row"> | ||
<td class="ret-table-cell">Cell 1</td> | ||
<td class="ret-table-cell">Cell 2</td> | ||
</tr> | ||
<tr class="ret-table-row"> | ||
<td class="ret-table-cell">Cell 3</td> | ||
<td class="ret-table-cell">Cell 4</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
</div> | ||
``` | ||
|
||
## 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<RehypeEnhancedTableElementClasses>` | 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
{ | ||
"author": "Benjamin Charity <[email protected]> (https://www.benjamincharity.com/)", | ||
"bugs": { | ||
"url": "https://github.com/benjamincharity/rehype-enhanced-tables/issues" | ||
}, | ||
"dependencies": { | ||
"hast-util-has-property": "3.0.0", | ||
"hast-util-is-element": "3.0.0", | ||
"rehype": "^13.0.0", | ||
"unified": "^11.0.0", | ||
"unist-util-remove": "4.0.0", | ||
"unist-util-visit": "^5.0.0" | ||
}, | ||
"description": "A Rehype plugin that modifies HTML tables, with support for caption, footer, custom classes, scroll-wrappers, and scopes.", | ||
"devDependencies": { | ||
"@trivago/prettier-plugin-sort-imports": "^4.3.0", | ||
"@types/hast": "^3.0.4", | ||
"@types/node": "^20.11.16", | ||
"@vitest/coverage-v8": "^1.2.2", | ||
"hast-util-select": "6.0.2", | ||
"hast-util-to-html": "^9.0.0", | ||
"hastscript": "^9.0.0", | ||
"prettier": "^3.2.4", | ||
"rehype-minify-whitespace": "^6.0.0", | ||
"rimraf": "^5.0.5", | ||
"to-vfile": "^8.0.0", | ||
"type-coverage": "^2.27.1", | ||
"typecov": "~0.2.3", | ||
"typescript": "^5.3.3", | ||
"vite": "^5.0.12", | ||
"vitest": "^1.2.2", | ||
"xo": "~0.56.0" | ||
}, | ||
"engines": { | ||
"node": ">=18.0.0" | ||
}, | ||
"files": [ | ||
"dist" | ||
], | ||
"homepage": "https://github.com/benjamincharity/rehype-enhanced-tables#readme", | ||
"keywords": [ | ||
"rehype", | ||
"rehype-plugin", | ||
"unified", | ||
"unified-plugin", | ||
"html", | ||
"images", | ||
"figure" | ||
], | ||
"license": "MIT", | ||
"main": "dist/index.js", | ||
"module": "dist/index.js", | ||
"name": "@benjc/rehype-enhanced-tables", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/benjamincharity/rehype-enhanced-tables.git" | ||
}, | ||
"scripts": { | ||
"build": "tsc", | ||
"coverage": "vitest run --coverage", | ||
"coverage:types": "type-coverage", | ||
"format": "prettier --write .", | ||
"lint": "xo --prettier", | ||
"lint:fix": "xo --fix --prettier", | ||
"prebuild": "rimraf dist", | ||
"test": "vitest", | ||
"typecheck": "tsc --noEmit" | ||
}, | ||
"type": "module", | ||
"typeCoverage": { | ||
"atLeast": 97, | ||
"detail": true, | ||
"ignoreCatch": true, | ||
"strict": true | ||
}, | ||
"types": "dist/index.d.ts", | ||
"version": "0.1.1" | ||
} |
Oops, something went wrong.