Last active
April 7, 2019 03:54
-
-
Save judah-caruso/726b366a05c4aa1537af7b911db6601b to your computer and use it in GitHub Desktop.
Takes a string of code and converts each special character to HTML entities.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import std | |
// should cover the main "problematic" characters | |
def char_to_entity(char): | |
return switch(char): | |
case "|" : "|" | |
case "_" : "_" | |
case ";" : ";" | |
case "#" : "#" | |
case "-" : "‐" | |
case "<" : "<" | |
case ">" : ">" | |
case "*" : "*" | |
case "\n": "<br />" | |
case "\t", " ": " " | |
default: char | |
def string_to_safe(str): | |
let converted = | |
str.map() t: char_to_entity(unicode_to_string([t])) | |
return concat_string(converted, "") | |
// so meta! | |
let code = | |
""" | |
def string_to_safe(str): | |
let converted = | |
str.map() t: char_to_entity(unicode_to_string([t])) | |
return concat_string(converted, "") | |
""" | |
print string_to_safe(code) | |
// output: def string_to_safe(str):<br /> let converted =<br /> str.map() t: char_to_entity(unicode_to_string([t]))<br /><br /> return concat_string(converted, "")<br /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment