{"id":14990166,"url":"https://github.com/daviddarnes/heading-anchors","last_synced_at":"2025-04-12T02:05:43.864Z","repository":{"id":246015651,"uuid":"729870707","full_name":"daviddarnes/heading-anchors","owner":"daviddarnes","description":"A Web Component to add anchor links to headings with IDs","archived":false,"fork":false,"pushed_at":"2024-10-15T10:57:22.000Z","size":42,"stargazers_count":28,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-12T02:05:32.763Z","etag":null,"topics":["component","components","customelement","customelements","webcomponent","webcomponents"],"latest_commit_sha":null,"homepage":"https://daviddarnes.github.io/heading-anchors/demo.html","language":"HTML","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/daviddarnes.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-12-10T16:01:29.000Z","updated_at":"2025-03-03T19:20:03.000Z","dependencies_parsed_at":"2024-06-25T11:29:43.520Z","dependency_job_id":"6ed531e7-b286-4f80-9f10-d6cb72f160d0","html_url":"https://github.com/daviddarnes/heading-anchors","commit_stats":{"total_commits":20,"total_committers":1,"mean_commits":20.0,"dds":0.0,"last_synced_commit":"81919f746c392fce0f4caec52c6c1f09e4f3ae56"},"previous_names":["daviddarnes/heading-anchors"],"tags_count":2,"template":false,"template_full_name":"daviddarnes/component-template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daviddarnes%2Fheading-anchors","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daviddarnes%2Fheading-anchors/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daviddarnes%2Fheading-anchors/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daviddarnes%2Fheading-anchors/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/daviddarnes","download_url":"https://codeload.github.com/daviddarnes/heading-anchors/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248505862,"owners_count":21115354,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["component","components","customelement","customelements","webcomponent","webcomponents"],"created_at":"2024-09-24T14:19:38.766Z","updated_at":"2025-04-12T02:05:43.840Z","avatar_url":"https://github.com/daviddarnes.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":"# `heading-anchors`\n\nA Web Component to add anchor links to headings with IDs.\n\n**[Demo](https://daviddarnes.github.io/heading-anchors/demo.html)** | **[Styling demo](https://daviddarnes.github.io/heading-anchors/demo-styling.html)** | **[Further reading](https://darn.es/heading-anchors-web-component/)**\n\n## Examples\n\n```html\n\u003cscript type=\"module\" src=\"heading-anchors.js\"\u003e\u003c/script\u003e\n\n\u003cheading-anchors\u003e\n  \u003ch2 id=\"heading-level-2\"\u003eHeading level 2\u003c/h2\u003e\n  \u003cp\u003eLorem ipsum dolor sit amet consectetur adipisicing elit.\u003c/p\u003e\n\n  \u003ch3 id=\"heading-level-3\"\u003eHeading level 3\u003c/h3\u003e\n  \u003cp\u003e\n    Excepturi eligendi exercitationem, ratione, in delectus vitae veritatis\n    dolorem porro cupiditate quam eaque voluptates.\n  \u003c/p\u003e\n\u003c/heading-anchors\u003e\n```\n\n## Features\n\nThis Web Component allows you to:\n\n- Add anchor links to headings which have an ID attribute and value\n- Customise which elements will be appended with an anchor link using the `selector` attribute\n- Customise where the anchor link is appended using the `position` attribute\n\n## Installation\n\nYou have a few options (choose one of these):\n\n1. Install via [npm](https://www.npmjs.com/package/@daviddarnes/heading-anchors): `npm install @daviddarnes/heading-anchors` (also avaialbe on [jsr](https://jsr.io/@daviddarnes/heading-anchors))\n1. [Download the source manually from GitHub](https://github.com/daviddarnes/heading-anchors/releases) into your project.\n1. Skip this step and use the script directly via a 3rd party CDN (not recommended for production use)\n\n### Usage\n\nMake sure you include the `\u003cscript\u003e` in your project (choose one of these):\n\n```html\n\u003c!-- Host yourself --\u003e\n\u003cscript type=\"module\" src=\"heading-anchors.js\"\u003e\u003c/script\u003e\n```\n\n```html\n\u003c!-- 3rd party CDN, not recommended for production use --\u003e\n\u003cscript\n  type=\"module\"\n  src=\"https://www.unpkg.com/@daviddarnes/heading-anchors@2.0.2/heading-anchors.js\"\n\u003e\u003c/script\u003e\n```\n\n```html\n\u003c!-- 3rd party CDN, not recommended for production use --\u003e\n\u003cscript\n  type=\"module\"\n  src=\"https://esm.sh/@daviddarnes/heading-anchors@2.0.2\"\n\u003e\u003c/script\u003e\n```\n\n### Using `selector` and `position`\n\nBy default `heading-anchors` will select all the `h2[id]`, `h3[id]` and `h4[id]` elements within it to append an anchor link to. However with the `selector` attribute you can pass in a different selector string to select:\n\n```html\n\u003cheading-anchors selector=\"h2[id]\"\u003e\n  \u003c!-- ... --\u003e\n\u003c/heading-anchors\u003e\n```\n\n_Note: It's recommended you use selectors that utilise the `[id]` attribute selector for better reliability_\n\nBy default `heading-anchors` will append anchor links right after the element, using the [`insertAdjacentHTML`](https://developer.mozilla.org/en-US/docs/Web/API/Element/insertAdjacentHTML) API. However you can adjust this using the `position` attribute:\n\n```html\n\u003cheading-anchors position=\"beforeend\"\u003e\n  \u003c!-- ... --\u003e\n\u003c/heading-anchors\u003e\n```\n\n## Credit\n\nWith thanks to the following people:\n\n- [Zach Leatherman](https://zachleat.com) for inspiring this [Web Component repo template](https://github.com/daviddarnes/component-template)\n- [Curtis Wilcox](https://github.com/extra808) for the accessibility feedback\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdaviddarnes%2Fheading-anchors","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdaviddarnes%2Fheading-anchors","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdaviddarnes%2Fheading-anchors/lists"}