Support for using HTML entity names for characters.
This package provides a table of the 2125 named character references defined by HTML, with fast lookups in both directions:
- from an entity name to the Unicode character(s) it represents,
- from a character, or a pair of characters, to all of the entity names for it,
- from a prefix to all of the entity names that start with it (for completions).
Requires Julia 1.10 or later.
using Pkg
Pkg.add("HTML_Entities")Nothing is exported. The lookup functions come from
StrTables.jl and take the table
HTML_Entities.default as their first argument.
using HTML_Entities, StrTables
const tab = HTML_Entities.default
lookupname(tab, "nle") # "≰"
lookupname(tab, "lvnE") # "≨︀" (two characters: U+2268 U+FE00)
lookupname(tab, "foobar") # "" (unknown name)
matchchar(tab, 'α') # ["alpha"]
matches(tab, "≨︀") # ["lvertneqq", "lvnE"]
longestmatches(tab, "≰ abcd") # ["NotLessEqual", "nle", "nleq"]
completions(tab, "um") # ["umacr", "uml"]| Function | Description |
|---|---|
lookupname(tab, name) |
The string for an entity name, or "" if not found |
matchchar(tab, ch) |
All entity names for a single character |
matches(tab, str) |
All entity names that exactly match a string of one or two characters |
longestmatches(tab, str) |
All entity names for the longest match at the start of str |
completions(tab, prefix) |
All entity names that start with prefix |
HTML_Entities.default is also an AbstractVector{String} of all entity names, in sorted order.
The table is loaded from data/html.dat at precompile time and stored in the package image.
Nothing is read from disk at runtime, and the table has a concrete type, so the package can be
used in executables built with JuliaC.jl and --trim=safe.
The entity definitions are in deps/htmlnames.jl. To rebuild the table,
delete data/html.dat and run:
julia --project=. -e 'using Pkg; Pkg.instantiate(); include("deps/build.jl")'