Search code examples
sublimetext3sublimetext-snippet

Livereload snippet throwing error


I'm using the livereload plugin with SublimeText3 and when I open SublimeText get this error:

Error parsing snippet xml: expected > in file
Packages/User/livereload.sublime-snippet on line:6

Here's the code:

<snippet>
    <content>
<script>document.write('<script src="http://'
    + (location.host || 'localhost').split(':')[0]
    + ':35729/livereload.js?snipver=1"></'
    + 'script>')</script>
    </content>
    <!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
    <tabTrigger>livereload</tabTrigger>
    <!-- Optional: Set a scope to limit where the snippet will trigger -->
    <!-- <scope>source.html</scope> -->
</snippet>

It's highlighting the < here: ...snipver=1"></'.

Note that it doesn't seem to affect it working, because LiveReload is indeed working but it's annoying every time I open SublimeText I get that error and can't determine why.


Solution

  • Your snippet is not valid XML, you should enclose your content in CDATA:

    <snippet>
        <content><![CDATA[
    <script>document.write('<script src="http://'
        + (location.host || 'localhost').split(':')[0]
        + ':35729/livereload.js?snipver=1"></'
        + 'script>')</script>
        ]]></content>
        <!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
        <tabTrigger>livereload</tabTrigger>
        <!-- Optional: Set a scope to limit where the snippet will trigger -->
        <!-- <scope>source.html</scope> -->
    </snippet>