EscapeString provides a single function that escapes a given string according to the given format. The function signature is escapestring(s::AbstractString, fmt::Symbol)
. For example:
s = "<div>Hi there 'Sam'!</div>"
s2 = escapestring(s, :html_text)
s2 == "<div>Hi there 'Sam'!</div>" # true
The following formats are currently supported:
- HTML text (
:html_text
)
Suppose you would like to add functionality for escaping to XML. To do this:
- Write a function that takes an
AbstractString
and escapes it to the desired format, sayescape_xml(s::AbstractString)
. - Save the function in a file such as
src/escape_xml.jl
. - Add
include("escape_xml.jl")
tosrc/EscapeString.jl
. - Add
formats[:xml] = escape_xml
tosrc/EscapeString.jl
.
That's it!
- Other formats will be added over time on an as-needed basis, such as:
- HTML attribute
- URL, also known as percent encoding
- CSS
- XML