mirror of
https://github.com/idris-lang/Idris2.git
synced 2024-12-01 09:49:24 +03:00
Add Text.PrettyPrint.Prettyprinter.Render.HTML to contrib as well
This commit is contained in:
parent
9591b147a4
commit
8d21a292d0
36
libs/contrib/Text/PrettyPrint/Prettyprinter/Render/HTML.idr
Normal file
36
libs/contrib/Text/PrettyPrint/Prettyprinter/Render/HTML.idr
Normal file
@ -0,0 +1,36 @@
|
||||
module Text.PrettyPrint.Prettyprinter.Render.HTML
|
||||
|
||||
import Data.List
|
||||
import Data.Strings
|
||||
|
||||
export
|
||||
htmlEscape : String -> String
|
||||
htmlEscape s = fastAppend $ reverse $ go [] s
|
||||
where
|
||||
isSafe : Char -> Bool
|
||||
isSafe '"' = False
|
||||
isSafe '<' = False
|
||||
isSafe '>' = False
|
||||
isSafe '&' = False
|
||||
isSafe '\'' = False
|
||||
isSafe '\t' = True
|
||||
isSafe '\n' = True
|
||||
isSafe '\r' = True
|
||||
isSafe c = (c >= ' ' && c <= '~')
|
||||
|
||||
htmlQuote : Char -> String
|
||||
htmlQuote '"' = """
|
||||
htmlQuote '<' = "<"
|
||||
htmlQuote '>' = ">"
|
||||
htmlQuote '&' = "&"
|
||||
htmlQuote '\'' = "'"
|
||||
htmlQuote c = "&#" ++ (show $ ord c) ++ ";"
|
||||
|
||||
go : List String -> String -> List String
|
||||
go acc "" = acc
|
||||
go acc s =
|
||||
case span isSafe s of
|
||||
(safe, "") => safe::acc
|
||||
(safe, rest) => let c = assert_total (strIndex rest 0)
|
||||
escaped = htmlQuote c in
|
||||
go (escaped::safe::acc) (assert_total $ strTail rest)
|
@ -161,5 +161,6 @@ modules = Control.ANSI,
|
||||
Text.PrettyPrint.Prettyprinter.Symbols,
|
||||
Text.PrettyPrint.Prettyprinter.Util,
|
||||
Text.PrettyPrint.Prettyprinter.SimpleDocTree,
|
||||
Text.PrettyPrint.Prettyprinter.Render.HTML,
|
||||
Text.PrettyPrint.Prettyprinter.Render.String,
|
||||
Text.PrettyPrint.Prettyprinter.Render.Terminal
|
||||
|
Loading…
Reference in New Issue
Block a user