【问题标题】:How to create active links with Mustache?如何使用 Mustache 创建活动链接?
【发布时间】:2014-02-25 15:39:02
【问题描述】:

如何使用 Mustache 创建活动的可点击链接? 我更喜欢为此使用 JavaScript 版本的 Mustache。

换句话说:

我想用 javascript/mustache (=linkify) 自动链接用户生成的文本内容。

模板

{{#.}}
    <div>{{.}}</div>
{{/.}}

数据

[
    'User content, like regular text.',
    'User content with text and links http://www.google.com or secure https://www.google.com'
]

我正在寻找的输出

<div>User content, like regular text.</div>
<div>User content with text and links <a href="http://www.google.com">http://www.google.com</a> or secure <a href="https://www.google.com">https://www.google.com</a></div>

【问题讨论】:

    标签: javascript html templates hyperlink mustache


    【解决方案1】:

    使用 {{{.}}} 代替 {{.}} - 这不会转义特殊字符。

    【讨论】:

    • 谢谢你,拯救了我的一天! :)
    • 欢迎 :) 但是如果内容是用户生成的,注意不要渲染一些不受欢迎的js脚本,会做坏事。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-08-04
    • 1970-01-01
    • 1970-01-01
    • 2021-05-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多