html_unicoder
Version, currently 0.22 versions
- 0.2latestOct 31, 2017
- 0.1not indexedAug 18, 2018
github.com/kostya/html_unicoder
Convert html page to utf-8 for Crystal language
3 stars
0 dependents
License: MIT
Installation
# Add this to your shard.yml
dependencies:
html_unicoder:
github: kostya/html_unicoder
version: ~> 0.2Then run:
shards installshard.yml
- Crystal
- no constraint declared
- License
- MIT
- Author
- Konstantin Makarchev <kostya27@gmail.com>
Dependencies
Runtime Dependencies
- encoding_name*github: kostya/encoding_name
README
# html_unicoder
Convert html page to utf-8 for Crystal language.
## Features
* Encoding name parsed from http headers
* Encoding name parsed from page meta tag
* Encoding name normalized to be used in internal Crystal decoder.
* Correctly handle many edge cases
* Convert page as IO to IO
* Result page should be safe utf-8 to use in Crystal
## Installation
Add this to your application's `shard.yml`:
```yaml
dependencies:
html_unicoder:
github: kostya/html_unicoder
```
## Usage
```crystal
require "html_unicoder"
# basic usage, encoding only from meta tag, or use UTF-8//ignore, by default
page = HtmlUnicoder.new(page, default_encoding: "UTF-8").to_s
# use headers Array(String)
page = HtmlUnicoder.new(page, headers: ["Content-type: text/html; charset=Windows-1251"]).to_s
# use custom encoding
page = HtmlUnicoder.new(page, encoding: "CP1251").to_s
# set use default encoding
HtmlUnicoder.default_encoding = "CP1251"
page = HtmlUnicoder.new(page).to_s
# with http client
require "http/client"
page = ""
HTTP::Client.get("http://www.example.com") do |response|
page = HtmlUnicoder.new(response.body_io, response.headers).to_s
end
# io -> io
io = HtmlUnicoder.new(io).io
# streaming http client body_io
# steps to find encoding
# 1) finding encoding in headers
# 2) finding encoding in response.body meta tag
# 3) consider io as CP1251
body_io = HtmlUnicoder.new(response.body_io, response.headers, default_encoding: "CP1251").io
```
Documentation
Built from the current release. The first visit to a release nobody has asked for starts its build.
Links
This release
- Version
0.2- Tagged
- Oct 31, 2017
- Commit
31000db023d3- Indexed
- yes
Dependents
No indexed shard depends on this one yet.
Repository
github.com/kostya/html_unicoder
Metadata
- Created
- Aug 12, 2026
- Updated
- Aug 14, 2026
- Synced
- Aug 14, 2026
- Versions
- 2