// retoor <retoor@molodetz.nl>
import "html" for Html
System.print("=== HTML Module Demo ===")
System.print("\n--- URL Encoding ---")
var text = "hello world & special=chars"
var encoded = Html.urlencode(text)
var decoded = Html.urldecode(encoded)
System.print("Original: %(text)")
System.print("Encoded: %(encoded)")
System.print("Decoded: %(decoded)")
System.print("\n--- Slugify ---")
var titles = [
"Hello World",
"This is a Test Article!",
"Product Name (2024)",
"FAQ & Help"
]
for (title in titles) {
System.print("%(title) -> %(Html.slugify(title))")
}
System.print("\n--- HTML Escaping ---")
var unsafe = "<script>alert('XSS')</script>"
var safe = Html.quote(unsafe)
System.print("Unsafe: %(unsafe)")
System.print("Safe: %(safe)")
System.print("Unescaped: %(Html.unquote(safe))")
System.print("\n--- Query Parameters ---")
var params = {"name": "John Doe", "city": "New York", "age": 30}
var queryString = Html.encodeParams(params)
System.print("Params: %(params)")
System.print("Query string: %(queryString)")
var parsed = Html.decodeParams(queryString)
System.print("Parsed back: %(parsed)")