{"id":25582820,"url":"https://github.com/andreruffert/syntax-highlight-element","last_synced_at":"2025-06-21T06:36:46.211Z","repository":{"id":277088595,"uuid":"931295844","full_name":"andreruffert/syntax-highlight-element","owner":"andreruffert","description":"👓 Syntax Highlighting using the CSS Custom Highlight API","archived":false,"fork":false,"pushed_at":"2025-05-09T08:57:45.000Z","size":1574,"stargazers_count":40,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-09T14:06:38.152Z","etag":null,"topics":["custom-elements","syntax-highlighting","web-components"],"latest_commit_sha":null,"homepage":"https://andreruffert.github.io/syntax-highlight-element/","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/andreruffert.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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,"zenodo":null},"funding":{"github":["andreruffert"],"custom":["https://paypal.me/andreruffert","https://thx.to/:andre"]}},"created_at":"2025-02-12T03:16:37.000Z","updated_at":"2025-05-27T12:20:15.000Z","dependencies_parsed_at":"2025-02-12T04:29:38.850Z","dependency_job_id":"8be95c92-c612-4fd2-a661-704fa51441b5","html_url":"https://github.com/andreruffert/syntax-highlight-element","commit_stats":null,"previous_names":["andreruffert/syntax-highlight-element"],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/andreruffert/syntax-highlight-element","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreruffert%2Fsyntax-highlight-element","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreruffert%2Fsyntax-highlight-element/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreruffert%2Fsyntax-highlight-element/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreruffert%2Fsyntax-highlight-element/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/andreruffert","download_url":"https://codeload.github.com/andreruffert/syntax-highlight-element/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreruffert%2Fsyntax-highlight-element/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261080048,"owners_count":23106560,"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":["custom-elements","syntax-highlighting","web-components"],"created_at":"2025-02-21T05:19:06.499Z","updated_at":"2025-06-21T06:36:41.191Z","avatar_url":"https://github.com/andreruffert.png","language":"JavaScript","funding_links":["https://github.com/sponsors/andreruffert","https://paypal.me/andreruffert","https://thx.to/:andre"],"categories":["JavaScript"],"sub_categories":[],"readme":"# \u0026lt;syntax-highlight\u0026gt; element\n\n\u003e Syntax Highlighting using the CSS Custom Highlight API.\n\n[![Test status](https://img.shields.io/github/actions/workflow/status/andreruffert/syntax-highlight-element/test.yml?label=Test\u0026logo=github\u0026color=32A9C3\u0026labelColor=1B3C4A)](https://github.com/andreruffert/syntax-highlight-element/actions/workflows/test.yml)\n[![npm version](https://img.shields.io/npm/v/syntax-highlight-element?color=32A9C3\u0026labelColor=1B3C4A)](https://www.npmjs.com/package/syntax-highlight-element)\n[![npm downloads](https://img.shields.io/npm/dm/syntax-highlight-element?logo=npm\u0026color=32A9C3\u0026labelColor=1B3C4A)](https://www.npmjs.com/package/syntax-highlight-element)\n\nThe code is highlighted without having to wrap a bunch of `\u003cspan\u003e` elements around each token, thanks to [Prism][prism_github]'s tokenizer and the [CSS Custom Highlight API][MDN_CSS_Custom_Highlight_API].\n\n\u003cdiv align=\"center\"\u003e\n  \u003cbr\u003e\n  \u003cbr\u003e\n  \u003cimg src=\"media/cover.png\" alt=\"Screenshot of the \u003csyntax-highlight\u003e element demo in the browser with DevTools open\"\u003e\n  \u003cbr\u003e\n  \u003cbr\u003e\n\u003c/div\u003e\n\n## Install\n\nInstall via npm\n\n```shell\nnpm install syntax-highlight-element\n```\n\n## Usage\n\n### JavaScript\n\nImport as ES module\n\n```js\nimport 'syntax-highlight-element';\n```\n\nOr via CDN\n\n```html\n\u003cscript type=\"module\" src=\"https://cdn.jsdelivr.net/npm/syntax-highlight-element/+esm\"\u003e\u003c/script\u003e\n```\n\n### HTML\n\n```html\n\u003csyntax-highlight language=\"js\"\u003e\n  // ... \n\u003c/syntax-highlight\u003e\n```\n\n### CSS\n\nMake sure to load a theme e.g. `syntax-highlight-element/themes/prettylights.css`.\n\nOr via CDN\n\n```html\n\u003clink rel=\"stylesheet\" href=\"https://cdn.jsdelivr.net/npm/syntax-highlight-element/dist/themes/prettylights.min.css\"\u003e\n```\n\nCurrently there are only limited [themes](https://github.com/andreruffert/syntax-highlight-element/tree/main/src/themes) available/converted. You can always create your own theme. Contributions are also very welcome.\n\n## Attributes\n\n* `language` The code language. The default is `plaintext`. Default suported languages `html|css|js`.\n* `content-selector` A CSS selector to specify the content element. The default is the element itself.\n\n## Configuration\n```js\n/**\n * @typedef Config\n * @type {object}\n * @property {string[]} [languages=['markup', 'css', 'javascript']] - Language grammars to highlight.\n * @property {{ [key: string]: string[] }} languageTokens - Language specific token types.\n */\nwindow.she = window.she || {};\n/** @type {Config} */\nwindow.she.config = {};\n```\n\nFull list of all [languages supported](https://prismjs.com/#supported-languages) by the prism tokenizer.\n\n## Browser Support\n\n\u003cpicture\u003e\n  \u003csource media=\"(prefers-color-scheme: dark)\" srcset=\"https://web-platform-dx.github.io/web-features/assets/img/baseline-limited-word-dark.svg\"\u003e\n  \u003cimg src=\"https://web-platform-dx.github.io/web-features/assets/img/baseline-limited-word.svg\" width=\"224\" height=\"63\" alt=\"Baseline limited availability wordmark\"\u003e\n\u003c/picture\u003e\n\n- [CSS Custom Highlight API][caniuse_mdn-api_highlight]\n\n## Credits\n\n* [Bramus Van Damme][bramus_github] and his [blog post][bramus_blog_post] where I first read about using the [CSS Custom Highlight API][MDN_CSS_Custom_Highlight_API] for syntax highlighting.\n* [Prism][prism_github]'s tokenizer.\n\n## License\n\nDistributed under the MIT license. See LICENSE for details. \n\n© [André Ruffert](https://andreruffert.com)\n\n[prism_github]: https://github.com/PrismJS/prism\n[bramus_github]: https://github.com/bramus\n[bramus_blog_post]: https://www.bram.us/2024/02/18/custom-highlight-api-for-syntax-highlighting\n[MDN_CSS_Custom_Highlight_API]: https://developer.mozilla.org/en-US/docs/Web/API/CSS_Custom_Highlight_API\n[caniuse_mdn-api_highlight]: https://caniuse.com/mdn-api_highlight\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandreruffert%2Fsyntax-highlight-element","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandreruffert%2Fsyntax-highlight-element","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandreruffert%2Fsyntax-highlight-element/lists"}