{"id":13716718,"url":"https://github.com/syntax-tree/mdast-util-heading-range","last_synced_at":"2026-04-08T19:31:01.787Z","repository":{"id":30434828,"uuid":"33987896","full_name":"syntax-tree/mdast-util-heading-range","owner":"syntax-tree","description":"utility to use headings as ranges in mdast","archived":false,"fork":false,"pushed_at":"2023-07-07T16:29:14.000Z","size":172,"stargazers_count":10,"open_issues_count":0,"forks_count":2,"subscribers_count":7,"default_branch":"main","last_synced_at":"2026-03-25T08:15:06.603Z","etag":null,"topics":["heading","markdown","mdast","mdast-util","syntax-tree","unist","util"],"latest_commit_sha":null,"homepage":"https://unifiedjs.com","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/syntax-tree.png","metadata":{"funding":{"github":"unifiedjs","open_collective":"unified"},"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2015-04-15T10:37:11.000Z","updated_at":"2024-04-28T08:33:01.000Z","dependencies_parsed_at":"2026-03-18T17:02:02.525Z","dependency_job_id":null,"html_url":"https://github.com/syntax-tree/mdast-util-heading-range","commit_stats":{"total_commits":145,"total_committers":3,"mean_commits":"48.333333333333336","dds":0.03448275862068961,"last_synced_commit":"07b435d28fd81e8526ec148e9985ba405e1401f3"},"previous_names":["wooorm/mdast-heading"],"tags_count":20,"template":false,"template_full_name":null,"purl":"pkg:github/syntax-tree/mdast-util-heading-range","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Fmdast-util-heading-range","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Fmdast-util-heading-range/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Fmdast-util-heading-range/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Fmdast-util-heading-range/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/syntax-tree","download_url":"https://codeload.github.com/syntax-tree/mdast-util-heading-range/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Fmdast-util-heading-range/sbom","scorecard":{"id":863488,"data":{"date":"2025-08-11","repo":{"name":"github.com/syntax-tree/mdast-util-heading-range","commit":"f59c55ba288f06d60ba2c0517bdb9460377063ca"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3.7,"checks":[{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: third-party GitHubAction not pinned by hash: .github/workflows/bb.yml:11: update your workflow using https://app.stepsecurity.io/secureworkflow/syntax-tree/mdast-util-heading-range/bb.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:10: update your workflow using https://app.stepsecurity.io/secureworkflow/syntax-tree/mdast-util-heading-range/main.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:11: update your workflow using https://app.stepsecurity.io/secureworkflow/syntax-tree/mdast-util-heading-range/main.yml/main?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/main.yml:16: update your workflow using https://app.stepsecurity.io/secureworkflow/syntax-tree/mdast-util-heading-range/main.yml/main?enable=pin","Warn: npmCommand not pinned by hash: .github/workflows/main.yml:15","Info:   0 out of   2 GitHub-owned GitHubAction dependencies pinned","Info:   0 out of   2 third-party GitHubAction dependencies pinned","Info:   0 out of   1 npmCommand dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Code-Review","score":0,"reason":"Found 0/30 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: no topLevel permission defined: .github/workflows/bb.yml:1","Warn: no topLevel permission defined: .github/workflows/main.yml:1","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: license:0","Info: FSF or OSI recognized license: MIT License: license:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":0,"reason":"Project has not signed or included provenance with any releases.","details":["Warn: release artifact 2.1.5 not signed: https://api.github.com/repos/syntax-tree/mdast-util-heading-range/releases/33318775","Warn: release artifact 2.1.5 does not have provenance: https://api.github.com/repos/syntax-tree/mdast-util-heading-range/releases/33318775"],"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'main'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Security-Policy","score":10,"reason":"security policy file detected","details":["Info: security policy file detected: github.com/syntax-tree/.github/security.md:1","Info: Found linked content: github.com/syntax-tree/.github/security.md:1","Info: Found disclosure, vulnerability, and/or timelines in security policy: github.com/syntax-tree/.github/security.md:1","Info: Found text in security policy: github.com/syntax-tree/.github/security.md:1"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}}]},"last_synced_at":"2025-08-24T02:00:53.358Z","repository_id":30434828,"created_at":"2025-08-24T02:00:53.358Z","updated_at":"2025-08-24T02:00:53.358Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31571599,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-08T14:31:17.711Z","status":"ssl_error","status_checked_at":"2026-04-08T14:31:17.202Z","response_time":54,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["heading","markdown","mdast","mdast-util","syntax-tree","unist","util"],"created_at":"2024-08-03T00:01:13.659Z","updated_at":"2026-04-08T19:31:01.765Z","avatar_url":"https://github.com/syntax-tree.png","language":"JavaScript","readme":"# mdast-util-heading-range\n\n[![Build][build-badge]][build]\n[![Coverage][coverage-badge]][coverage]\n[![Downloads][downloads-badge]][downloads]\n[![Size][size-badge]][size]\n[![Sponsors][sponsors-badge]][collective]\n[![Backers][backers-badge]][collective]\n[![Chat][chat-badge]][chat]\n\n[mdast][] utility to find headings and replace the content in their section.\n\n## Contents\n\n*   [What is this?](#what-is-this)\n*   [When should I use this?](#when-should-i-use-this)\n*   [Install](#install)\n*   [Use](#use)\n*   [API](#api)\n    *   [`headingRange(tree, test|options, handler)`](#headingrangetree-testoptions-handler)\n    *   [`Handler`](#handler)\n    *   [`Info`](#info)\n    *   [`Options`](#options)\n    *   [`Test`](#test)\n    *   [`TestFunction`](#testfunction)\n*   [Types](#types)\n*   [Compatibility](#compatibility)\n*   [Security](#security)\n*   [Related](#related)\n*   [Contribute](#contribute)\n*   [License](#license)\n\n## What is this?\n\nThis package is a utility that lets you find a certain heading, then takes the\ncontent in their section (from it to the next heading of the same or lower\ndepth), and calls a given handler with the result, so that you can change or\nreplace things.\n\n## When should I use this?\n\nThis utility is typically useful when you have certain sections that can be\ngenerated.\nFor example, this utility is used by [`remark-toc`][remark-toc] to update the\nabove `Contents` heading.\n\nA similar package, [`mdast-zone`][mdast-zone], does the same but uses comments\nto mark the start and end of sections.\n\n## Install\n\nThis package is [ESM only][esm].\nIn Node.js (version 16+), install with [npm][]:\n\n```sh\nnpm install mdast-util-heading-range\n```\n\nIn Deno with [`esm.sh`][esmsh]:\n\n```js\nimport {headingRange} from 'https://esm.sh/mdast-util-heading-range@4'\n```\n\nIn browsers with [`esm.sh`][esmsh]:\n\n```html\n\u003cscript type=\"module\"\u003e\n  import {headingRange} from 'https://esm.sh/mdast-util-heading-range@4?bundle'\n\u003c/script\u003e\n```\n\n## Use\n\nSay we have the following file, `example.md`:\n\n```markdown\n# Foo\n\nBar.\n\n# Baz\n```\n\n…and a module `example.js`:\n\n```js\nimport {read} from 'to-vfile'\nimport {remark} from 'remark'\nimport {headingRange} from 'mdast-util-heading-range'\n\nconst file = await remark()\n  .use(myPluginThatReplacesFoo)\n  .process(await read('example.md'))\n\nconsole.log(String(file))\n\n/** @type {import('unified').Plugin\u003c[], import('mdast').Root\u003e} */\nfunction myPluginThatReplacesFoo() {\n  return function (tree) {\n    headingRange(tree, 'foo', function (start, nodes, end) {\n      return [\n        start,\n        {type: 'paragraph', children: [{type: 'text', value: 'Qux.'}]},\n        end\n      ]\n    })\n  }\n}\n```\n\n…now running `node example.js` yields:\n\n```markdown\n# Foo\n\nQux.\n\n# Baz\n```\n\n## API\n\nThis package exports the identifier [`headingRange`][api-heading-range].\nThere is no default export.\n\n### `headingRange(tree, test|options, handler)`\n\nSearch `tree` for a heading matching `test` and change its “section” with\n`handler`.\n\nA “section” ranges from the matched heading until the next heading of the\nsame or lower depth, or the end of the document.\n\nIf `ignoreFinalDefinitions: true`, final definitions “in” the section are\nexcluded.\n\n###### Parameters\n\n*   `tree` ([`Node`][node])\n    — tree to change\n*   `test` ([`Test`][api-test])\n    — same as passing `{test: Test}`\n*   `options` ([`Options`][api-options])\n    — configuration\n*   `handler` ([`Handler`][api-handler])\n    — handle a section\n\n###### Returns\n\nNothing (`undefined`).\n\n### `Handler`\n\nCallback called when a section is found (TypeScript type).\n\n###### Parameters\n\n*   `start` ([`Heading`][heading])\n    — start of section (a heading node matching `test`)\n*   `nodes` ([`Array\u003cNode\u003e`][node])\n    — nodes between `start` and `end`\n*   `end` ([`Node`][node] or `undefined`)\n    — end of section, if any\n*   `info` ([`Info`][api-info])\n    — extra info\n\n###### Returns\n\nResults (`Array\u003cNode | null | undefined\u003e`, optional).\n\nIf nothing is returned, nothing will be changed.\nIf an array of nodes (can include `null` and `undefined`) is returned, the\noriginal section will be replaced by those nodes.\n\n### `Info`\n\nExtra info (TypeScript type).\n\n###### Fields\n\n*   `parent` ([`Node`][node])\n    — parent of the section\n*   `start` (`number`)\n    — index of `start` in `parent`\n*   `end` (`number` or `undefined`)\n    — index of `end` in `parent`\n\n### `Options`\n\nConfiguration (TypeScript type).\n\n###### Fields\n\n*   `test` ([`Test`][api-test])\n    — test for a heading\n*   `ignoreFinalDefinitions` (`boolean`, default: `false`)\n    — ignore final definitions otherwise in the section\n\n### `Test`\n\nTest for a heading (TypeScript type).\n\nWhen `string`, wrapped in `new RegExp('^(' + value + ')$', 'i')`;\nwhen `RegExp`, wrapped in `(value) =\u003e expression.test(value)`\n\n###### Type\n\n```ts\nexport type Test = RegExp | TestFunction | string\n```\n\n### `TestFunction`\n\nCheck if a node matches (TypeScript type).\n\n###### Parameters\n\n*   `value` (`string`)\n    — plain-text heading\n*   `node` ([`Heading`][heading])\n    — heading node\n\n###### Returns\n\nWhether this is the heading that is searched for (`boolean`, optional).\n\n## Types\n\nThis package is fully typed with [TypeScript][].\nThis package exports the types [`Handler`][api-handler],\n[`Info`][api-info], [`Options`][api-options], [`Test`][api-test],\nand [`TestFunction`][api-test-function].\n\n## Compatibility\n\nProjects maintained by the unified collective are compatible with maintained\nversions of Node.js.\n\nWhen we cut a new major release, we drop support for unmaintained versions of\nNode.\nThis means we try to keep the current release line,\n`mdast-util-heading-range@^4`, compatible with Node.js 16.\n\n## Security\n\nImproper use of `handler` can open you up to a [cross-site scripting (XSS)][xss]\nattack as the value it returns is injected into the syntax tree.\nThis can become a problem if the tree is later transformed to [**hast**][hast].\nThe following example shows how a script is injected that could run when loaded\nin a browser.\n\n```js\n/** @type {import('mdast-util-heading-range').Handler} */\nfunction handler(start, nodes, end) {\n  return [start, {type: 'html', value: '\u003cscript\u003ealert(1)\u003c/script\u003e'}, end]\n}\n```\n\nYields:\n\n```markdown\n# Foo\n\n\u003cscript\u003ealert(1)\u003c/script\u003e\n\n# Baz\n```\n\nEither do not use user input in `handler` or use\n[`hast-util-santize`][hast-util-sanitize].\n\n## Related\n\n*   [`mdast-zone`](https://github.com/syntax-tree/mdast-zone)\n    — similar but uses comments to mark the start and end of sections\n\n## Contribute\n\nSee [`contributing.md`][contributing] in [`syntax-tree/.github`][health] for\nways to get started.\nSee [`support.md`][support] for ways to get help.\n\nThis project has a [code of conduct][coc].\nBy interacting with this repository, organisation, or community you agree to\nabide by its terms.\n\n## License\n\n[MIT][license] © [Titus Wormer][author]\n\n\u003c!-- Definitions --\u003e\n\n[build-badge]: https://github.com/syntax-tree/mdast-util-heading-range/workflows/main/badge.svg\n\n[build]: https://github.com/syntax-tree/mdast-util-heading-range/actions\n\n[coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/mdast-util-heading-range.svg\n\n[coverage]: https://codecov.io/github/syntax-tree/mdast-util-heading-range\n\n[downloads-badge]: https://img.shields.io/npm/dm/mdast-util-heading-range.svg\n\n[downloads]: https://www.npmjs.com/package/mdast-util-heading-range\n\n[size-badge]: https://img.shields.io/badge/dynamic/json?label=minzipped%20size\u0026query=$.size.compressedSize\u0026url=https://deno.bundlejs.com/?q=mdast-util-heading-range\n\n[size]: https://bundlejs.com/?q=mdast-util-heading-range\n\n[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg\n\n[backers-badge]: https://opencollective.com/unified/backers/badge.svg\n\n[collective]: https://opencollective.com/unified\n\n[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg\n\n[chat]: https://github.com/syntax-tree/unist/discussions\n\n[npm]: https://docs.npmjs.com/cli/install\n\n[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c\n\n[esmsh]: https://esm.sh\n\n[typescript]: https://www.typescriptlang.org\n\n[license]: license\n\n[author]: https://wooorm.com\n\n[health]: https://github.com/syntax-tree/.github\n\n[contributing]: https://github.com/syntax-tree/.github/blob/main/contributing.md\n\n[support]: https://github.com/syntax-tree/.github/blob/main/support.md\n\n[coc]: https://github.com/syntax-tree/.github/blob/main/code-of-conduct.md\n\n[mdast]: https://github.com/syntax-tree/mdast\n\n[node]: https://github.com/syntax-tree/unist#node\n\n[heading]: https://github.com/syntax-tree/mdast#heading\n\n[xss]: https://en.wikipedia.org/wiki/Cross-site_scripting\n\n[hast]: https://github.com/syntax-tree/hast\n\n[mdast-zone]: https://github.com/syntax-tree/mdast-zone\n\n[hast-util-sanitize]: https://github.com/syntax-tree/hast-util-sanitize\n\n[remark-toc]: https://github.com/remarkjs/remark-toc\n\n[api-heading-range]: #headingrangetree-testoptions-handler\n\n[api-handler]: #handler\n\n[api-options]: #options\n\n[api-test]: #test\n\n[api-test-function]: #testfunction\n\n[api-info]: #info\n","funding_links":["https://github.com/sponsors/unifiedjs","https://opencollective.com/unified"],"categories":["mdast utilities"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsyntax-tree%2Fmdast-util-heading-range","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsyntax-tree%2Fmdast-util-heading-range","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsyntax-tree%2Fmdast-util-heading-range/lists"}