var md = window.markdownit(); var context = { 'xml' : {}, 'yaml' : jsyaml.load(document.getElementById("yaml_data").innerHTML), 'alert' : alert, }; // read xml data var xml_data_items = document.getElementsByClassName("xml_data") for (var i=0; i < xml_data_items.length; i++) { var key = xml_data_items[i].id.substr(9); var val = xml_data_items[i].innerHTML; context.xml[key] = val; } var env = new nunjucks.Environment([], { autoescape: true, trimBlocks: true, lstripBlocks: true, }); env.addFilter('markdown', function(str) { return md.render(str); }); env.addFilter('cull_whitespace', function(str) { return str.split(/\s+/).join(' ').trim(); }); env.addFilter('any', function(iterable) { for (var index = 0; index < iterable.length; index++) { if (iterable[index]) return true; } return false; }); env.addFilter('all', function(iterable) { for (var index = 0; index < iterable.length; index++) { if (!iterable[index]) return false; } return true; }); env.addFilter('startswith', function(string, match) { return string.slice(0, match.length) === match; }); env.addFilter('tail', function(sequence) { return sequence.slice(1) }); try { rendered = env.renderString(jinja_template, context); } catch(err) { rendered = "
" + err + "
"; } //console.log(rendered); document.write(rendered);