{"id":20857727,"url":"https://github.com/the-best-codes/best-highlight","last_synced_at":"2025-04-10T21:09:40.879Z","repository":{"id":263033632,"uuid":"889083334","full_name":"The-Best-Codes/best-highlight","owner":"The-Best-Codes","description":"best-highlight is a lightweight, efficient syntax highlighting library with zero runtime dependencies","archived":false,"fork":false,"pushed_at":"2025-03-26T03:06:44.000Z","size":86,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-10T21:09:32.361Z","etag":null,"topics":["code","fast","high-performance","highlight","highlighting","lightweight","standalone","syntax","syntax-highlighting","zero-dependency"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/The-Best-Codes.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-11-15T15:22:25.000Z","updated_at":"2025-03-26T03:06:10.000Z","dependencies_parsed_at":"2024-11-15T18:32:54.906Z","dependency_job_id":"d9a12515-2409-4c40-89a8-227051a1ed2f","html_url":"https://github.com/The-Best-Codes/best-highlight","commit_stats":null,"previous_names":["the-best-codes/best-highlight"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/The-Best-Codes%2Fbest-highlight","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/The-Best-Codes%2Fbest-highlight/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/The-Best-Codes%2Fbest-highlight/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/The-Best-Codes%2Fbest-highlight/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/The-Best-Codes","download_url":"https://codeload.github.com/The-Best-Codes/best-highlight/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248298334,"owners_count":21080320,"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":["code","fast","high-performance","highlight","highlighting","lightweight","standalone","syntax","syntax-highlighting","zero-dependency"],"created_at":"2024-11-18T04:42:33.852Z","updated_at":"2025-04-10T21:09:40.874Z","avatar_url":"https://github.com/The-Best-Codes.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# best-highlight\n\n\u003cimg alt=\"Best Highlight Logo\" src=\"https://github.com/user-attachments/assets/b6d7abd3-e893-41dc-b46e-45c147c9a026\" for=\"cover\" width=\"300\" /\u003e\n\n[npm Library](https://npmjs.com/package/best-highlight)\n\nA lightweight, efficient syntax highlighting library with zero runtime dependencies. Supports both CommonJS and ES Modules, perfect for both browser and Node.js environments.\n\n## Features\n\n- 🚀 Zero runtime dependencies\n- 📦 Tiny bundle size\n- 🎨 Multiple themes (Light, Dark, Nord, GitHub)\n- 🔧 First-class TypeScript support\n- 🌐 Universal compatibility (Browser, Node.js)\n- ⚡ Fast and reliable tokenization using optimized scanner\n- 🎯 Support for 7 popular languages with comprehensive test coverage\n\n## Installation\n\n```bash\nnpm install best-highlight\n```\n\n## Browser Usage\n\nTo use the library in a browser environment:\n\n1. Include the library in your HTML file:\n\n```html\n\u003cscript src=\"https://cdn.jsdelivr.net/npm/best-highlight@latest/dist/browser/index.global.js\"\u003e\u003c/script\u003e\n```\n\n2. Use the global `bestHighlight` function to highlight code:\n\n```javascript\nbestHighlight.highlight(\n  'function hello() {\\n  console.log(\"Hello, World!\");\\n}',\n  \"javascript\",\n);\n```\n\n3. Write your own styles or use the provided themes:\n\n```html\n\u003clink\n  rel=\"stylesheet\"\n  href=\"https://cdn.jsdelivr.net/npm/best-highlight@latest/dist/themes/light.css\"\n/\u003e\n```\n\nExample:\n\n```html\n\u003chtml\u003e\n  \u003chead\u003e\n    \u003clink\n      rel=\"stylesheet\"\n      href=\"https://cdn.jsdelivr.net/npm/best-highlight@latest/dist/themes/light.css\"\n    /\u003e\n    \u003cscript src=\"https://cdn.jsdelivr.net/npm/best-highlight@latest/dist/browser/index.global.js\"\u003e\u003c/script\u003e\n  \u003c/head\u003e\n  \u003cbody\u003e\n    \u003cpre data-language=\"javascript\" id=\"code\"\u003e\n      function hello() {\n        console.log(\"Hello, World!\");\n      }\n    \u003c/pre\u003e\n    \u003cscript\u003e\n      document.addEventListener(\"DOMContentLoaded\", () =\u003e {\n        bestHighlight.highlightElement(document.getElementById(\"code\"));\n      });\n    \u003c/script\u003e\n  \u003c/body\u003e\n\u003c/html\u003e\n```\n\n## Usage\n\n### Basic Usage\n\n```javascript\nimport { highlight } from \"best-highlight\";\n\nconst code = `function hello() {\n  console.log(\"Hello, World!\");\n}`;\n\nconst html = highlight(code, \"javascript\");\n```\n\n### DOM Element Highlighting\n\n```javascript\nimport { highlightElement } from \"best-highlight\";\n\n// Highlight a pre element\nconst element = document.querySelector(\"pre\");\nelement.setAttribute(\"data-language\", \"javascript\");\nhighlightElement(element);\n```\n\n### Supported Languages\n\nThe library provides robust support for 7 programming languages:\n\n- JavaScript (keywords, operators, strings, comments)\n- TypeScript (with identifier preservation)\n- Python (keywords, functions, strings, comments)\n- HTML (tags, attributes, strings, comments, doctypes, entities)\n- CSS (selectors, properties, values, punctuation)\n- JSON (strings, numbers, punctuation)\n- Markdown (headings, emphasis)\n\n## Themes\n\nFour built-in themes are available:\n\n- Light (default)\n- Dark\n- Nord\n- GitHub\n\nEach theme is available as a separate CSS file in the themes directory:\n\n```css\n/* Choose one of: */\nimport 'best-highlight/themes/light.css'\nimport 'best-highlight/themes/dark.css'\nimport 'best-highlight/themes/nord.css'\nimport 'best-highlight/themes/github.css'\n```\n\n## API Reference\n\n### highlight(code: string, language: string): string\n\nHighlights code and returns HTML string with appropriate class names. Each token is wrapped in a `span` with classes `bh-npm-token` and `bh-npm-{type}`.\n\n### highlightElement(element: HTMLElement): void\n\nHighlights code within a DOM element. The element should have a `data-language` attribute specifying the language. Adds the `bh-npm-highlight` class to the element.\n\n### tokenize(code: string, language: string): Token[]\n\nLow-level API that returns an array of tokens for custom processing. Each token has:\n\n- `type`: string (e.g., 'keyword', 'string', 'comment')\n- `content`: string (the actual token content)\n\n## Testing\n\nThe library includes comprehensive test coverage for all supported languages and features:\n\n- Language-specific tokenization tests\n- HTML generation and escaping\n- DOM element highlighting\n- Theme application\n- Edge cases (empty content, unknown languages)\n\nRun tests with:\n\n```bash\nnpm test\n```\n\n## Contributing\n\nContributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.\n\n1. Fork the repository\n2. Create your feature branch (`git checkout -b feature/amazing-feature`)\n3. Commit your changes (`git commit -m 'Add some amazing feature'`)\n4. Push to the branch (`git push origin feature/amazing-feature`)\n5. Open a Pull Request\n\n## Development\n\n```bash\n# Install dependencies\nnpm install\n\n# Run tests\nnpm test\n```\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthe-best-codes%2Fbest-highlight","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthe-best-codes%2Fbest-highlight","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthe-best-codes%2Fbest-highlight/lists"}