{"id":19339722,"url":"https://github.com/rubenv/pygmentize","last_synced_at":"2025-04-23T02:30:54.014Z","repository":{"id":66156187,"uuid":"29722983","full_name":"rubenv/pygmentize","owner":"rubenv","description":"Go wrapper for pygments","archived":false,"fork":false,"pushed_at":"2015-03-23T18:56:00.000Z","size":224,"stargazers_count":9,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-02T06:43:12.318Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rubenv.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-01-23T08:07:22.000Z","updated_at":"2023-01-29T20:17:11.000Z","dependencies_parsed_at":"2023-02-19T23:20:25.238Z","dependency_job_id":null,"html_url":"https://github.com/rubenv/pygmentize","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/rubenv%2Fpygmentize","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rubenv%2Fpygmentize/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rubenv%2Fpygmentize/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rubenv%2Fpygmentize/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rubenv","download_url":"https://codeload.github.com/rubenv/pygmentize/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250357566,"owners_count":21417307,"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-11-10T03:23:30.399Z","updated_at":"2025-04-23T02:30:53.774Z","avatar_url":"https://github.com/rubenv.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# pygmentize\n\n[![Build Status](https://travis-ci.org/rubenv/pygmentize.svg?branch=master)](https://travis-ci.org/rubenv/pygmentize) [![GoDoc](https://godoc.org/github.com/rubenv/pygmentize?status.png)](https://godoc.org/github.com/rubenv/pygmentize)\n\nPygments wrapper for Go.\n\nhttp://pygments.org/\n\n\n### Quick Example\n\nTo highlight a piece of code, use:\n\n    code := `fmt.Println(\"hello world\")`\n    out, err := pygmentize.HighlightLanguage(code, \"go\", NewHtmlFormatter())\n    if err != nil {\n    \treturn err\n    }\n    fmt.Println(out)\n\nThis outputs:\n\n    \u003cspan class=\"n no\"\u003efmt\u003c/span\u003e\u003cspan class=\"p\"\u003e.\u003c/span\u003e\u003cspan class=\"n no\"\u003ePrintln\u003c/span\u003e\u003cspan class=\"p\"\u003e(\u003c/span\u003e\u003cspan class=\"l ls\"\u003e\u0026#34;hello world\u0026#34;\u003c/span\u003e\u003cspan class=\"p\"\u003e)\u003c/span\u003e\u003cspan class=\"t\"\u003e\n    \u003c/span\u003e\n\nApply CSS to your liking to get the desired visual effect.\n\n## Installation\n```\ngo get github.com/rubenv/pygmentize\n```\n\nImport into your application with:\n\n```go\nimport \"github.com/rubenv/pygmentize\"\n```\n\n## Usage\n\n```go\nvar DebugFormatter = \u0026debugFormatter{\n\tHtmlFormatter: NewHtmlFormatter(),\n}\n```\nFormatter that outputs HTML with token types as the class name.\n\n```go\nvar DefaultClasses = map[string]string{\n\t\"Comment\":                \"c\",\n\t\"Comment.Preproc\":        \"cp\",\n\t\"Comment.Single\":         \"cs\",\n\t\"Keyword\":                \"k\",\n\t\"Keyword.Constant\":       \"kc\",\n\t\"Keyword.Type\":           \"kt\",\n\t\"Literal\":                \"l\",\n\t\"Literal.Number\":         \"ln\",\n\t\"Literal.Number.Integer\": \"lni\",\n\t\"Literal.String\":         \"ls\",\n\t\"Literal.String.Double\":  \"lsd\",\n\t\"Literal.String.Single\":  \"lss\",\n\t\"Name\":                   \"n\",\n\t\"Name.Class\":             \"nc\",\n\t\"Name.Entity\":            \"ne\",\n\t\"Name.Function\":          \"nf\",\n\t\"Name.Other\":             \"no\",\n\t\"Name.Namespace\":         \"nn\",\n\t\"Name.Variable\":          \"nv\",\n\t\"Operator\":               \"o\",\n\t\"Punctuation\":            \"p\",\n\t\"Text\":                   \"t\",\n}\n```\nDefault token -\u003e class mapping.\n\n#### func  Highlight\n\n```go\nfunc Highlight(code string, formatter Formatter) (string, error)\n```\nHighlight a piece of code.\n\n#### func  HighlightLanguage\n\n```go\nfunc HighlightLanguage(code, language string, formatter Formatter) (string, error)\n```\nHighlight a piece of code, with a given language.\n\nSee http://pygments.org/docs/lexers/ for a list of languages (look under \"Short\nnames\").\n\n#### type Formatter\n\n```go\ntype Formatter interface {\n\tFormat(token Token, input string) (string, error)\n}\n```\n\n\n#### type HtmlFormatter\n\n```go\ntype HtmlFormatter struct {\n\t// Maps of token types to class names\n\tClasses map[string]string\n\n\t// Prefix added to each class\n\tPrefix string\n\n\t// Fail on unmapped token types?\n\tStrict bool\n}\n```\n\nHighlights by adding \u003cspan\u003e tags.\n\n#### func  NewHtmlFormatter\n\n```go\nfunc NewHtmlFormatter() *HtmlFormatter\n```\nCreate a new HtmlFormatter with default class mapping.\n\n#### func (*HtmlFormatter) Format\n\n```go\nfunc (f *HtmlFormatter) Format(token Token, input string) (string, error)\n```\n\n#### type Token\n\n```go\ntype Token struct {\n\tType    string\n\tSubtype string\n\tDetail  string\n}\n```\n\n\n#### func (Token) String\n\n```go\nfunc (t Token) String() string\n```\n\n## License\n\n    (The MIT License)\n\n    Copyright (C) 2015 by Ruben Vermeersch \u003cruben@rocketeer.be\u003e\n\n    Permission is hereby granted, free of charge, to any person obtaining a copy\n    of this software and associated documentation files (the \"Software\"), to deal\n    in the Software without restriction, including without limitation the rights\n    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n    copies of the Software, and to permit persons to whom the Software is\n    furnished to do so, subject to the following conditions:\n\n    The above copyright notice and this permission notice shall be included in\n    all copies or substantial portions of the Software.\n\n    THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n    THE SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frubenv%2Fpygmentize","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frubenv%2Fpygmentize","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frubenv%2Fpygmentize/lists"}