X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;ds=sidebyside;f=src%2Fmkws-handlebars.js;h=999c1385244f9f06ed4bd195513d6649c22208b7;hb=bbc2308efbf35330bd4e5c6af18beec11b8f7405;hp=6e93578a6b026f75ff8943093a163b28d9aabd48;hpb=d81d10eb466240b6e557379a4e298709a5086bf1;p=mkws-moved-to-github.git diff --git a/src/mkws-handlebars.js b/src/mkws-handlebars.js index 6e93578..999c138 100644 --- a/src/mkws-handlebars.js +++ b/src/mkws-handlebars.js @@ -5,10 +5,20 @@ Handlebars.registerHelper('mkws-json', function(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 == 0 || count > obj.length) { + count = obj.length; + } + + for (var i = 0; i < count; i++) { + acc.push('

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

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