+ },\r
+ attachMetadata: function(document) {\r
+ var toret = $('<div>');\r
+ toret.append($(document));\r
+ var meta = $('<metadata></metadata>\n').append(transformations.getXML(view.getMetadata()));\r
+ \r
+ var metadata = toret.find('metadata');\r
+ if(metadata.length === 0) {\r
+ var section = toret.find('section');\r
+ section = section.length ? $(section[0]) : null;\r
+ if(section) {\r
+ section.prepend(meta)\r
+ }\r
+ } else {\r
+ metadata.replaceWith(meta);\r
+ }\r
+ return toret.html();\r