janl / mustache.js

Minimal templating with {{mustaches}} in JavaScript
https://mustache.github.io
MIT License
16.37k stars 2.4k forks source link

How to prevent mustache from encoding the url value? #806

Closed fzn0x closed 1 year ago

fzn0x commented 1 year ago

How to prevent mustache from encoding the url value?

const stringDoc = Mustache.render("This is your {{ endpoint }}", {
  endpoint: "https://loli.dev",
});
console.log(stringDoc); // https://loli.dev

Expected value

This is your https://loli.dev

fzn0x commented 1 year ago

Decoding the result solve my issue, if it's still the part of the mustache issue, you can reopen it.

stringDoc = stringDoc.replace(REG_HEX, function (match, group) {
  var num = parseInt(group, 16); //=> 39
  return String.fromCharCode(num); //=> '
});

console.log(stringDoc);

Happy hacking!

phillipj commented 1 year ago
This is your {{{ endpoint }}}

Was not an option to avoid HTML escaping completely?

fzn0x commented 1 year ago
This is your {{{ endpoint }}}

Was not an option to avoid HTML escaping completely?

Wow, you are right haha. I missed that part in the docs! 😄

fzn0x commented 1 year ago

Thank you!

phillipj commented 1 year ago

No worries, I'd say it's yet another hint to improve docs 😬

You're certainly not the first one who's asked and been surprised the built-in HTML encoding can be avoided when needed.

On Fri, 9 Sept 2022 at 16:51, Muhammad Fauzan @.***> wrote:

Thank you!

— Reply to this email directly, view it on GitHub https://github.com/janl/mustache.js/issues/806#issuecomment-1242075876, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAJMWE3EYWTS6AK63JWJZ4TV5NFHPANCNFSM6AAAAAAQINLP3A . You are receiving this because you commented.Message ID: <janl/mustache. @.***>