Can I prevent JTidy from converting an apostrophe in an attribute value to an entity - jtidy

My input HTML has a line similar to this:
<div class="image" style="background:url('/images/someImage.jpg') no-repeat;"/>
which JTidy is converting to
<div class="image" style="background:url(&apos;/images/someImage.jpg&apos;) no-repeat;"/>
Is there a way to suppress that entity conversion? There appears to be a config method for preventing double quotes from being converted (setQuoteMarks()), but I don't see similar for apostrophes.

Are you using the escapeXml() method?
If so try the escapeHtml3() or escapeHtml4() method.

Related

Angularjs Placeholder (Attribute) Containing Smart Quote

I want to set the placeholder of an editable text area based on a value set in the controller. The placeholder text contains smart quotes. When I do this it works:
<div>
<p editable-textarea="vm.address" e-rows="8" e-name="address" e-ng-model="vm.address" e-ng-maxlength="vm.addressLimit"
e-maxlength="{{vm.addressLimit}}" e-placeholder="They’re">{{vm.address || '(empty)'}} </p>
</div>
This is displayed: "They’re".
However if I set e-placeholder to value defined in my controller it doesn't. For example if the controller has
vm.addressPlaceholder = 'They’re';
and the view
<div>
<p editable-textarea="vm.address" e-rows="8" e-name="address" e-ng-model="vm.address" e-ng-maxlength="vm.addressLimit"
e-maxlength="{{vm.addressLimit}}" e-placeholder="{{vm.addressPlaceholder}}">{{vm.address || '(empty)'}} </p>
</div>
They’re is displayed. Any idea on what I am doing wrong.
Thanks in advance.
Try putting your value in quotes when you set it...
vm.addressPlaceholder = 'They’re'
and then remove the curly braces and set it in the markup like so
e-placeholder="vm.addressPlaceholder"
Issue resolved. The problem had to do with the encoding. The javascript file was saved as ANSI. After changing the encoding to UTF-8, problem resolved.

loop through json array having complex variable

I am trying to loop through json array inside the template, here is what I have tried:
Json array is in this format: [{"a":123,"b":234},{"a":1233,"b":23232}]
when I give this expression:
<div ng-repeat=(name,value) in row.entity["'+branch_name+'_wu_tester_detail"]>{{name}} :: {{value}} </div>
I m getting this error:
Error: [ngRepeat:iexp] Expected expression in form of 'item in
_collection[ track by _id]' but got '(name,value)'.
Also I have tried this:
<div ng-repeat=items in row.entity["'+branch_name+'_wu_tester_detail"]>{{items.tester_id}} :: {{items.workunit_id}}</div>
But this also is not working.
FYI here the branch_name is variable and the value of row.entity["'+branch_name+'_wu_tester_detail"] is in format of [{"a":123,"b":234},{"a":1233,"b":23232}]
Thanks in advance
Didn't find any perfect solution but got a good workaround. Here it seems angular is confused while parsing the expression in ng-repeat. Even escape character doesn't seems to work. So I stored this variable to a much simpler otehr variable using ng-init and then I used ng-repeat, which solved the problem.
If there are any better way, please add to this question, I will add that as accepted answer.
<div ng-init=myJsonVar=row.entity[\"'+branch_name+'_wu_tester_detail\"]> {{myJsonVar}}</div><div ng-repeat="item in myJsonVar">IN{{item.tester_id}} :: {{item.workunit_id}} </div>

AngularJS: Is there a convenient way to show and bind on an element if value is defined?

I am looking for one line syntax for this:
<span ng-if="value">{{value}}</span>
Maybe something like:
<span ng-bind-if="value"></span>
If saving characters is important I would recommend creating a custom directive and handle the logic internally.
<span my-hide-if-undefined="value"></span>

AngularJS Expression

I have a quick question on AngularJS:
I have one property from JSON as
"icon-class": "home"
Now I need to do this in my html page:
<span class="{{sub.icon-class}}"></span>
the sub is some other object here.
But inspecting the DOM, the value of the above expression is always zero (0). I guess the dash(-) is acting like a subtraction here.
How to do it I could not make it resolve.
Please help.
In this case, you can use bracket notation to retrieve the value when the key has non-standard characters:
<span class="{{sub['icon-class']}}"></span>
Read more about accessing properties at MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Property_Accessors
You could do this:
<span class="{{sub['icon-class']}}"></span>
But in general I'd avoid hyphens in variable names

GAE Jinja2 single quotes escaping

Hello!
I've attempted to implement typeahead feature in GAE app with TwitterBootstrap framework. It's necessary to render into Jinja2 template this snippet:
<input type="text" class="span3"
style="margin: 0 auto;" data-provide="typeahead"
data-items="4" data-source='["Alabama","Alaska","Arizona"]'>
And it's seems to be impossible because template engine always escaped single quotes replasing it by double. Obviously what entire typeahead construction could not work at all in this case. There are several documented escaping method such as raw, safe or even autoescape false but they can't resolve this issue. How to force Jinja2 to render the single quotes?
Have anybody a matching recipe how it would been resolved?
Thanks!
The following code works for me:
{{ typeahead_data|safe }}
Please consider including your actual code next time, instead of just saying 'it doesn\'t work'.

Resources