Skip to content

Commit

Permalink
readme and lic, more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Mario Hros committed May 5, 2017
1 parent 68b5b79 commit 59a3793
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2017 K3A
Copyright (c) 2017 Mario K3A Hros (www.k3a.me)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@
# html2text

A simple Golang package to convert HTML to plain text.

It converts HTML tags to text and also parses HTML entities into characters they represent.
A header section of the HTML document is stripped out, most tags are stripped but links are
properly converted into their href attribute.

It can be used for converting HTML emails into text.

Some tests are installed as well.

Expand Down
9 changes: 8 additions & 1 deletion html2text_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ func TestHTML2Text(t *testing.T) {
Convey("HTML2Text should work", t, func() {

Convey("Links", func() {
So(HTML2Text(`<div></div>`), ShouldEqual, "")
So(HTML2Text(`<div>simple text</div>`), ShouldEqual, "simple text")
So(HTML2Text(`click <a href="test">here</a>`), ShouldEqual, "click test")
So(HTML2Text(`click <a class="x" href="test">here</a>`), ShouldEqual, "click test")
So(HTML2Text(`click <a href="ents/&apos;x&apos;">here</a>`), ShouldEqual, "click ents/'x'")
Expand All @@ -20,11 +22,16 @@ func TestHTML2Text(t *testing.T) {

Convey("HTML entities", func() {
So(HTML2Text(`two&nbsp;&nbsp;spaces`), ShouldEqual, "two spaces")
So(HTML2Text(`two&nbsp;&nbsp;spaces`), ShouldEqual, "two spaces")
So(HTML2Text(`&copy; 2017 K3A`), ShouldEqual, "© 2017 K3A")
So(HTML2Text("&lt;printtag&gt;"), ShouldEqual, "<printtag>")
So(HTML2Text(`Tom & Jerry is not an entity`), ShouldEqual, "Tom & Jerry is not an entity")
So(HTML2Text(`this &neither; as you see`), ShouldEqual, "this &neither; as you see")
})

Convey("Full HTML structure", func() {
So(HTML2Text(`<html><head><title>Good</title></head><body>x</body>`), ShouldEqual, "x")
So(HTML2Text(`we are not <script type="javascript"></script>interested in scripts`),
ShouldEqual, "we are not interested in scripts")
})
})
}

0 comments on commit 59a3793

Please sign in to comment.