diff options
author | nimojs <imhadley@163.com> | 2015-04-19 23:14:19 +0800 |
---|---|---|
committer | nimojs <imhadley@163.com> | 2015-04-19 23:14:19 +0800 |
commit | cbaf08642e63b1dc50b99ba5ac41ea1ecc4b7163 (patch) | |
tree | 2d2d55cfbd5e9b89a99223d2e30037ed4ba14cae /posts/demo/SafeString.md | |
parent | 720cb5a6ba938cb9864bd24d6df5527b5cdbfa91 (diff) | |
download | handlebarsjs.org-origin/master.zip handlebarsjs.org-origin/master.tar.gz handlebarsjs.org-origin/master.tar.bz2 |
增加章节,静态资源文件目录调整
Diffstat (limited to 'posts/demo/SafeString.md')
-rw-r--r-- | posts/demo/SafeString.md | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/posts/demo/SafeString.md b/posts/demo/SafeString.md new file mode 100644 index 0000000..a999814 --- /dev/null +++ b/posts/demo/SafeString.md @@ -0,0 +1,34 @@ +<!--_PAGEDATA +{ + "title": "HTML 转义配合 SafeString", + "githubissuesid": 2, + "keywords": "js,handlebars,javascript", + "description":" Handlebars 中使用 helper 输出链接", + "doc_text":"HTML 转义配合 SafeString", + "doc_link":"../index.html#SafeString", + "_template": "demo" +} +_PAGEDATA--> + +<!-- 模板 --> +<script class="show" id="source" type="text/x-handlebars-template" > +{{{link "<em>html</em>" "http://www.handlebarsjs.org"}}} +</script> + +<!-- 数据 --> +<script class="show json-format-error" id="data" type="text/json"> + +</script> + +<!-- helper实现 --> +<script class="show" id="helper"> +Handlebars.registerHelper('link', function(text, url) { + // 将下行 text = ... 注释以查看未作安全性转义导致的文字倾斜效果 + text = Handlebars.Utils.escapeExpression(text); + url = Handlebars.Utils.escapeExpression(url); + + var result = '<a href="' + url + '">' + text + '</a>'; + + return new Handlebars.SafeString(result); +}); +</script>
\ No newline at end of file |