{"id":36987132,"url":"https://github.com/demyanovs/php-highlight","last_synced_at":"2026-01-13T23:06:08.085Z","repository":{"id":56965327,"uuid":"155549194","full_name":"demyanovs/php-highlight","owner":"demyanovs","description":"A PHP library for highlighting code syntax.","archived":false,"fork":false,"pushed_at":"2025-11-21T15:11:52.000Z","size":325,"stargazers_count":7,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-11-21T16:22:25.943Z","etag":null,"topics":["codehighlighter","codehighlighting","php","syntax-highlighting"],"latest_commit_sha":null,"homepage":"https://packagist.org/packages/demyanovs/php-highlight","language":"PHP","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/demyanovs.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","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,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2018-10-31T11:51:50.000Z","updated_at":"2025-11-21T14:58:46.000Z","dependencies_parsed_at":"2022-08-21T10:20:58.490Z","dependency_job_id":null,"html_url":"https://github.com/demyanovs/php-highlight","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/demyanovs/php-highlight","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/demyanovs%2Fphp-highlight","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/demyanovs%2Fphp-highlight/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/demyanovs%2Fphp-highlight/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/demyanovs%2Fphp-highlight/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/demyanovs","download_url":"https://codeload.github.com/demyanovs/php-highlight/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/demyanovs%2Fphp-highlight/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28403763,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-13T21:51:37.118Z","status":"ssl_error","status_checked_at":"2026-01-13T21:45:14.585Z","response_time":56,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: 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":["codehighlighter","codehighlighting","php","syntax-highlighting"],"created_at":"2026-01-13T23:06:07.351Z","updated_at":"2026-01-13T23:06:08.079Z","avatar_url":"https://github.com/demyanovs.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PHPHighlight\n\nPHPHighlight is a PHP syntax highlighting library that can be easily customized and extended.\n\n## How it works\nThe library parses the text, finds the `\u003cpre\u003e` and `\u003cpre\u003e\u003ccode\u003e` tags, reads the attributes (data-lang, data-file, data-theme) and highlights the syntax of the code block.\n\n**Recommended:** Use `\u003cpre\u003e\u003ccode\u003e` pattern for better semantics and compatibility with Markdown output.\n\nSupports style customization. Here are examples of styling:\n\n\u003cimg width=\"757\" height=\"309\" src=\"examples/img/scr_01.png\" alt=\"styling example\"\u003e\n\n## Requirements\nPHP 8.1+\n\n## Installation\nYou can install package via composer\n```bash\n$ composer require demyanovs/php-highlight\n```\n\n## Usage\nSee full example in [examples/index.php](examples/index.php)\n```php\n\u003c?php\n\nrequire_once 'vendor/autoload.php';\n\nuse Demyanovs\\PHPHighlight\\Highlighter;\nuse Demyanovs\\PHPHighlight\\Themes\\ObsidianTheme;\n\n$text = '\n\u003cpre\u003e\u003ccode class=\"language-php\" data-file=\"php-highlight/examples/index.php\"\u003e\n\u0026lt;?php\nabstract class AbstractClass\n{\n    /**\n     * Our abstract method only needs to define the required arguments\n     */\n    abstract protected function prefixName(string $name): string;\n}\n\nclass ConcreteClass extends AbstractClass\n{\n    /**\n     * Our child class may define optional arguments not in the parent\\'s signature\n     */\n    public function prefixName(string $name): string\n    {\n        $prefix = \"\";\n        if ($name === \"Pacman\") {\n            $prefix = \"Mr.\";\n        } elseif ($name === \"Pacwoman\") {\n            $prefix = \"Mrs.\";\n        } else {\n            \n        }\n        \n        return $prefix . \" \" . $name;\n    }\n}\n\n$class = new ConcreteClass;\necho $class-\u003eprefixName(\"Pacman\"), \"\\n\";\necho $class-\u003eprefixName(\"Pacwoman\"), \"\\n\";\n\u003c/code\u003e\u003c/pre\u003e\n';\n\n$highlighter = (new Highlighter($text, ObsidianTheme::TITLE))\n        -\u003eshowLineNumbers(true)\n        -\u003eshowActionPanel(true);\necho $highlighter-\u003eparse();\n```\n\n### Customization\n```php\n$highlighter-\u003eshowLineNumbers(true);\n$highlighter-\u003eshowActionPanel(true);\n```\n\nYou can set following attributes in `\u003cpre\u003e` or `\u003ccode\u003e` tags:\n```html\n\u003cpre\u003e\u003ccode class=\"language-php\" data-file=\"example.php\" data-theme=\"darkula\"\u003e\n// or\n\u003cpre data-lang=\"php\" data-file=\"example.php\" data-theme=\"darkula\"\u003e\u003ccode\u003e\n```\n\n* `data-lang` or `class=\"language-*\"` - a language of the text. This affects how the parser will highlight the syntax.\n* `data-file` - show file name in action panel.\n* `data-theme` - allows to overwrite the global theme.\n\n**Note:** `class=\"language-*\"` on `\u003ccode\u003e` tag is automatically recognized (common in Markdown output).\n\n### How to create a custom theme\nTo create a custom theme you need to create an instance of `Demyanovs\\PHPHighlight\\Themes\\Theme` class\nand pass it to Highlighter as a third argument:\n```php\nuse Demyanovs\\PHPHighlight\\Highlighter;\nuse Demyanovs\\PHPHighlight\\Themes\\Theme;\nuse Demyanovs\\PHPHighlight\\Themes\\Dto\\DefaultColorSchemaDto;\nuse Demyanovs\\PHPHighlight\\Themes\\Dto\\PHPColorSchemaDto;\nuse Demyanovs\\PHPHighlight\\Themes\\Dto\\XMLColorSchemaDto;\n\n$defaultColorSchemaDto = new DefaultColorSchemaDto(\n    '#000000', // background\n    '#ffffff', // default text\n    '#888888', // comment\n    '#ff0000', // keyword\n    '#00ff00', // string\n    '#0000ff', // number\n    '#ffff00'  // variable\n);\n\n$PHPColorSchemaDto = new PHPColorSchemaDto(\n    '#0000BB', // keyword\n    '#FF8000', // variable\n    '#fbc201', // function\n    '#007700', // string\n    '#DD0000'  // comment\n);\n\n$XMLColorSchemaDto = new XMLColorSchemaDto(\n    '#008000', // tag\n    '#7D9029', // attribute\n    '#BA2121', // string\n    '#BC7A00'  // comment\n);\n\n$myTheme = new Theme(\n    'myThemeTitle',\n    $defaultColorSchemaDto,\n    $PHPColorSchemaDto,\n    $XMLColorSchemaDto\n);\n\n$highlighter = new Highlighter($text, 'myThemeTitle', [$myTheme]);\n```\n\n### Supports language syntax\n* PHP\n* JavaScript\n* XML/HTML\n* Bash\n* Go\n* and others\n\n### Themes\n* default\n* darkula\n* railscasts\n* obsidian\n* far\n* vs2015\n* c64\n\n## Contributing\nPull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.\n\nPlease make sure to update tests as appropriate.\n\n## Changelog\nSee [CHANGELOG.md](./CHANGELOG.md) for a list of changes and version history.\n\n## License\n[MIT](./LICENSE.md)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdemyanovs%2Fphp-highlight","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdemyanovs%2Fphp-highlight","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdemyanovs%2Fphp-highlight/lists"}