{"id":13693650,"url":"https://github.com/jaytaylor/html2text","last_synced_at":"2025-05-14T14:10:12.890Z","repository":{"id":29964920,"uuid":"33511772","full_name":"jaytaylor/html2text","owner":"jaytaylor","description":"Golang HTML to plaintext conversion library","archived":false,"fork":false,"pushed_at":"2023-10-02T07:14:15.000Z","size":58,"stargazers_count":556,"open_issues_count":24,"forks_count":141,"subscribers_count":12,"default_branch":"master","last_synced_at":"2025-04-10T03:49:58.129Z","etag":null,"topics":["go","golang","html-emails","html2text","plaintext"],"latest_commit_sha":null,"homepage":"https://jaytaylor.com/html2text","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/jaytaylor.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":"2015-04-06T23:46:15.000Z","updated_at":"2025-04-02T12:55:48.000Z","dependencies_parsed_at":"2024-06-05T00:24:19.157Z","dependency_job_id":null,"html_url":"https://github.com/jaytaylor/html2text","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/jaytaylor%2Fhtml2text","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaytaylor%2Fhtml2text/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaytaylor%2Fhtml2text/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaytaylor%2Fhtml2text/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jaytaylor","download_url":"https://codeload.github.com/jaytaylor/html2text/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254160557,"owners_count":22024571,"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":["go","golang","html-emails","html2text","plaintext"],"created_at":"2024-08-02T17:01:14.724Z","updated_at":"2025-05-14T14:10:07.854Z","avatar_url":"https://github.com/jaytaylor.png","language":"Go","readme":"# html2text\n\n[![Documentation](https://godoc.org/github.com/jaytaylor/html2text?status.svg)](https://godoc.org/github.com/jaytaylor/html2text)\n[![Build Status](https://travis-ci.org/jaytaylor/html2text.svg?branch=master)](https://travis-ci.org/jaytaylor/html2text)\n[![Report Card](https://goreportcard.com/badge/github.com/jaytaylor/html2text)](https://goreportcard.com/report/github.com/jaytaylor/html2text)\n\n### Converts HTML into text of the markdown-flavored variety\n\n## Introduction\n\nEnsure your emails are readable by all!\n\nTurns HTML into raw text, useful for sending fancy HTML emails with an equivalently nicely formatted TXT document as a fallback (e.g. for people who don't allow HTML emails or have other display issues).\n\nhtml2text is a simple golang package for rendering HTML into plaintext.\n\nThere are still lots of improvements to be had, but FWIW this has worked fine for my [basic] HTML-2-text needs.\n\nIt requires go 1.x or newer ;)\n\n## Download the package\n\n```bash\ngo get jaytaylor.com/html2text\n```\n\n## Example usage\n\n### Library\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"jaytaylor.com/html2text\"\n)\n\nfunc main() {\n\tinputHTML := `\n\u003chtml\u003e\n  \u003chead\u003e\n    \u003ctitle\u003eMy Mega Service\u003c/title\u003e\n    \u003clink rel=\\\"stylesheet\\\" href=\\\"main.css\\\"\u003e\n    \u003cstyle type=\\\"text/css\\\"\u003ebody { color: #fff; }\u003c/style\u003e\n  \u003c/head\u003e\n\n  \u003cbody\u003e\n    \u003cdiv class=\"logo\"\u003e\n      \u003ca href=\"http://jaytaylor.com/\"\u003e\u003cimg src=\"/logo-image.jpg\" alt=\"Mega Service\"/\u003e\u003c/a\u003e\n    \u003c/div\u003e\n\n    \u003ch1\u003eWelcome to your new account on my service!\u003c/h1\u003e\n\n    \u003cp\u003e\n      Here is some more information:\n\n      \u003cul\u003e\n        \u003cli\u003eLink 1: \u003ca href=\"https://example.com\"\u003eExample.com\u003c/a\u003e\u003c/li\u003e\n        \u003cli\u003eLink 2: \u003ca href=\"https://example2.com\"\u003eExample2.com\u003c/a\u003e\u003c/li\u003e\n        \u003cli\u003eSomething else\u003c/li\u003e\n      \u003c/ul\u003e\n    \u003c/p\u003e\n\n    \u003ctable\u003e\n      \u003cthead\u003e\n        \u003ctr\u003e\u003cth\u003eHeader 1\u003c/th\u003e\u003cth\u003eHeader 2\u003c/th\u003e\u003c/tr\u003e\n      \u003c/thead\u003e\n      \u003ctfoot\u003e\n        \u003ctr\u003e\u003ctd\u003eFooter 1\u003c/td\u003e\u003ctd\u003eFooter 2\u003c/td\u003e\u003c/tr\u003e\n      \u003c/tfoot\u003e\n      \u003ctbody\u003e\n        \u003ctr\u003e\u003ctd\u003eRow 1 Col 1\u003c/td\u003e\u003ctd\u003eRow 1 Col 2\u003c/td\u003e\u003c/tr\u003e\n        \u003ctr\u003e\u003ctd\u003eRow 2 Col 1\u003c/td\u003e\u003ctd\u003eRow 2 Col 2\u003c/td\u003e\u003c/tr\u003e\n      \u003c/tbody\u003e\n    \u003c/table\u003e\n  \u003c/body\u003e\n\u003c/html\u003e`\n\n\ttext, err := html2text.FromString(inputHTML, html2text.Options{PrettyTables: true})\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tfmt.Println(text)\n}\n```\n\nOutput:\n```\nMega Service ( http://jaytaylor.com/ )\n\n******************************************\nWelcome to your new account on my service!\n******************************************\n\nHere is some more information:\n\n* Link 1: Example.com ( https://example.com )\n* Link 2: Example2.com ( https://example2.com )\n* Something else\n\n+-------------+-------------+\n|  HEADER 1   |  HEADER 2   |\n+-------------+-------------+\n| Row 1 Col 1 | Row 1 Col 2 |\n| Row 2 Col 1 | Row 2 Col 2 |\n+-------------+-------------+\n|  FOOTER 1   |  FOOTER 2   |\n+-------------+-------------+\n```\n\n### Command line\n\n```\necho '\u003cdiv\u003ehi\u003c/div\u003e' | html2text\n```\n\n## Unit-tests\n\nRunning the unit-tests is straightforward and standard:\n\n```bash\ngo test\n```\n\n# License\n\nPermissive MIT license.\n\n## Contact\n\nYou are more than welcome to open issues and send pull requests if you find a bug or want a new feature.\n\nIf you appreciate this library please feel free to drop me a line and tell me!  It's always nice to hear from people who have benefitted from my work.\n\nEmail: jay at (my github username).com\n\nTwitter: [@jtaylor](https://twitter.com/jtaylor)\n\n# Alternatives\n\nhttps://github.com/k3a/html2text - Lightweight\n","funding_links":[],"categories":["开源类库","Open source library"],"sub_categories":["文本处理","Word Processing"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjaytaylor%2Fhtml2text","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjaytaylor%2Fhtml2text","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjaytaylor%2Fhtml2text/lists"}