From b1667ecb9ddaa3677d7e8b742fb0e43670291d82 Mon Sep 17 00:00:00 2001 From: lin onetwo Date: Sat, 3 Aug 2024 01:05:49 +0800 Subject: [PATCH] fix: condition manually Deekseek is silly --- .../parsers/wikiparser/rules/conditional.js | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/core/modules/parsers/wikiparser/rules/conditional.js b/core/modules/parsers/wikiparser/rules/conditional.js index ead7fc0af..88d243d0e 100644 --- a/core/modules/parsers/wikiparser/rules/conditional.js +++ b/core/modules/parsers/wikiparser/rules/conditional.js @@ -120,11 +120,24 @@ exports.parseIfClause = function(filterCondition) { exports.serialize = function(tree, serialize) { var filterCondition = tree.attributes.filter.value; var ifClause = serialize(tree.children[0].children); - var elseClause = serialize(tree.children[1].children); - var serialized = '<% if ' + filterCondition + ' %>' + ifClause; - if(elseClause) { - serialized += '<% else %>' + elseClause; + var elseClause = tree.children[1].children; + var serialized = '<% if ' + filterCondition + '%>' + ifClause; + + if(elseClause && elseClause.length > 0) { + for(var i = 0; i < elseClause.length; i++) { + if(elseClause[i].type === 'list' && elseClause[i].attributes.filter) { + // Handle elseif clause + var elseifCondition = elseClause[i].attributes.filter.value; + var elseifClause = serialize(elseClause[i].children[0]); + serialized += '<% elseif ' + elseifCondition + '%>' + elseifClause; + } + if(elseClause[i].children[1]) { + var elseClauseText = serialize(elseClause[i].children[1]); + serialized += '<% else %>' + elseClauseText; + } + } } + serialized += '<% endif %>'; return serialized; };