So, you are using Slim, right? If not, go check it out because it’s awesome. ;)
Now, I don’t know about you but prior to Slim I use Haml quite a bit, and even though syntax-wise Haml and Slim have a lot in common, it’s still quite a challenge to convert all Haml templates to Slim templates.
As a result, let me present you with a quick n’ dirty Haml2Slim converter! Check out the source code.
When you are getting an HTML string from an external source (e.g. from an AJAX get result) and you want to rip out a certain part of the HTML source, you need to make sure that the ‘certain part’ is not at the top level of the HTML source.
For example, we have the following HTML string:
Hello
World
If we want to get the first paragraph element by using:
// data is the HTML source
$("p#first", data);
The above code won’t work, because the p tags are at the top level. Instead, we can simply wrap the HTML source with a div tag and that’ll do it. :)