{"id":20228325,"url":"https://github.com/matryer/anno","last_synced_at":"2025-04-10T17:33:31.119Z","repository":{"id":32977772,"uuid":"36601125","full_name":"matryer/anno","owner":"matryer","description":"Go package for text annotation.","archived":false,"fork":false,"pushed_at":"2020-02-04T16:39:13.000Z","size":28,"stargazers_count":71,"open_issues_count":2,"forks_count":7,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-24T15:11:15.568Z","etag":null,"topics":["golang","hashtags","mentions","text-annotation"],"latest_commit_sha":null,"homepage":null,"language":"Go","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/matryer.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}},"created_at":"2015-05-31T12:02:38.000Z","updated_at":"2025-03-04T10:16:31.000Z","dependencies_parsed_at":"2022-08-07T19:16:19.425Z","dependency_job_id":null,"html_url":"https://github.com/matryer/anno","commit_stats":null,"previous_names":["downlist/anno"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matryer%2Fanno","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matryer%2Fanno/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matryer%2Fanno/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matryer%2Fanno/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/matryer","download_url":"https://codeload.github.com/matryer/anno/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248261995,"owners_count":21074229,"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":["golang","hashtags","mentions","text-annotation"],"created_at":"2024-11-14T07:29:38.821Z","updated_at":"2025-04-10T17:33:31.082Z","avatar_url":"https://github.com/matryer.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# anno  [![GoDoc](https://godoc.org/github.com/matryer/anno?status.svg)](https://godoc.org/github.com/matryer/anno)\n\nGo package for text annotation. [Read the article covering anno](https://medium.com/@matryer/annotating-text-in-go-and-package-design-ae43f9dccc6d)\n\n  * Simple interface\n  * Very extensible\n  * Looks nice in JSON (good for APIs)\n\n## Usage\n\n```go\ns := \"Find http://www.websites.com/ and #hashtags and @mentions easily\"\nnotes, err := anno.FindManyString(s, anno.Emails, anno.URLs, anno.Mentions, anno.Hashtags)\nif err != nil {\n\tlog.Fatalln(err)\n}\nfor _, note := range notes {\n\tlog.Printf(\"Found a %s at [%d:%d]: \\\"%s\\\"\", note.Kind, note.Start, note.End, note.Val)\n}\n```\n\nWill output:\n\n```\nFound a url at [5:29]: \"http://www.websites.com/\"\nFound a mention at [48:57]: \"@mentions\"\nFound a hashtag at [34:43]: \"#hashtags\"\n```\n\nYou can expand (replace) occurances of the notes using `anno.Expander`:\n\n```go\nexpander := anno.Expander{\n\t\"url\": func(b string) string {\n\t\treturn fmt.Sprintf(`\u003ca href=\"%[1]s\"\u003e%[1]s\u003c/a\u003e`, b)\n\t},\n\t\"mention\": func(b string) string {\n\t\treturn fmt.Sprintf(`\u003ca href=\"https://downlist.io/%[1]s\"\u003e%[1]s\u003c/a\u003e`, b)\n\t},\n}\nsrc := \"This is a #long string written by @mat containing links to https://downlist.io/.\"\nnotes, err := anno.FindManyString(src, anno.URLs, anno.Mentions, anno.Hashtags)\nif err != nil {\n\tlog.Fatalln(err)\t\n}\n\nlog.Println(expander.Expand(src, notes))\n```\n\nWill output:\n\n```\nThis is a #long string written by \u003ca href=\"https://downlist.io/@mat\"\u003e@mat\u003c/a\u003e containing links to \u003ca href=\"https://downlist.io/\"\u003ehttps://downlist.io/\u003c/a\u003e.\n```\n\n## Emoji\n\nEmoji support lives in its own package due to the external dependency.\n\n```go\nsrc := \"You make me want to :smile: you know!\"\nnotes, err := anno.FindManyString(src, emoji.Find)\nexpander := anno.Expander{\n\t\"emoji\": emoji.Expand,\n}\n\nlog.Println(expander.Expand(src, notes))\n```\n\nWill replace `:smile:` with the appropriate emoji character.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmatryer%2Fanno","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmatryer%2Fanno","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmatryer%2Fanno/lists"}