From 0163c04b7d8fc4288688da71ade46c331bce0840 Mon Sep 17 00:00:00 2001 From: "jeremy@jermolene.com" Date: Tue, 3 May 2022 09:37:49 +0100 Subject: [PATCH] Fix addAttributeToParseTreeNode handling of ordered attributes --- core/modules/utils/parsetree.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/core/modules/utils/parsetree.js b/core/modules/utils/parsetree.js index e056b0fdd..fa6d7ef1a 100644 --- a/core/modules/utils/parsetree.js +++ b/core/modules/utils/parsetree.js @@ -15,9 +15,18 @@ Parse tree utility functions. exports.addAttributeToParseTreeNode = function(node,name,value) { var attribute = {name: name, type: "string", value: value}; node.attributes = node.attributes || {}; + node.orderedAttributes = node.orderedAttributes || []; node.attributes[name] = attribute; - if(node.orderedAttributes) { + var foundIndex = -1; + $tw.utils.each(node.orderedAttributes,function(attr,index) { + if(attr.name === name) { + foundIndex = index; + } + }); + if(foundIndex === -1) { node.orderedAttributes.push(attribute); + } else { + node.orderedAttributes[foundIndex] = attribute; } };