I came across this piece of Javascript code which uses Handlebars.js and I would like to link this to my index.html page. Can anyone help with that?
Thanks!
This is the original code:
//replace URL by html link
Handlebars.registerHelper('link', function(text) {
var exp = /((https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig
var exp2 = /(@[A-Za-z0-9]+)/ig
return new Handlebars.SafeString(text.replace(exp,'<a href="$1">$1</a>').replace())
})
Initially you need to include the handlerbars.js file in your HTML.
<script src="~/Scripts/handlebars-v2.0.0.js"></script>
Then
If you want to return the register Helper function named "link" inside a div then you can use it like this.
<div id="sample">{{link}}</div>
The output will be
<div id="sample"><a href="$1">$1</a></div>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.