{"id":13828405,"url":"https://github.com/spatie/commonmark-highlighter","last_synced_at":"2025-04-05T09:06:39.596Z","repository":{"id":48108594,"uuid":"159513310","full_name":"spatie/commonmark-highlighter","owner":"spatie","description":"Highlight code blocks with league/commonmark","archived":false,"fork":false,"pushed_at":"2022-07-25T17:41:45.000Z","size":58,"stargazers_count":134,"open_issues_count":0,"forks_count":10,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-29T08:06:20.750Z","etag":null,"topics":["commonmark","highlight"],"latest_commit_sha":null,"homepage":"https://spatie.be/open-source","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/spatie.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}},"created_at":"2018-11-28T14:18:42.000Z","updated_at":"2025-01-16T06:31:52.000Z","dependencies_parsed_at":"2022-08-12T18:50:12.569Z","dependency_job_id":null,"html_url":"https://github.com/spatie/commonmark-highlighter","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spatie%2Fcommonmark-highlighter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spatie%2Fcommonmark-highlighter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spatie%2Fcommonmark-highlighter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spatie%2Fcommonmark-highlighter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/spatie","download_url":"https://codeload.github.com/spatie/commonmark-highlighter/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247312077,"owners_count":20918344,"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":["commonmark","highlight"],"created_at":"2024-08-04T09:02:45.019Z","updated_at":"2025-04-05T09:06:39.564Z","avatar_url":"https://github.com/spatie.png","language":"PHP","funding_links":[],"categories":["PHP"],"sub_categories":[],"readme":"\n[\u003cimg src=\"https://github-ads.s3.eu-central-1.amazonaws.com/support-ukraine.svg?t=1\" /\u003e](https://supportukrainenow.org)\n\n# Highlight your markdown code blocks with league/commonmark\n\n[![Latest Version](https://img.shields.io/github/release/spatie/commonmark-highlighter.svg?style=flat-square)](https://github.com/spatie/commonmark-highlighter/releases)\n[![Build Status](https://img.shields.io/github/workflow/status/spatie/commonmark-highlighter/Tests.svg?style=flat-square)](https://github.com/spatie/commonmark-highlighter/actions)\n[![Quality Score](https://img.shields.io/scrutinizer/g/spatie/commonmark-highlighter.svg?style=flat-square)](https://scrutinizer-ci.com/g/spatie/commonmark-highlighter)\n[![StyleCI](https://styleci.io/repos/159513310/shield)](https://styleci.io/repos/159513310)\n[![Total Downloads](https://img.shields.io/packagist/dt/spatie/commonmark-highlighter.svg?style=flat-square)](https://packagist.org/packages/spatie/commonmark-highlighter)\n\nA block renderer for  [league/commonmark](https://github.com/thephpleague/commonmark) to highlight code blocks using [scrivo/highlight.php](https://github.com/scrivo/highlight.php).\n\n\u003e highlight.php is a server side code highlighter written in PHP that currently supports 185 languages. It's a port of highlight.js by Ivan Sagalaev that makes full use of the language and style definitions of the original JavaScript project.\n\nThe output html is compatible with highlight.js themes, which you can explore on [highlightjs.org](https://highlightjs.org/static/demo/). \n\nWhat are the benefits of using this package over highlight.js?\n\n- Less JavaScript, which means faster page loads\n- No more flash of unstyled code blocks\n\n This project was inspired by [sixlive/parsedown-highlight](https://github.com/sixlive/parsedown-highlight).\n\n## Support us\n\n[\u003cimg src=\"https://github-ads.s3.eu-central-1.amazonaws.com/commonmark-highlighter.jpg?t=1\" width=\"419px\" /\u003e](https://spatie.be/github-ad-click/commonmark-highlighter)\n\nWe invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).\n\nWe highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).\n\n## Installation\n\nYou can install the package via composer:\n\n```bash\ncomposer require spatie/commonmark-highlighter\n```\n\n## Usage\n\nCreate a custom CommonMark environment, and register the `FencedCodeRenderer` and `IndentedCodeRender` as described in the [league/commonmark documentation](https://commonmark.thephpleague.com/customization/block-rendering/).\n\n```php\nuse League\\CommonMark\\Environment\\Environment;\nuse League\\CommonMark\\Extension\\CommonMark\\CommonMarkCoreExtension;\nuse League\\CommonMark\\Extension\\CommonMark\\Node\\Block\\FencedCode;\nuse League\\CommonMark\\Extension\\CommonMark\\Node\\Block\\IndentedCode;\nuse League\\CommonMark\\MarkdownConverter;\nuse Spatie\\CommonMarkHighlighter\\FencedCodeRenderer;\nuse Spatie\\CommonMarkHighlighter\\IndentedCodeRenderer;\n\n$environment = new Environment();\n$environment-\u003eaddExtension(new CommonMarkCoreExtension());\n$environment-\u003eaddRenderer(FencedCode::class, new FencedCodeRenderer());\n$environment-\u003eaddRenderer(IndentedCode::class, new IndentedCodeRenderer());\n\n$markdownConverter = new MarkdownConverter($environment);\n\necho $markdownConverter-\u003econvertToHtml($markdown);\n```\n\nThe underlying highlight library recommends specifying a subset of languages for the auto-detection. You can pass an array of languages to any of the renderers.\n\n```php\nnew FencedCodeRenderer(['html', 'php', 'js']);\n\nnew IndentedCodeRenderer(['html', 'php', 'js']);\n```\n\n### Highlighting specific lines\n\nLine numbers start at 1.\n\n\\`\\`\\`php - Don't highlight any lines  \n\\`\\`\\`php{4} - Highlight just line 4  \n\\`\\`\\`php{4-6} - Highlight the range of lines from 4 to 6 (inclusive)  \n\\`\\`\\`php{1,5} - Highlight just lines 1 and 5 on their own  \n\\`\\`\\`php{1-3,5} - Highlight 1 through 3 and then 5 on its own  \n\\`\\`\\`php{5,7,2-3} - The order of lines don't matter  \nHowever, specifying 3-2 will not work.  \n\n### Testing\n\n``` bash\ncomposer test\n```\n\n### Changelog\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.\n\n## Contributing\n\nPlease see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details.\n\n### Security\n\nIf you've found a bug regarding security please mail [security@spatie.be](mailto:security@spatie.be) instead of using the issue tracker.\n\n## Postcardware\n\nYou're free to use this package, but if it makes it to your production environment we highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using.\n\nOur address is: Spatie, Kruikstraat 22, 2018 Antwerp, Belgium.\n\nWe publish all received postcards [on our company website](https://spatie.be/en/opensource/postcards).\n\n## Credits\n\n- [Sebastian De Deyne](https://github.com/sebastiandedeyne)\n- [All Contributors](../../contributors)\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspatie%2Fcommonmark-highlighter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fspatie%2Fcommonmark-highlighter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspatie%2Fcommonmark-highlighter/lists"}