Function Updated 23 Oct 2026
htmlEncode(text)
Encodes <, >, &, " and ' as HTML entities, so text can be placed safely in HTML element content. Several arguments are encoded and joined.
Not the same as toHtml(): toHtml() also turns line breaks into <br /> and URLs into links.
Parameters
textstringrequiredThe string to encode
Returns
An encoded string.
Example
Mixed HTML (or any text file) with inline JavaScript between hash signs.
#{
let myString = "<a></a>";
// Encode the string.
let myEncodedString = docly.htmlEncode(myString);
write(`HTML Encoded string is: ${myEncodedString}`);
}#The template above produces this output:
HTML Encoded string is: <a></a>