Ok I found that that the new lines and spaces in .html() was breaking it. So I had to scrub out the new lines and spaces before feeding it into the layout:
<html>
<body>
...
<div id="main">
<div id="head">...</div>
<div id="body">...</div>
<div id="foot">...</div>
</div>
...
<script>
var html = $('#main').html().replace(/^\s+|\r\n|\n|\r|(>)\s+(<)|\s+$/gm, '$1$2');
$('#main').empty();
var layout = new kendo.Layout(html);
layout.render("#main");
</script>
</body>
</html>