diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index fe284ad..fb63387 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -7,15 +7,15 @@ jobs: name: ${{matrix.node}} runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - uses: dcodeIO/setup-node-nvm@master + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 with: node-version: ${{matrix.node}} - run: npm install - run: npm test - - uses: codecov/codecov-action@v1 + - uses: codecov/codecov-action@v3 strategy: matrix: node: - - lts/erbium + - lts/gallium - node diff --git a/index.js b/index.js index 66d33cd..c83f91e 100644 --- a/index.js +++ b/index.js @@ -23,14 +23,14 @@ export const slugs = new Slugger() * enableCustomId?: boolean, * maintainCase?: boolean, * removeAccents?: boolean - * }} props + * }} properties */ -export function getHeaderNodeId(node, props = {}) { +export function getHeaderNodeId(node, properties = {}) { const { enableCustomId = false, maintainCase = false, removeAccents = false - } = props + } = properties /** * @type {Node & HTMLElement} @@ -70,19 +70,25 @@ export function getHeaderNodeId(node, props = {}) { /** * Plugin to add `id`s to headings. * - * @type {import('unified').Plugin<[{ + * @param {{ * enableCustomId?: boolean, * maintainCase?: boolean, * removeAccents?: boolean - * }], Root>} + * }} properties */ -export default function rehypeSlug(props = {}) { +export default function rehypeSlug(properties = {}) { + /** + * @param {Root} tree + * Tree. + * @returns {undefined} + * Nothing. + */ return (tree) => { slugs.reset() visit(tree, 'element', (node) => { if (headingRank(node) && node.properties && !hasProperty(node, 'id')) { - const {id, isCustomId} = getHeaderNodeId(node, props) + const {id, isCustomId} = getHeaderNodeId(node, properties) if (isCustomId) node.children.pop() node.properties.id = id diff --git a/package.json b/package.json index 5e8103c..9f508d1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rehype-slug-custom-id", - "version": "1.1.0", + "version": "2.0.0", "description": "plugin to add `id` attributes to headings similar to gatsby-remark-autolink-headers ", "license": "MIT", "keywords": [ @@ -24,32 +24,31 @@ "index.js" ], "dependencies": { - "@types/hast": "^2.0.0", - "github-slugger": "^1.1.1", - "hast-util-has-property": "^2.0.0", - "hast-util-heading-rank": "^2.0.0", - "hast-util-to-string": "^2.0.0", + "@types/hast": "^3.0.4", + "github-slugger": "^2.0.0", + "hast-util-has-property": "^3.0.0", + "hast-util-heading-rank": "^3.0.0", + "hast-util-to-string": "^3.0.0", "lodash": "^4.17.21", - "unified": "^10.0.0", - "unist-util-visit": "^4.0.0" + "unified": "^11.0.5", + "unist-util-visit": "^5.0.0" }, "devDependencies": { - "@types/github-slugger": "^1.0.0", "@types/lodash": "^4.14.177", - "@types/tape": "^4.0.0", - "c8": "^7.0.0", - "prettier": "^2.0.0", - "rehype": "^12.0.0", - "remark-cli": "^10.0.0", - "remark-preset-wooorm": "^9.0.0", - "rimraf": "^3.0.0", + "@types/tape": "^5.6.4", + "c8": "^10.1.2", + "prettier": "^3.3.2", + "rehype": "^13.0.1", + "remark-cli": "^12.0.1", + "remark-preset-wooorm": "^10.0.0", + "rimraf": "^5.0.7", "tape": "^5.0.0", "type-coverage": "^2.0.0", - "typescript": "^4.0.0", - "xo": "^0.44.0" + "typescript": "^5.5.2", + "xo": "^0.58.0" }, "scripts": { - "build": "rimraf \"*.d.ts\" && tsc && type-coverage", + "build": "rimraf --glob \"*.d.ts\" && tsc && type-coverage", "format": "remark . -qo && prettier . -w --loglevel warn && xo --fix", "test-api": "node --conditions development test.js", "test-coverage": "c8 --check-coverage --branches 80 --functions 90 --lines 90 --statements 90 --reporter lcov npm run test-api", @@ -64,7 +63,10 @@ "trailingComma": "none" }, "xo": { - "prettier": true + "prettier": true, + "rules": { + "unicorn/prefer-at": "off" + } }, "remarkConfig": { "plugins": [ diff --git a/readme.md b/readme.md index 700163c..c84eb7d 100644 --- a/readme.md +++ b/readme.md @@ -76,9 +76,9 @@ Uses [**github-slugger**][ghslug] to create GitHub style `id`s, or a custom ID i We support the following options for the plugin: -* `enableCustomId`: `Boolean`. Enable custom header IDs with {#id} (optional) -* `maintainCase`: `Boolean`. Maintains the case for markdown header (optional) -* `removeAccents`: `Boolean`. Remove accents from generated headings IDs (optional) +* `enableCustomId`: `Boolean`. Enable custom header IDs with {#id} (optional) +* `maintainCase`: `Boolean`. Maintains the case for markdown header (optional) +* `removeAccents`: `Boolean`. Remove accents from generated headings IDs (optional) ## Security @@ -92,12 +92,12 @@ Always be wary with user input and use [`rehype-sanitize`][sanitize]. ## Related -* [`rehype-slug`](https://github.com/rehypejs/rehype-slug) - — Add slugs to headings in html -* [`remark-slug`](https://github.com/wooorm/remark-slug) - — Add slugs to headings in markdown -* [`gatsby-remark-autolink-headers`](https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-remark-autolink-headers) - — Add slugs to headings in markdown for Gatsby +* [`rehype-slug`](https://github.com/rehypejs/rehype-slug) + — Add slugs to headings in html +* [`remark-slug`](https://github.com/wooorm/remark-slug) + — Add slugs to headings in markdown +* [`gatsby-remark-autolink-headers`](https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-remark-autolink-headers) + — Add slugs to headings in markdown for Gatsby diff --git a/tsconfig.json b/tsconfig.json index e60e14d..d9c0e74 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,7 +2,7 @@ "include": ["*.js"], "compilerOptions": { "target": "ES2020", - "lib": ["ES2020", "DOM"], + "lib": ["ES2020", "DOM", "ES2020.String"], "module": "ES2020", "moduleResolution": "node", "allowJs": true,