splash/Sources/Splash/Extensions/Strings/String+HTMLEntities.swift
John Sundell 3de0275b52
HTML: Fully escape all required entities (#89)
Both when outputting HTML, and when highlighting code blocks within a
Markdown text, Splash now fully escapes all required character entities.
2019-11-23 23:59:16 +00:00

25 lines
522 B
Swift

/**
* Splash
* Copyright (c) John Sundell 2019
* MIT license - see LICENSE.md
*/
import Foundation
internal extension StringProtocol {
func escapingHTMLEntities() -> String {
return String(flatMap { character -> String in
switch character {
case "&":
return "&"
case "<":
return "&lt;"
case ">":
return "&gt;"
default:
return String(character)
}
})
}
}