Finding some difficulty rendering out '&' using the Jade engine.
I need to make a call to Google Maps using the following string:
script(type='text/javascript', src='http://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&sensor=SET_TO_TRUE_OR_FALSE')
But this will be rendered in Jade as:
src="http://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&sensor=SET_TO_TRUE_OR_FALSE
One way to unescape HTML entities is to put our escaped text in a text area. This will unescape the text, so we can return the unescaped text afterward by getting the text from the text area. We have an htmlDecode function that takes an input string as a parameter.
In JavaScript, to decode a string unescape() method is used. This method takes a string, which is encoded by escape() method, and decodes it. The hexadecimal characters in a string will be replaced by the actual characters they represent using unescape() method.
unescape() Programmers should not use or assume the existence of these features and behaviors when writing new ECMAScript code. … The unescape() function computes a new string in which hexadecimal escape sequences are replaced with the character that it represents.
1. The unescape() function is used to decode that string encoded by the escape() function. The escape() function in JavaScript is used for encoding a string. Using ASCII character support, it makes a string portable so that it can be transmitted across any network to any computer.
Still according to https://github.com/visionmedia/jade/issues/198 it is now possible to write:
script(type='text/javascript', src!='http://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&sensor=SET_TO_TRUE_OR_FALSE')
Note the !=
for the src
argument; thus its content is not escaped.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With