1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-12-27 02:20:28 +00:00

Importvariables should skip parameters widgets

This commit is contained in:
jeremy@jermolene.com 2022-04-29 22:36:07 +01:00
parent 5bcf7b9edd
commit f78e1f6f7d
2 changed files with 48 additions and 32 deletions

View File

@ -49,7 +49,8 @@ ImportVariablesWidget.prototype.execute = function(tiddlerList) {
var parser = widgetPointer.wiki.parseTiddler(title,{parseAsInline:true}); var parser = widgetPointer.wiki.parseTiddler(title,{parseAsInline:true});
if(parser) { if(parser) {
var parseTreeNode = parser.tree[0]; var parseTreeNode = parser.tree[0];
while(parseTreeNode && parseTreeNode.type === "set") { while(parseTreeNode && ["set","parameters"].indexOf(parseTreeNode.type) !== -1) {
if(parseTreeNode.type === "set") {
var node = { var node = {
type: "set", type: "set",
attributes: parseTreeNode.attributes, attributes: parseTreeNode.attributes,
@ -82,6 +83,7 @@ ImportVariablesWidget.prototype.execute = function(tiddlerList) {
} }
widgetPointer = widgetPointer.children[0]; widgetPointer = widgetPointer.children[0];
} }
}
parseTreeNode = parseTreeNode.children && parseTreeNode.children[0]; parseTreeNode = parseTreeNode.children && parseTreeNode.children[0];
} }
} }

View File

@ -683,7 +683,7 @@ describe("Widget module", function() {
expect(wrapper.innerHTML).toBe("<p>New value</p>"); expect(wrapper.innerHTML).toBe("<p>New value</p>");
}); });
it("should can mix setWidgets and macros when importing", function() { it("should support mixed setWidgets and macros when importing", function() {
var wiki = new $tw.Wiki(); var wiki = new $tw.Wiki();
// Add some tiddlers // Add some tiddlers
wiki.addTiddlers([ wiki.addTiddlers([
@ -699,6 +699,20 @@ describe("Widget module", function() {
expect(wrapper.innerHTML).toBe("<p>Aval Bval Cval</p>"); expect(wrapper.innerHTML).toBe("<p>Aval Bval Cval</p>");
}); });
it("should skip parameters widgets when importing", function() {
var wiki = new $tw.Wiki();
// Add some tiddlers
wiki.addTiddlers([
{title: "B", text: "<$parameters bee=nothing><$set name='B' value='Bval'>\n\ndummy text</$set></$parameters>"},
]);
var text = "\\import B\n<<B>>";
var widgetNode = createWidgetNode(parseText(text,wiki),wiki);
// Render the widget node to the DOM
var wrapper = renderWidgetNode(widgetNode);
// Test the rendering
expect(wrapper.innerHTML).toBe("<p>Bval</p>");
});
it("can have more than one macroDef variable imported", function() { it("can have more than one macroDef variable imported", function() {
var wiki = new $tw.Wiki(); var wiki = new $tw.Wiki();
wiki.addTiddlers([ wiki.addTiddlers([