{"id":18206598,"url":"https://github.com/krtninja/krt-text-highlighter","last_synced_at":"2025-06-10T23:39:47.415Z","repository":{"id":260809470,"uuid":"882354698","full_name":"KrtNinja/krt-text-highlighter","owner":"KrtNinja","description":"Simple text highlighter based on css.highlight","archived":false,"fork":false,"pushed_at":"2024-11-02T19:22:17.000Z","size":13,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-07T08:46:48.580Z","etag":null,"topics":["css","html","javascript","text-highlighting"],"latest_commit_sha":null,"homepage":"https://krtninja.github.io/krt-text-highlighter/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/KrtNinja.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2024-11-02T15:54:30.000Z","updated_at":"2024-11-02T19:47:25.000Z","dependencies_parsed_at":"2024-11-02T20:18:49.327Z","dependency_job_id":"e2327796-124d-4418-af64-e07d3dd87e02","html_url":"https://github.com/KrtNinja/krt-text-highlighter","commit_stats":null,"previous_names":["krtninja/text-highlighter","krtninja/krt-text-highlighter"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KrtNinja%2Fkrt-text-highlighter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KrtNinja%2Fkrt-text-highlighter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KrtNinja%2Fkrt-text-highlighter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KrtNinja%2Fkrt-text-highlighter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/KrtNinja","download_url":"https://codeload.github.com/KrtNinja/krt-text-highlighter/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KrtNinja%2Fkrt-text-highlighter/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259172115,"owners_count":22816514,"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":["css","html","javascript","text-highlighting"],"created_at":"2024-11-03T12:05:23.289Z","updated_at":"2025-06-10T23:39:47.393Z","avatar_url":"https://github.com/KrtNinja.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Text highlighter\n\nExample for implementation in your project, or use as a library. \\\nAnalogue of the search in the browser on the page, but you can specify areas (custom root element) for highlighting the text.\\\nAlso exclude paragraphs from highlighting inside the root.\n\n\u003e Using [CSS highlight](https://developer.mozilla.org/en-US/docs/Web/CSS/::highlight)\n\n## How to use\n\n### Highlight style\n\nAdd style by specify the custom-highlight-name\n\n```css\n::highlight(example-highlight-name) {\n  color: black;\n  background-color: #fed330;\n}\n```\n\n### Create highlighter\n\nCreate `Highlighter` by specify the custom-highlight-name\n\n```javascript\nimport { Highlighter } from 'krt-text-highlighter'\n\n// The root is any element inside which you want the highlight to work\nconst $root = document.getElementById('example-root')\nconst highlighter = new Highlighter('example-highlight-name')\n\nhighlighter.attach($root) // attach the root\nhighlighter.highlight(['example', 'words']) // highlight words\n```\n\n### Ignoring elements\n\nSpecify the css-selector with the second argument. \\\nBy default `[data-nohls]`\n\n```html\n\u003c!-- file.html --\u003e\n    \u003cdiv id=\"example-root\"\u003e\n      \u003cp\u003e\n        \u003cb data-nohls\u003eHighlight:\u003c/b\u003e \u003c!-- Ignored --\u003e\n        Any text can be highlighted\u003c/span\u003e\n      \u003c/p\u003e\n      \u003cp\u003e\n        \u003cb data-nohls\u003eExclude:\u003c/b\u003e\u003c!-- Ignored --\u003e\n        \u003cspan data-nohls\u003eAny text can be excluded for highlighting\u003c/span\u003e \u003c!-- Ignored --\u003e\n      \u003c/p\u003e\n    \u003c/div\u003e\n```\n\n```js\n// file.js\nconst highlighter = new Highlighter('example-highlight-name', '[data-nohls]') // by default [data-nohls]\n\nhighlighter.attach($root)\nhighlighter.highlight(['example', 'words'])\n```\n\n## [Example](./example)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkrtninja%2Fkrt-text-highlighter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkrtninja%2Fkrt-text-highlighter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkrtninja%2Fkrt-text-highlighter/lists"}