{"id":13617173,"url":"https://github.com/sensiolabs/ansi-to-html","last_synced_at":"2025-04-14T04:56:59.312Z","repository":{"id":7522505,"uuid":"8873487","full_name":"sensiolabs/ansi-to-html","owner":"sensiolabs","description":"An ANSI to HTML5 converter","archived":false,"fork":false,"pushed_at":"2025-03-15T17:35:32.000Z","size":50,"stargazers_count":245,"open_issues_count":10,"forks_count":33,"subscribers_count":13,"default_branch":"master","last_synced_at":"2025-03-23T23:02:36.214Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/sensiolabs.png","metadata":{"files":{"readme":"README.md","changelog":null,"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}},"created_at":"2013-03-19T07:58:18.000Z","updated_at":"2025-03-23T22:40:50.000Z","dependencies_parsed_at":"2025-01-19T15:02:04.588Z","dependency_job_id":"70773eed-f81f-413f-a1dd-fd286259dcdb","html_url":"https://github.com/sensiolabs/ansi-to-html","commit_stats":{"total_commits":19,"total_committers":11,"mean_commits":"1.7272727272727273","dds":0.5263157894736843,"last_synced_commit":"7a6c16623c02bdbcbe907ab2abcf465ebb31db72"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sensiolabs%2Fansi-to-html","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sensiolabs%2Fansi-to-html/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sensiolabs%2Fansi-to-html/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sensiolabs%2Fansi-to-html/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sensiolabs","download_url":"https://codeload.github.com/sensiolabs/ansi-to-html/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245284719,"owners_count":20590307,"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":[],"created_at":"2024-08-01T20:01:37.881Z","updated_at":"2025-03-31T01:02:18.284Z","avatar_url":"https://github.com/sensiolabs.png","language":"PHP","funding_links":[],"categories":["PHP","字符串","目录","Table of Contents","Strings","Text and Numbers","字符串( Strings )","字符串 Strings"],"sub_categories":["字符串 Strings","Strings","Library"],"readme":"ANSI to HTML5 Converter\n=======================\n\nThis small library only does one thing: converting a text containing ANSI\ncodes to an HTML5 fragment:\n\n```php\nrequire_once __DIR__.'/vendor/autoload.php';\n\nuse SensioLabs\\AnsiConverter\\AnsiToHtmlConverter;\n\n$converter = new AnsiToHtmlConverter();\n\n$html = $converter-\u003econvert($ansi);\n```\n\nThe `$ansi` variable should contain a text with ANSI codes, and `$html` will\ncontain the converted HTML5 version of it.\n\nYou can then output the HTML5 fragment in any HTML document:\n\n```html+php\n\u003chtml\u003e\n    \u003cbody\u003e\n        \u003cpre style=\"background-color: black; overflow: auto; padding: 10px 15px; font-family: monospace;\"\n        \u003e\u003c?php echo $html ?\u003e\u003c/pre\u003e\n    \u003c/body\u003e\n\u003c/html\u003e\n```\n\nThe converter supports different color themes:\n\n```php\nuse SensioLabs\\AnsiConverter\\Theme\\SolarizedTheme;\n\n$theme = new SolarizedTheme();\n$converter = new AnsiToHtmlConverter($theme);\n```\n\nBy default, the colors are inlined into the HTML, but you can also use classes\nby turning off style inlining:\n\n```php\n$converter = new AnsiToHtmlConverter($theme, false);\n```\n\nAnd the `asCss()` method of the theme object lets you retrieve the theme styles\nas a CSS snippet:\n\n```php\n$styles = $theme-\u003easCss();\n```\n\nwhich you can then use in your HTML document:\n\n```html+php\n\u003chtml\u003e\n    \u003chead\u003e\n        \u003cstyle\u003e\n            \u003c?php echo $styles ?\u003e\n\n            .ansi_box { overflow: auto; padding: 10px 15px; font-family: monospace; }\n        \u003c/style\u003e\n    \u003c/head\u003e\n    \u003cbody\u003e\n        \u003cpre class=\"ansi_color_bg_black ansi_color_fg_white ansi_box\"\u003e\u003c?php echo $html ?\u003e\u003c/pre\u003e\n    \u003c/body\u003e\n\u003c/html\u003e\n```\n\nTwig Integration\n----------------\n\nRegister the extension:\n\n```php\nuse SensioLabs\\AnsiConverter\\Bridge\\Twig\\AnsiExtension;\n\n$twig-\u003eaddExtension(AnsiExtension());\n```\n\nIt's possible to use a custom ``AnsiToHtmlConverter``:\n\n```php\nuse SensioLabs\\AnsiConverter\\Bridge\\Twig\\AnsiExtension;\nuse SensioLabs\\AnsiConverter\\Theme\\SolarizedTheme;\n\n$theme = new SolarizedTheme();\n$converter = new AnsiToHtmlConverter($theme, false);\n\n$twig-\u003eaddExtension(new AnsiExtension($converter));\n```\n\nThen:\n\n```jinja\n\u003chtml\u003e\n    \u003chead\u003e\n        \u003cstyle\u003e\n            {# This is only need if the inline styling is disabled #}\n            {{ ansi_css }}\n        \u003c/style\u003e\n    \u003c/head\u003e\n    \u003cbody\u003e\n        {{ some_ansi_code|ansi_to_html }}\n    \u003c/body\u003e\n\u003c/html\u003e\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsensiolabs%2Fansi-to-html","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsensiolabs%2Fansi-to-html","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsensiolabs%2Fansi-to-html/lists"}