{"id":13693696,"url":"https://github.com/sourcegraph/syntaxhighlight","last_synced_at":"2025-05-02T22:30:26.993Z","repository":{"id":13585005,"uuid":"16277678","full_name":"sourcegraph/syntaxhighlight","owner":"sourcegraph","description":"Go package for syntax highlighting of code","archived":false,"fork":false,"pushed_at":"2023-05-11T16:35:08.000Z","size":79,"stargazers_count":274,"open_issues_count":4,"forks_count":21,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-04-24T00:48:51.918Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sourcegraph.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}},"created_at":"2014-01-27T11:53:38.000Z","updated_at":"2025-03-03T02:56:53.000Z","dependencies_parsed_at":"2024-01-13T22:55:09.883Z","dependency_job_id":"e41c5165-541b-4cac-a553-a83490e2145f","html_url":"https://github.com/sourcegraph/syntaxhighlight","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sourcegraph%2Fsyntaxhighlight","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sourcegraph%2Fsyntaxhighlight/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sourcegraph%2Fsyntaxhighlight/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sourcegraph%2Fsyntaxhighlight/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sourcegraph","download_url":"https://codeload.github.com/sourcegraph/syntaxhighlight/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252115827,"owners_count":21697252,"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-02T17:01:15.620Z","updated_at":"2025-05-02T22:30:26.068Z","avatar_url":"https://github.com/sourcegraph.png","language":"Go","funding_links":[],"categories":["开源类库","Open source library"],"sub_categories":["文本处理","Word Processing"],"readme":"# syntaxhighlight\n\nPackage syntaxhighlight provides syntax highlighting for code. It currently uses a language-independent lexer and performs decently on JavaScript, Java, Ruby, Python, Go, and C.\n\nThe main [`AsHTML(src []byte) ([]byte, error)`](https://sourcegraph.com/sourcegraph.com/sourcegraph/syntaxhighlight@master/.GoPackage/sourcegraph.com/sourcegraph/syntaxhighlight/.def/AsHTML) function outputs HTML that uses the same CSS classes as [google-code-prettify](https://code.google.com/p/google-code-prettify/), so any stylesheets for that should also work with this package.\n\n**[Documentation on Sourcegraph](https://sourcegraph.com/github.com/sourcegraph/syntaxhighlight)**\n\n[![Build Status](https://travis-ci.org/sourcegraph/syntaxhighlight.png?branch=master)](https://travis-ci.org/sourcegraph/syntaxhighlight)\n[![status](https://sourcegraph.com/api/repos/github.com/sourcegraph/syntaxhighlight/badges/status.png)](https://sourcegraph.com/github.com/sourcegraph/syntaxhighlight)\n\n## Installation\n\n```\ngo get -u github.com/sourcegraph/syntaxhighlight\n```\nFirst you should install the golang evironment, you can download it [here](https://golang.org/dl) or you can follow the [getting started](https://golang.org/doc/install)\n\nRemember you should set the environment variables correctly (GOPATH and PATH)\n\n## Example usage\n\nThe function [`AsHTML(src []byte, options ...Option) ([]byte, error)`](https://sourcegraph.com/sourcegraph.com/sourcegraph/syntaxhighlight@master/.GoPackage/sourcegraph.com/sourcegraph/syntaxhighlight/.def/AsHTML) returns an HTML-highlighted version of `src`. The input source code can be in any language; the lexer is language independent. An `OrderedList()` option can be passed to produce an `\u003col\u003e...\u003c/ol\u003e`-wrapped list to display line numbers.\n\n```go\npackage syntaxhighlight_test\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\n\t\"github.com/sourcegraph/syntaxhighlight\"\n)\n\nfunc Example() {\n\tsrc := []byte(`\n/* hello, world! */\nvar a = 3;\n\n// b is a cool function\nfunction b() {\n  return 7;\n}`)\n\n\thighlighted, err := syntaxhighlight.AsHTML(src)\n\tif err != nil {\n\t\tfmt.Println(err)\n\t\tos.Exit(1)\n\t}\n\n\tfmt.Println(string(highlighted))\n\n\t// Output:\n\t// \u003cspan class=\"com\"\u003e/* hello, world! */\u003c/span\u003e\n\t// \u003cspan class=\"kwd\"\u003evar\u003c/span\u003e \u003cspan class=\"pln\"\u003ea\u003c/span\u003e \u003cspan class=\"pun\"\u003e=\u003c/span\u003e \u003cspan class=\"dec\"\u003e3\u003c/span\u003e\u003cspan class=\"pun\"\u003e;\u003c/span\u003e\n\t//\n\t// \u003cspan class=\"com\"\u003e// b is a cool function\u003c/span\u003e\n\t// \u003cspan class=\"kwd\"\u003efunction\u003c/span\u003e \u003cspan class=\"pln\"\u003eb\u003c/span\u003e\u003cspan class=\"pun\"\u003e(\u003c/span\u003e\u003cspan class=\"pun\"\u003e)\u003c/span\u003e \u003cspan class=\"pun\"\u003e{\u003c/span\u003e\n\t//   \u003cspan class=\"kwd\"\u003ereturn\u003c/span\u003e \u003cspan class=\"dec\"\u003e7\u003c/span\u003e\u003cspan class=\"pun\"\u003e;\u003c/span\u003e\n\t// \u003cspan class=\"pun\"\u003e}\u003c/span\u003e\n}\n```\n\n## Contributors\n\n* [Quinn Slack](https://sourcegraph.com/sqs)\n\nContributions are welcome! Submit a pull request on GitHub.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsourcegraph%2Fsyntaxhighlight","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsourcegraph%2Fsyntaxhighlight","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsourcegraph%2Fsyntaxhighlight/lists"}