How to create active links with Mustache?

三世轮回 提交于 2021-02-11 12:31:38

问题


How to create active clickable links with Mustache? I prefer to use javascript version of Mustache for this.

In other words:

I want to autolink user generated text content with javascript/mustache (=linkify).

Template

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

Data

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

Output I'm looking for

<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>

回答1:


Use {{{.}}} instead of {{.}} - this will not escape special characters.



来源:https://stackoverflow.com/questions/22019029/how-to-create-active-links-with-mustache

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!