Skip to content

Commit

Permalink
Merge pull request #14 from j3lamp/html-entities
Browse files Browse the repository at this point in the history
Encode special characters as HTML entities
  • Loading branch information
technosophos committed Dec 31, 2015
2 parents bae117a + 499524b commit 7b71f0b
Showing 1 changed file with 275 additions and 1 deletion.
276 changes: 275 additions & 1 deletion dashing.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,19 @@ func ignore(src string) bool {
return false
}

func encodeHTMLentities(orig string) string {
escaped := new(bytes.Buffer)
for _, c := range orig {
if point_to_entity[c] == "" {
escaped.WriteRune(c)
} else {
escaped.WriteString(point_to_entity[c])
}
}

return escaped.String()
}

func writeHTML(orig, dest string, root *html.Node) error {
dir := filepath.Dir(orig)
base := filepath.Base(orig)
Expand All @@ -369,7 +382,12 @@ func writeHTML(orig, dest string, root *html.Node) error {
}
defer out.Close()

return html.Render(out, root)
content_bytes := new(bytes.Buffer)
html.Render(content_bytes, root)
content := encodeHTMLentities(content_bytes.String())

_, err = out.WriteString(content)
return err
}

func htmlish(filename string) bool {
Expand Down Expand Up @@ -511,3 +529,259 @@ func copyFile(src, dest string) error {
_, err = io.Copy(out, in)
return err
}


var point_to_entity = map[rune]string{
8704: "∀",
8194: " ",
8195: " ",
8709: "∅",
8711: "∇",
8712: "∈",
8201: " ",
8715: "∋",
8204: "‌",
8205: "‍",
8206: "‎",
8719: "∏",
8721: "∑",
8722: "−",
8211: "–",
8212: "—",
8727: "∗",
8216: "‘",
8217: "’",
8730: "√",
175: "¯",
8220: "“",
8221: "”",
8222: "„",
8224: "†",
8225: "‡",
8226: "•",
8230: "…",
8743: "∧",
8744: "∨",
8745: "∩",
8746: "∪",
8747: "∫",
8240: "‰",
8242: "′",
8243: "″",
8756: "∴",
8713: "∉",
8249: "‹",
8250: "›",
8764: "∼",
// 62: ">", // this is already encoded for us
8629: "↵",
9824: "♠",
8260: "⁄",
8773: "≅",
8776: "≈",
8207: "‏",
9829: "♥",
8800: "≠",
8801: "≡",
9827: "♣",
8804: "≤",
8805: "≥",
9830: "♦",
// 38: "&", // this is already encoded for us
8834: "⊂",
8835: "⊃",
8836: "⊄",
8838: "⊆",
8839: "⊇",
8853: "⊕",
8855: "⊗",
8734: "∞",
8218: "‚",
8901: "⋅",
160: " ",
161: "¡",
162: "¢",
163: "£",
164: "¤",
8869: "⊥",
166: "¦",
167: "§",
168: "¨",
169: "©",
170: "ª",
171: "«",
8364: "€",
173: "­",
174: "®",
8733: "∝",
176: "°",
177: "±",
178: "²",
179: "³",
180: "´",
181: "µ",
182: "¶",
183: "·",
184: "¸",
185: "¹",
186: "º",
187: "»",
188: "¼",
189: "½",
190: "¾",
191: "¿",
192: "À",
193: "Á",
194: "Â",
195: "Ã",
196: "Ä",
197: "Å",
198: "Æ",
199: "Ç",
200: "È",
201: "É",
202: "Ê",
203: "Ë",
204: "Ì",
// 34: """, // this is already encoded
206: "Î",
207: "Ï",
208: "Ð",
209: "Ñ",
210: "Ò",
211: "Ó",
212: "Ô",
213: "Õ",
214: "Ö",
215: "×",
216: "Ø",
217: "Ù",
218: "Ú",
219: "Û",
220: "Ü",
221: "Ý",
222: "Þ",
223: "ß",
224: "à",
225: "á",
226: "â",
227: "ã",
228: "ä",
229: "å",
230: "æ",
231: "ç",
232: "è",
205: "Í",
234: "ê",
235: "ë",
236: "ì",
8658: "⇒",
238: "î",
239: "ï",
240: "ð",
241: "ñ",
242: "ò",
243: "ó",
244: "ô",
245: "õ",
246: "ö",
247: "÷",
248: "ø",
249: "ù",
250: "ú",
251: "û",
252: "ü",
253: "ý",
254: "þ",
255: "ÿ",
172: "¬",
8968: "⌈",
8969: "⌉",
8970: "⌊",
8971: "⌋",
8465: "ℑ",
8472: "℘",
8476: "ℜ",
8482: "™",
732: "˜",
9002: "⟩",
8736: "∠",
402: "ƒ",
8706: "∂",
8501: "ℵ",
710: "ˆ",
338: "Œ",
339: "œ",
352: "Š",
353: "š",
8593: "↑",
// 60: "<", // this is already encoded for us
8594: "→",
8707: "∃",
8595: "↓",
8254: "‾",
233: "é",
376: "Ÿ",
916: "Δ",
237: "í",
8592: "←",
913: "Α",
914: "Β",
915: "Γ",
8596: "↔",
917: "Ε",
918: "Ζ",
919: "Η",
920: "Θ",
921: "Ι",
922: "Κ",
923: "Λ",
924: "Μ",
925: "Ν",
926: "Ξ",
927: "Ο",
928: "Π",
929: "Ρ",
931: "Σ",
932: "Τ",
933: "Υ",
934: "Φ",
935: "Χ",
936: "Ψ",
937: "Ω",
945: "α",
946: "β",
947: "γ",
948: "δ",
949: "ε",
950: "ζ",
951: "η",
952: "θ",
953: "ι",
954: "κ",
955: "λ",
956: "μ",
957: "ν",
958: "ξ",
959: "ο",
960: "π",
961: "ρ",
962: "ς",
963: "σ",
964: "τ",
965: "υ",
966: "φ",
967: "χ",
968: "ψ",
969: "ω",
9674: "◊",
8656: "⇐",
977: "ϑ",
978: "ϒ",
8659: "⇓",
8660: "⇔",
982: "ϖ",
165: "¥",
8657: "⇑",
9001: "⟨",
}

0 comments on commit 7b71f0b

Please sign in to comment.