1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-27 03:57:21 +00:00

Procedures and widgets inherit whitespace trim setting from their definition

This commit is contained in:
jeremy@jermolene.com 2022-05-23 15:30:33 +01:00
parent 170c4b1799
commit 22e7ec2381
7 changed files with 14 additions and 7 deletions

View File

@ -101,6 +101,9 @@ exports.parse = function() {
} else if(this.match[1] === "widget") { } else if(this.match[1] === "widget") {
parseTreeNodes[0].isWidgetDefinition = true; parseTreeNodes[0].isWidgetDefinition = true;
} }
if(this.parser.configTrimWhiteSpace) {
parseTreeNodes[0].configTrimWhiteSpace = true;
}
return parseTreeNodes; return parseTreeNodes;
}; };

View File

@ -32,6 +32,7 @@ options: see below:
parseAsInline: true to parse text as inline instead of block parseAsInline: true to parse text as inline instead of block
wiki: reference to wiki to use wiki: reference to wiki to use
_canonical_uri: optional URI of content if text is missing or empty _canonical_uri: optional URI of content if text is missing or empty
configTrimWhiteSpace: true to trim whitespace
*/ */
var WikiParser = function(type,text,options) { var WikiParser = function(type,text,options) {
this.wiki = options.wiki; this.wiki = options.wiki;
@ -46,7 +47,7 @@ var WikiParser = function(type,text,options) {
this.source = text || ""; this.source = text || "";
this.sourceLength = this.source.length; this.sourceLength = this.source.length;
// Flag for ignoring whitespace // Flag for ignoring whitespace
this.configTrimWhiteSpace = false; this.configTrimWhiteSpace = options.configTrimWhiteSpace !== undefined ? options.configTrimWhiteSpace : false;
// Set current parse position // Set current parse position
this.pos = 0; this.pos = 0;
// Start with empty output // Start with empty output

View File

@ -58,7 +58,8 @@ ImportVariablesWidget.prototype.execute = function(tiddlerList) {
isMacroDefinition: parseTreeNode.isMacroDefinition, isMacroDefinition: parseTreeNode.isMacroDefinition,
isFunctionDefinition: parseTreeNode.isFunctionDefinition, isFunctionDefinition: parseTreeNode.isFunctionDefinition,
isProcedureDefinition: parseTreeNode.isProcedureDefinition, isProcedureDefinition: parseTreeNode.isProcedureDefinition,
isWidgetDefinition: parseTreeNode.isWidgetDefinition isWidgetDefinition: parseTreeNode.isWidgetDefinition,
configTrimWhiteSpace: parseTreeNode.configTrimWhiteSpace
}; };
if (parseTreeNode.isMacroDefinition || parseTreeNode.isProcedureDefinition) { if (parseTreeNode.isMacroDefinition || parseTreeNode.isProcedureDefinition) {
// Macro definitions can be folded into // Macro definitions can be folded into

View File

@ -53,9 +53,9 @@ SetWidget.prototype.execute = function() {
} else if(this.parseTreeNode.isFunctionDefinition) { } else if(this.parseTreeNode.isFunctionDefinition) {
this.setVariable(this.setName,this.getValue(),this.parseTreeNode.params,undefined,{isFunctionDefinition: true}); this.setVariable(this.setName,this.getValue(),this.parseTreeNode.params,undefined,{isFunctionDefinition: true});
} else if(this.parseTreeNode.isProcedureDefinition) { } else if(this.parseTreeNode.isProcedureDefinition) {
this.setVariable(this.setName,this.getValue(),this.parseTreeNode.params,undefined,{isProcedureDefinition: true}); this.setVariable(this.setName,this.getValue(),this.parseTreeNode.params,undefined,{isProcedureDefinition: true, configTrimWhiteSpace: this.parseTreeNode.configTrimWhiteSpace});
} else if(this.parseTreeNode.isWidgetDefinition) { } else if(this.parseTreeNode.isWidgetDefinition) {
this.setVariable(this.setName,this.getValue(),this.parseTreeNode.params,undefined,{isWidgetDefinition: true}); this.setVariable(this.setName,this.getValue(),this.parseTreeNode.params,undefined,{isWidgetDefinition: true, configTrimWhiteSpace: this.parseTreeNode.configTrimWhiteSpace});
} else { } else {
this.setVariable(this.setName,this.getValue()); this.setVariable(this.setName,this.getValue());
} }

View File

@ -179,7 +179,7 @@ TranscludeWidget.prototype.getTransclusionTarget = function() {
if(srcVariable.isCacheable && srcVariable[mode]) { if(srcVariable.isCacheable && srcVariable[mode]) {
parser = srcVariable[mode]; parser = srcVariable[mode];
} else { } else {
parser = this.wiki.parseText(this.transcludeType,variableInfo.text || "",{parseAsInline: parseAsInline}); parser = this.wiki.parseText(this.transcludeType,variableInfo.text || "",{parseAsInline: parseAsInline, configTrimWhiteSpace: srcVariable.configTrimWhiteSpace});
if(srcVariable.isCacheable) { if(srcVariable.isCacheable) {
srcVariable[mode] = parser; srcVariable[mode] = parser;
} }

View File

@ -104,7 +104,8 @@ Widget.prototype.setVariable = function(name,value,params,isMacroDefinition,opti
isMacroDefinition: !!isMacroDefinition, isMacroDefinition: !!isMacroDefinition,
isFunctionDefinition: !!options.isFunctionDefinition, isFunctionDefinition: !!options.isFunctionDefinition,
isProcedureDefinition: !!options.isProcedureDefinition, isProcedureDefinition: !!options.isProcedureDefinition,
isWidgetDefinition: !!options.isWidgetDefinition isWidgetDefinition: !!options.isWidgetDefinition,
configTrimWhiteSpace: !!options.configTrimWhiteSpace
}; };
}; };

View File

@ -988,7 +988,8 @@ exports.parseText = function(type,text,options) {
return new Parser(type,text,{ return new Parser(type,text,{
parseAsInline: options.parseAsInline, parseAsInline: options.parseAsInline,
wiki: this, wiki: this,
_canonical_uri: options._canonical_uri _canonical_uri: options._canonical_uri,
configTrimWhiteSpace: options.configTrimWhiteSpace
}); });
}; };