Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why am I getting this weird “​” line break?

A similar question have been asked (and answered), but there were no answer / solution on how to fix it

I'm using jQuery Mobile / Handlebars for my Phonegap project. Up till now everything seemed to work just fine. But suddenly I get this weird line break:

"​                               "

enter image description here

I use the following code to make the list:

    // HTML
    <ul id="guideListView" data-role="listview" ></ul>

    <script id="guideListTemplate" type="text/x-handlebars-template">​
        {{#if this}}
            {{#each this}}
            <li class="guide">
                <a href="{{guideUrl}}{{id}}" data-transition="slide" class="ui-nodisc-icon" >
                    <div class="name">{{name}}</div>
                    <div class="num-stores-container no-bold small">Stores: <span class="num-stores">{{storesCount}}</span></div>
                </a>
            </li>
            {{/each}}
        {{else}}
            <li class="ui-btn">Sorry, no guides for <span class="city"></span></li>
    {{/if}}
    </script>

    // JS
    var template = Handlebars.compile($("#guideListTemplate").html());
    $('#guideListView').append(template(guides));
    $('#guideListView').listview().listview('refresh');

Does anyone know what might be causing this?

updated
I've tried using ("#guideListTemplate").html().trim() and $('#guideListView').html(template(guides));, but that didn't make any difference. Could this be a big in jQuery Mobile?

A bit more debugging and it seems the problem might lie in this:

<script id="guideListTemplate" type="text/x-handlebars-template">​
like image 334
Steven Avatar asked Feb 26 '15 09:02

Steven


People also ask

Why do I feel weird all of a sudden?

Feeling like there is someting wrong, odd, or strange about how you feel is a common sign and symptom of anxiety, anxiety disorder, and anxiety and panic attacks. This article explains the relationship between anxiety and feeling like there is something wrong, odd, or strange about how you feel.

Is it normal to have a weird feeling?

It's totally normal to have a day here or there where we just feel a little bit “weird” or “off”. In other words, not quite ourselves. Even though this is common, it's important to pay attention to what's going on with our emotional and physical state when this happens.

Why am I feeling uncomfortable for no reason?

A little anxiety is fine, but long-term anxiety may cause more serious health problems, such as high blood pressure (hypertension). You may also be more likely to develop infections. If you're feeling anxious all the time, or it's affecting your day-to-day life, you may have an anxiety disorder or a panic disorder.

What is the feeling of weird?

Feeling “weird' often involves emotions we can't name, an overall foggy feeling or an inability to focus.


2 Answers

Ok, so I found a solution from this thread.

The problem is that when you try to fetch the html of a javascript string, you might get zero width space.

Unicode has the following zero-width characters:

  • U+200B zero width space
  • U+200C zero width non-joiner Unicode code point
  • U+200D zero width joiner Unicode code point
  • U+FEFF zero width no-break space Unicode code point

So to fix my problem by I use regular expression to remove the unicode charecter:

var source = $("#guideListTemplate").html().replace(/[\u200B]/g, '');
like image 174
Steven Avatar answered Oct 19 '22 21:10

Steven


I just had the same problem and found the solution. The problem stems from the fact we copy-paste snippets from the www into our editor and sometimes it results in a character like space being copied as a numeric entity. The editor parses the entity so everything looks ordinary. The solution is to find a way to highlight numeric entities (if it's not built-in in your editor, look for an extension) and deleting it. Regex/replace is not a solution.

like image 5
adi518 Avatar answered Oct 19 '22 21:10

adi518