GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - threedaymonk/htmlentities: HTMLEntities is a simple library to facilitate encoding and decoding of named (ý and so on) or numerical ({ or Ī) entities in HTML and XHTML documents.

This repository was archived by the owner on Oct 18, 2026. It is now read-only.
BranchesTags
Open more actions menu

Latest commit

 

History

148 Commits
148 Commits

Folders and files

NameName
Last commit message
Last commit date
.github/workflows
.github/workflows
 
 
lib
lib
 
 
perf
perf
 
 
spec
spec
 
 
util
util
 
 
.gitignore
.gitignore
 
 
.standard.yml
.standard.yml
 
 
COPYING.txt
COPYING.txt
 
 
Gemfile
Gemfile
 
 
History.txt
History.txt
 
 
README.md
README.md
 
 
Rakefile
Rakefile
 
 
htmlentities.gemspec
htmlentities.gemspec
 
 

Repository files navigation

Why I'm no longer updating this repository

HTMLEntities

The canonical source for this project can be found at GitHub: threedaymonk/htmlentities.

HTML entity encoding and decoding for Ruby

HTMLEntities is a simple library to facilitate encoding and decoding of named (ý and so on) or numerical ({ or Ī) entities in HTML and XHTML documents.

Usage

Decoding

require 'htmlentities'
coder = HTMLEntities.new
string = "élan"
coder.decode(string) # => "élan"

Encoding

This is slightly more complicated, due to the various options. The encode method takes a variable number of parameters, which tell it which instructions to carry out.

require 'htmlentities'
coder = HTMLEntities.new
string = "<élan>"

Escape unsafe codepoints only:

coder.encode(string) # => "&lt;élan&gt;"

Or:

coder.encode(string, :basic) # => "&lt;élan&gt;"

Escape all entities that have names:

coder.encode(string, :named) # => "&lt;&eacute;lan&gt;"

Escape all non-ASCII/non-safe codepoints using decimal entities:

coder.encode(string, :decimal) # => "&#60;&#233;lan&#62;"

As above, using hexadecimal entities:

coder.encode(string, :hexadecimal) # => "&#x3c;&#xe9;lan&#x3e;"

You can also use several options, e.g. use named entities for unsafe codepoints, then decimal for all other non-ASCII:

coder.encode(string, :basic, :decimal) # => "&lt;&#233;lan&gt;"

Flavours

HTMLEntities knows about three different sets of entities:

  • :xhtml1 – Entities from the XHTML1 doctype
  • :html4 – Entities from the HTML4 doctype. Differs from +xhtml1+ only by the absence of +&apos+
  • :expanded – Entities from a variety of SGML sets

The default is :xhtml, but you can override this:

coder = HTMLEntities.new(:expanded)

Licence

This code is free to use under the terms of the MIT licence. See the file COPYING.txt for more details.

Contact

Send email to [email protected].

About

HTMLEntities is a simple library to facilitate encoding and decoding of named (&yacute; and so on) or numerical (&#123; or &#x12a;) entities in HTML and XHTML documents.

Resources

Readme
License
Activity

Stars

347 stars

Watchers

6 watching

Forks

32 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.