move HTML escape to global as E

This commit is contained in:
ccd0 2014-06-28 21:58:14 -07:00
parent 79ef398b32
commit b6739cc45d
4 changed files with 15 additions and 16 deletions

View File

@ -1,9 +1,6 @@
Build =
initPixelRatio: window.devicePixelRatio
spoilerRange: {}
h_escape: (text) ->
(text+'').replace /[&"'<>]/g, (c) ->
{'&': '&amp;', "'": '&#039;', '"': '&quot;', '<': '&lt;', '>': '&gt;'}[c]
unescape: (text) ->
return text unless text?
text.replace /&(amp|#039|quot|lt|gt);/g, (c) ->
@ -74,7 +71,6 @@ Build =
This function contains code from 4chan-JS (https://github.com/4chan/4chan-JS).
@license: https://github.com/4chan/4chan-JS/blob/master/LICENSE
###
E = Build.h_escape
{
postID, threadID, boardID
name, capcode, tripcode, uniqueID, email, subject, flagCode, flagName, date, dateUTC

View File

@ -160,7 +160,7 @@ Get =
return
# convert comment to html
h_comment = Build.h_escape (data.comment or '')
h_comment = E (data.comment or '')
# https://github.com/eksopl/fuuka/blob/master/Board/Yotsuba.pm#L413-452
# https://github.com/eksopl/asagi/blob/master/src/main/java/net/easymodo/asagi/Yotsuba.java#L109-138
h_comment = h_comment.replace ///

View File

@ -5,4 +5,7 @@ doc = d.documentElement
g =
VERSION: '<%= version %>'
NAMESPACE: '<%= meta.name %>.'
boards: {}
boards: {}
E = (text) ->
(text+'').replace /[&"'<>]/g, (x) ->
{'&': '&amp;', "'": '&#039;', '"': '&quot;', '<': '&lt;', '>': '&gt;'}[x]

View File

@ -13,23 +13,23 @@ FileInfo =
if c of FileInfo.h_formatters
FileInfo.h_formatters[c].call(post)
else
Build.h_escape s
E s
h_formatters:
t: -> Build.h_escape @file.URL.match(/\d+\..+$/)[0]
T: -> "<a href='#{Build.h_escape @file.URL}' target='_blank'>#{FileInfo.h_formatters.t.call @}</a>"
l: -> "<a href='#{Build.h_escape @file.URL}' target='_blank'>#{FileInfo.h_formatters.n.call @}</a>"
L: -> "<a href='#{Build.h_escape @file.URL}' target='_blank'>#{FileInfo.h_formatters.N.call @}</a>"
t: -> E @file.URL.match(/\d+\..+$/)[0]
T: -> "<a href='#{E @file.URL}' target='_blank'>#{FileInfo.h_formatters.t.call @}</a>"
l: -> "<a href='#{E @file.URL}' target='_blank'>#{FileInfo.h_formatters.n.call @}</a>"
L: -> "<a href='#{E @file.URL}' target='_blank'>#{FileInfo.h_formatters.N.call @}</a>"
n: ->
fullname = @file.name
shortname = Build.shortFilename @file.name, @isReply
if fullname is shortname
Build.h_escape fullname
E fullname
else
"<span class='fntrunc'>#{Build.h_escape shortname}</span><span class='fnfull'>#{Build.h_escape fullname}</span>"
N: -> Build.h_escape @file.name
"<span class='fntrunc'>#{E shortname}</span><span class='fnfull'>#{E fullname}</span>"
N: -> E @file.name
p: -> if @file.isSpoiler then 'Spoiler, ' else ''
s: -> Build.h_escape @file.size
s: -> E @file.size
B: -> return "#{+@file.sizeInBytes} Bytes"
K: -> "#{+Math.round(@file.sizeInBytes/1024)} KB"
M: -> "#{+Math.round(@file.sizeInBytes/1048576*100)/100} MB"
r: -> Build.h_escape (@file.dimensions or 'PDF')
r: -> E (@file.dimensions or 'PDF')