diff --git a/CHANGELOG.md b/CHANGELOG.md index a124320..db9bbd4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,81 +1,80 @@ -0.11.0 ------- +## 1.0.0 + +- `Format`, `FormatHTML`, `Unformat`, `UnformatHTML` support custom option for addition processes. + +Example: + +```go +type myFormatter struct {} +func (my myFormatter) Format(text string) string { + return strings.ReplaceAll(text, "ios", "iOS") +} + +autocorrect.Format("新版本ios即将发布", myFormatter{}) +// "新版本 iOS 即将发布" +``` + +## 0.11.0 - Fix fullwidth to remove `;` for fix invalid convert with HTML Entity case. -0.10.0 --------- +## 0.10.0 - Auto correct punctuation into fullwidth. -0.9.0 --------- +## 0.9.0 - Change rule for ignore spacing between `#`, `$` chars. -0.8.2 --------- +## 0.8.2 - Fix some break line miss bug. -0.8.0 --------- +## 0.8.0 - Add `Unformat` / `UnformatHTML` method for remove spacings. -0.7.0 --------- +## 0.7.0 - Use new HTML parser to format HTML for performance up. - Avoid format text with script/style/textarea/pre tags. -0.6.1 --------- +## 0.6.1 - Fix halfwidth to correct fullwidth spaces. -0.6.0 --------- +## 0.6.0 - Auto correct FullWidth -> halfwidth for Letters, Numbers, and Colon in time. -0.4.1 --------- +## 0.4.1 - Avoid create regex on format method call for performance up (~40%). -0.4.0 --------- +## 0.4.0 - Add Full CJK (Chinese, Japanese, Korean) support. -0.3.3 --------- +## 0.3.3 - Fix space around `-`; -0.3.2 --------- +## 0.3.2 - Fix add space round `*`; -0.3.1 --------- +## 0.3.1 - Fix HTML replace when content has escapeable `&`, ` ` chars. -0.3.0 --------- +## 0.3.0 - Rename package from `autospace` to `autocorrect`. -0.2.0 --------- +## 0.2.0 - Add `FormatHTML` method for process HTML contents. -0.1.0 --------- +## 0.1.0 - First release. - diff --git a/README.md b/README.md index d0e3bbc..1871ad3 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,7 @@ Automatically add whitespace between CJK (Chinese, Japanese, Korean) and half-wi - Fullwidth -> halfwidth (only for [a-zA-Z0-9], and `:` in time). - Correct punctuations into Fullwidth near the CJK. - Cleanup spacings. +- Support options for custom format, unformat. ## Usage @@ -60,6 +61,20 @@ func main() { } ``` +With custom formatter: + +```go +type myFormatter struct {} +func (my myFormatter) Format(text string) string { + return strings.ReplaceAll(text, "ios", "iOS") +} + +autocorrect.Format("新版本ios即将发布", myFormatter{}) +// "新版本 iOS 即将发布" +autocorrect.FormatHTML("
新版本ios即将发布
", myFormatter{}) +// "新版本 iOS 即将发布
" +``` + Use `autocorrect.Unformat` to cleanup spacings in plain text. ```go diff --git a/halfwidth_test.go b/halfwidth_test.go index 5018ae2..62cf150 100644 --- a/halfwidth_test.go +++ b/halfwidth_test.go @@ -12,6 +12,8 @@ func Test_halfwidth(t *testing.T) { assertEqual(t, "他说:我们将在16:32分出发去CBD中心。", halfwidth("他说:我们将在16:32分出发去CBD中心。")) // Fullwidth space assert.Equal(t, "ジョイフル-後場売り気配 200 店舗を閉鎖へ 7 月以降、不採算店中心に", halfwidth("ジョイフル-後場売り気配 200 店舗を閉鎖へ 7 月以降、不採算店中心に")) + // Fullwidth Numbers + assert.Equal(t, "0 1 2 3 4 5 6 7 8 9", halfwidth("0 1 2 3 4 5 6 7 8 9")) } func Benchmark_halfwidth(b *testing.B) {