X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Fmkws-handlebars.js;h=537779e5b21860a9dbb29c7535780746dd153fdb;hb=94a3083ce79f3cdf185add39bb933d695815b623;hp=916ddba9cd8be1fc33c17f321b3544f58203379a;hpb=655b6236d3b8c8f254557072908f0b2192cefa04;p=mkws-moved-to-github.git diff --git a/src/mkws-handlebars.js b/src/mkws-handlebars.js index 916ddba..537779e 100644 --- a/src/mkws-handlebars.js +++ b/src/mkws-handlebars.js @@ -1,13 +1,23 @@ // Handlebars helpers + Handlebars.registerHelper('mkws-json', function(obj) { return $.toJSON(obj); }); -Handlebars.registerHelper('mkws-paragraphs', function(obj) { +// This is intended to handle paragraphs from Wikipedia, hence the +// rather hacky code to remove numbered references. +// +Handlebars.registerHelper('mkws-paragraphs', function(obj, count) { var acc = []; - for (var i = 0; i < obj.length; i++) { - acc.push('

', obj[i], '

'); + + // For some reason, Handlebars provides the value + // {"hash":{},"data":{}} for undefined parameters + if (count.hasOwnProperty('hash')) count = undefined; + if (!count || count > obj.length) count = obj.length; + + for (var i = 0; i < count; i++) { + acc.push('

', obj[i].replace(/\[[0-9,]+\]/g, ''), '

'); } return acc.join(''); });