{"id":15696041,"url":"https://github.com/vweevers/section-remark","last_synced_at":"2026-04-30T01:39:37.613Z","repository":{"id":55828347,"uuid":"132285306","full_name":"vweevers/section-remark","owner":"vweevers","description":"Specialized Remark that only transforms (or adds) one Markdown section.","archived":false,"fork":false,"pushed_at":"2020-12-11T17:48:11.000Z","size":4,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-03-14T18:00:17.885Z","etag":null,"topics":["markdown","remark","unified"],"latest_commit_sha":null,"homepage":"","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/vweevers.png","metadata":{"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}},"created_at":"2018-05-05T21:19:22.000Z","updated_at":"2018-05-06T00:20:19.000Z","dependencies_parsed_at":"2022-08-15T07:31:19.337Z","dependency_job_id":null,"html_url":"https://github.com/vweevers/section-remark","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/vweevers/section-remark","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vweevers%2Fsection-remark","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vweevers%2Fsection-remark/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vweevers%2Fsection-remark/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vweevers%2Fsection-remark/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vweevers","download_url":"https://codeload.github.com/vweevers/section-remark/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vweevers%2Fsection-remark/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32451481,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-29T22:27:22.272Z","status":"ssl_error","status_checked_at":"2026-04-29T22:10:49.234Z","response_time":110,"last_error":"SSL_read: 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":["markdown","remark","unified"],"created_at":"2024-10-03T19:06:44.950Z","updated_at":"2026-04-30T01:39:37.579Z","avatar_url":"https://github.com/vweevers.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# section-remark\n\n\u003e Specialized Remark that only transforms (or adds) one Markdown section.\n\n[![npm status](http://img.shields.io/npm/v/section-remark.svg?style=flat-square)](https://www.npmjs.org/package/section-remark)\n[![node](https://img.shields.io/node/v/section-remark.svg?style=flat-square)](https://www.npmjs.org/package/section-remark)\n[![Build Status](https://img.shields.io/travis/vweevers/section-remark.svg?style=flat-square)](http://travis-ci.org/vweevers/section-remark)\n[![Dependency status](https://img.shields.io/david/vweevers/section-remark.svg?style=flat-square)](https://david-dm.org/vweevers/section-remark)\n[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg?style=flat-square)](https://standardjs.com)\n\n## Background\n\nRemark works on an *abstract* syntax tree, which means some information is lost. Not semantics, but formatting, style, whitespace, i.e. your personal preferences. What's more, converting the AST back to markdown will *add* formatting and possibly result in unwanted diff noise.\n\nMeant for sections of generated markdown, `section-remark` runs on a subset of the tree (a range of nodes starting with a certain header), stringifies it and concatenates the result with the rest of your markdown. Other sections are left alone.\n\nReturns a `unified` processor, so like the regular `remark`, you can use [any plugin](https://github.com/remarkjs/remark/blob/master/doc/plugins.md).\n\n## Usage\n\nAs an example, let's generate a Contributors section:\n\n```js\nconst remark = require('section-remark')\nconst contributors = require('remark-contributors')\nconst report = require('vfile-reporter')\nconst vfile = require('to-vfile')\n\nremark('Contributors')\n  .use(contributors)\n  .process(vfile.readSync('README.md'), function (err, file) {\n    console.error(report(err || file))\n    vfile.writeSync(file)\n  })\n```\n\nThis does nothing if the contributors section doesn't already exist. To either replace it or add it to the end of the document, do:\n\n```js\nremark('Contributors', { add: true })\n```\n\nTo replace it or add it after another section:\n\n```js\nremark('Contributors', { after: 'API' })\n```\n\nWe can use any `test` supported by [`mdast-util-heading-range`](https://github.com/syntax-tree/mdast-util-heading-range). If we want to generate an API section and insert it after a usage or example section:\n\n```js\nremark('API', { after: /^(usage|example)$/i })\n```\n\nSame goes for the first argument. If we want to replace or add a TOC:\n\n```js\nremark(/^(table of )?contents$/i, { add: true })\n```\n\nThis will throw an error though if the TOC doesn't exist, because `section-remark` can't convert the regular expression to a title. We should define the `text` option, so that a \"Contents\" header will be renamed to \"Table of Contents\". And let's insert the TOC before another section.\n\n```js\nremark(/^(table of )?contents$/i, {\n  text: 'Table of Contents',\n  before: /^usage|example$/i\n})\n```\n\nLastly, if you use `before` or `after` and the section does not already exist, its header will inherit the depth of its `before` or `after` sibling.\n\n## API\n\n### `sectionRemark(test[, options])`\n\nReturns a `unified` processor that transforms a section starting with a header which matches `test` (see [`mdast-util-heading-range`](https://github.com/syntax-tree/mdast-util-heading-range)). Options:\n\n- `add`: add to end of document, if not found\n- `before`: insert before section, if not found\n- `after`: insert after section, if not found\n- `text`: text content of header, defaults to `test` if a string\n- `depth`: header depth, starting at 1, defaults to sibling depth or 2.\n\n## Install\n\nWith [npm](https://npmjs.org) do:\n\n```\nnpm install section-remark\n```\n\n## License\n\n[MIT](http://opensource.org/licenses/MIT) © Vincent Weevers\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvweevers%2Fsection-remark","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvweevers%2Fsection-remark","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvweevers%2Fsection-remark/lists"}