|
|
|
|
@@ -41,30 +41,43 @@ TranscludeWidget.prototype.execute = function() {
|
|
|
|
|
this.collectAttributes();
|
|
|
|
|
this.collectStringParameters();
|
|
|
|
|
this.collectSlotFillParameters();
|
|
|
|
|
// Get the target text and parse tree nodes that we are transcluding
|
|
|
|
|
var target = this.getTransclusionTarget(),
|
|
|
|
|
parseTreeNodes;
|
|
|
|
|
this.sourceText = target.text;
|
|
|
|
|
this.parserType = target.type;
|
|
|
|
|
this.parseAsInline = target.parseAsInline;
|
|
|
|
|
// Determine whether we're being used in inline or block mode
|
|
|
|
|
var parseAsInline = !this.parseTreeNode.isBlock;
|
|
|
|
|
if(this.transcludeMode === "inline") {
|
|
|
|
|
parseAsInline = true;
|
|
|
|
|
} else if(this.transcludeMode === "block") {
|
|
|
|
|
parseAsInline = false;
|
|
|
|
|
}
|
|
|
|
|
// Set 'thisTiddler'
|
|
|
|
|
this.setVariable("thisTiddler",this.transcludeTitle);
|
|
|
|
|
var parseTreeNodes, target;
|
|
|
|
|
// Process the transclusion according to the output type
|
|
|
|
|
switch(this.transcludeOutput || "text/html") {
|
|
|
|
|
case "text/html":
|
|
|
|
|
// Return the parse tree nodes
|
|
|
|
|
// Return the parse tree nodes of the target
|
|
|
|
|
target = this.parseTransclusionTarget(parseAsInline);
|
|
|
|
|
this.parseAsInline = target.parseAsInline;
|
|
|
|
|
parseTreeNodes = target.parseTreeNodes;
|
|
|
|
|
break;
|
|
|
|
|
case "text/raw":
|
|
|
|
|
// Just return the raw text
|
|
|
|
|
parseTreeNodes = [{type: "text", text: this.sourceText}];
|
|
|
|
|
target = this.getTransclusionTarget();
|
|
|
|
|
parseTreeNodes = [{type: "text", text: target.text}];
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
// text/plain
|
|
|
|
|
var plainText = this.wiki.renderText("text/plain",this.parserType,this.sourceText,{parentWidget: this});
|
|
|
|
|
parseTreeNodes = [{type: "text", text: plainText}];
|
|
|
|
|
// "text/plain" is the plain text result of wikifying the text
|
|
|
|
|
target = this.parseTransclusionTarget(parseAsInline);
|
|
|
|
|
var widgetNode = this.wiki.makeWidget(target.parser,{
|
|
|
|
|
parentWidget: this,
|
|
|
|
|
document: $tw.fakeDocument
|
|
|
|
|
});
|
|
|
|
|
var container = $tw.fakeDocument.createElement("div");
|
|
|
|
|
widgetNode.render(container,null);
|
|
|
|
|
parseTreeNodes = [{type: "text", text: container.textContent}];
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
this.sourceText = target.text;
|
|
|
|
|
this.parserType = target.type;
|
|
|
|
|
// Set the legacy transclusion context variables only if we're not transcluding a variable
|
|
|
|
|
if(!this.transcludeVariable) {
|
|
|
|
|
var recursionMarker = this.makeRecursionMarker();
|
|
|
|
|
@@ -161,17 +174,44 @@ TranscludeWidget.prototype.collectSlotFillParameters = function() {
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
Get transcluded parse tree nodes as an object {text:,type:,parseTreeNodes:,parseAsInline:}
|
|
|
|
|
Get transcluded details as an object {text:,type:}
|
|
|
|
|
*/
|
|
|
|
|
TranscludeWidget.prototype.getTransclusionTarget = function() {
|
|
|
|
|
var self = this;
|
|
|
|
|
// Determine whether we're being used in inline or block mode
|
|
|
|
|
var parseAsInline = !this.parseTreeNode.isBlock;
|
|
|
|
|
if(this.transcludeMode === "inline") {
|
|
|
|
|
parseAsInline = true;
|
|
|
|
|
} else if(this.transcludeMode === "block") {
|
|
|
|
|
parseAsInline = false;
|
|
|
|
|
var text;
|
|
|
|
|
// Return the text and type of the target
|
|
|
|
|
if(this.hasAttribute("$variable")) {
|
|
|
|
|
if(this.transcludeVariable) {
|
|
|
|
|
// Transcluding a variable
|
|
|
|
|
var variableInfo = this.getVariableInfo(this.transcludeVariable,{params: this.getOrderedTransclusionParameters()});
|
|
|
|
|
text = variableInfo.text;
|
|
|
|
|
return {
|
|
|
|
|
text: variableInfo.text,
|
|
|
|
|
type: this.transcludeType
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// Transcluding a text reference
|
|
|
|
|
var parserInfo = this.wiki.getTextReferenceParserInfo(
|
|
|
|
|
this.transcludeTitle,
|
|
|
|
|
this.transcludeField,
|
|
|
|
|
this.transcludeIndex,
|
|
|
|
|
{
|
|
|
|
|
subTiddler: this.transcludeSubTiddler,
|
|
|
|
|
defaultType: this.transcludeType
|
|
|
|
|
});
|
|
|
|
|
return {
|
|
|
|
|
text: parserInfo.text,
|
|
|
|
|
type: parserInfo.type
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
Get transcluded parse tree nodes as an object {text:,type:,parseTreeNodes:,parseAsInline:}
|
|
|
|
|
*/
|
|
|
|
|
TranscludeWidget.prototype.parseTransclusionTarget = function(parseAsInline) {
|
|
|
|
|
var self = this;
|
|
|
|
|
var parser;
|
|
|
|
|
// Get the parse tree
|
|
|
|
|
if(this.hasAttribute("$variable")) {
|
|
|
|
|
@@ -237,7 +277,7 @@ TranscludeWidget.prototype.getTransclusionTarget = function() {
|
|
|
|
|
}
|
|
|
|
|
$tw.utils.addAttributeToParseTreeNode(parser.tree[0],name,param["default"])
|
|
|
|
|
});
|
|
|
|
|
} else if(srcVariable && (srcVariable.isMacroDefinition || !srcVariable.isFunctionDefinition)) {
|
|
|
|
|
} else if(srcVariable && !srcVariable.isFunctionDefinition) {
|
|
|
|
|
// For macros and ordinary variables, wrap the parse tree in a vars widget assigning the parameters to variables named "__paramname__"
|
|
|
|
|
parser = {
|
|
|
|
|
tree: [
|
|
|
|
|
@@ -269,22 +309,13 @@ TranscludeWidget.prototype.getTransclusionTarget = function() {
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
// Return the parse tree
|
|
|
|
|
if(parser) {
|
|
|
|
|
return {
|
|
|
|
|
parseTreeNodes: parser.tree,
|
|
|
|
|
parseAsInline: parseAsInline,
|
|
|
|
|
text: parser.source,
|
|
|
|
|
type: parser.type
|
|
|
|
|
};
|
|
|
|
|
} else {
|
|
|
|
|
// If there's no parse tree then return the missing slot value
|
|
|
|
|
return {
|
|
|
|
|
parseTreeNodes: (this.slotFillParseTrees["ts-missing"] || []),
|
|
|
|
|
parseAsInline: parseAsInline,
|
|
|
|
|
text: null,
|
|
|
|
|
type: null
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
return {
|
|
|
|
|
parser: parser,
|
|
|
|
|
parseTreeNodes: parser ? parser.tree : (this.slotFillParseTrees["ts-missing"] || []),
|
|
|
|
|
parseAsInline: parseAsInline,
|
|
|
|
|
text: parser && parser.source,
|
|
|
|
|
type: parser && parser.type
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|