diff --git a/core/modules/parsers/wikiparser/rules/block/transcludeblock.js b/core/modules/parsers/wikiparser/rules/block/transcludeblock.js index e7bd0c9da..a3765e461 100644 --- a/core/modules/parsers/wikiparser/rules/block/transcludeblock.js +++ b/core/modules/parsers/wikiparser/rules/block/transcludeblock.js @@ -23,25 +23,25 @@ exports.name = "transclude"; exports.init = function(parser) { this.parser = parser; // Regexp to match - this.matchRegExp = /\{\{([^\{\}\|]+)(?:\|([^\{\}]+))?\}([^\}]*)\}/mg; + this.matchRegExp = /\{\{([^\{\}\|]+)(?:\|([^\{\}]+))?\}([^\}]*)\}(?:\.(\S+))?(?:\r?\n|$)/mg; }; -exports.parse = function(match,isBlock) { +exports.parse = function() { // Move past the match this.parser.pos = this.matchRegExp.lastIndex; // Get the match details var targetTitle = this.match[1], tooltip = this.match[2], - style = this.match[3]; - // Parse any class definitions - var classes = this.parser.parseClasses(); + style = this.match[3], + classes = this.match[4]; // Return the transclude widget var node = { type: "widget", tag: "transclude", attributes: { target: {type: "string", value: targetTitle} - } + }, + isBlock: true }; if(tooltip) { node.attributes.tooltip = {type: "string", value: tooltip}; @@ -49,8 +49,8 @@ exports.parse = function(match,isBlock) { if(style) { node.attributes.style = {type: "string", value: style}; } - if(classes.length > 0) { - node.attributes["class"] = {type: "string", value: classes.join(" ")}; + if(classes) { + node.attributes["class"] = {type: "string", value: classes.split(".").join(" ")}; } return [node]; }; diff --git a/core/modules/parsers/wikiparser/rules/inline/transcludeinline.js b/core/modules/parsers/wikiparser/rules/inline/transcludeinline.js new file mode 100644 index 000000000..77a0e1956 --- /dev/null +++ b/core/modules/parsers/wikiparser/rules/inline/transcludeinline.js @@ -0,0 +1,57 @@ +/*\ +title: $:/core/modules/parsers/wikiparser/rules/inline/transcludeinline.js +type: application/javascript +module-type: wiki-inline-rule + +Wiki text rule for inline-level transclusion. For example: + +{{{ +{{MyTiddler}} +{{MyTiddler|tooltip}} +{{MyTiddler}width:40;height:50;}.class.class +}}} + +\*/ +(function(){ + +/*jslint node: true, browser: true */ +/*global $tw: false */ +"use strict"; + +exports.name = "transclude"; + +exports.init = function(parser) { + this.parser = parser; + // Regexp to match + this.matchRegExp = /\{\{([^\{\}\|]+)(?:\|([^\{\}]+))?\}([^\}]*)\}(?:\.(\S+))?/mg; +}; + +exports.parse = function() { + // Move past the match + this.parser.pos = this.matchRegExp.lastIndex; + // Get the match details + var targetTitle = this.match[1], + tooltip = this.match[2], + style = this.match[3], + classes = this.match[4]; + // Return the transclude widget + var node = { + type: "widget", + tag: "transclude", + attributes: { + target: {type: "string", value: targetTitle} + } + }; + if(tooltip) { + node.attributes.tooltip = {type: "string", value: tooltip}; + } + if(style) { + node.attributes.style = {type: "string", value: style}; + } + if(classes) { + node.attributes["class"] = {type: "string", value: classes.split(".").join(" ")}; + } + return [node]; +}; + +})(); diff --git a/core/modules/parsers/wikiparser/wikiparser.js b/core/modules/parsers/wikiparser/wikiparser.js index 412cd5c8c..47ff76b58 100644 --- a/core/modules/parsers/wikiparser/wikiparser.js +++ b/core/modules/parsers/wikiparser/wikiparser.js @@ -45,7 +45,7 @@ var WikiParser = function(vocabulary,type,text,options) { this.blockRules = this.instantiateRules(this.vocabulary.blockRuleClasses,this.pos); this.inlineRules = this.instantiateRules(this.vocabulary.inlineRuleClasses,this.pos); // Parse the text into inline runs or blocks - if(this.type === "text/vnd.tiddlywiki-run") { + if(options.parseAsInline) { this.tree = this.parseInlineRun(); } else { this.tree = this.parseBlocks(); @@ -218,8 +218,8 @@ WikiParser.prototype.parseInlineRun = function(terminatorRegExp,options) { WikiParser.prototype.parseInlineRunUnterminated = function(options) { var tree = []; - // Find the next occurrence of a runrule - var nextMatch = this.findNextMatch(this.runRules,this.pos); + // Find the next occurrence of an inline rule + var nextMatch = this.findNextMatch(this.inlineRules,this.pos); // Loop around the matches until we've reached the end of the text while(this.pos < this.sourceLength && nextMatch) { // Process the text preceding the run rule @@ -230,7 +230,7 @@ WikiParser.prototype.parseInlineRunUnterminated = function(options) { // Process the run rule tree.push.apply(tree,nextMatch.rule.parse()); // Look for the next run rule - nextMatch = this.findNextMatch(this.runRules,this.pos); + nextMatch = this.findNextMatch(this.inlineRules,this.pos); } // Process the remaining text if(this.pos < this.sourceLength) { diff --git a/core/modules/rendertree/renderers/widget.js b/core/modules/rendertree/renderers/widget.js index 335fcbc07..7ab3f5284 100644 --- a/core/modules/rendertree/renderers/widget.js +++ b/core/modules/rendertree/renderers/widget.js @@ -77,7 +77,7 @@ WidgetRenderer.prototype.render = function(type) { WidgetRenderer.prototype.renderInDom = function() { // Create the wrapper element - this.domNode = document.createElement("span"); + this.domNode = document.createElement(this.parseTreeNode.isBlock ? "div" : "span"); this.domNode.setAttribute("data-widget-type",this.parseTreeNode.tag); this.domNode.setAttribute("data-widget-attr",JSON.stringify(this.attributes)); // Render the widget if we've got one diff --git a/core/modules/widgets/transclude.js b/core/modules/widgets/transclude.js index 0aac98bdb..8989604c0 100644 --- a/core/modules/widgets/transclude.js +++ b/core/modules/widgets/transclude.js @@ -73,7 +73,7 @@ exports.generateChildNodes = function() { })) { templateParseTree = [{type: "text", text: "Tiddler recursion error in transclude widget"}]; } else { - var parser = this.renderer.renderTree.wiki.new_parseTiddler(this.templateTitle); + var parser = this.renderer.renderTree.wiki.new_parseTiddler(this.templateTitle,{parseAsInline: !this.renderer.parseTreeNode.isBlock}); templateParseTree = parser ? parser.tree : []; } } diff --git a/core/modules/wiki.js b/core/modules/wiki.js index 31d8c6b02..5c22f8992 100644 --- a/core/modules/wiki.js +++ b/core/modules/wiki.js @@ -363,19 +363,26 @@ exports.new_initParsers = function() { /* Parse a block of text of a specified MIME type + type: content type of text to be parsed + text: text + options: see below +Options include: + parseAsInline: if true, the text of the tiddler will be parsed as an inline run */ -exports.new_parseText = function(type,text) { - return this.vocabulary.parseText(type,text); +exports.new_parseText = function(type,text,options) { + return this.vocabulary.parseText(type,text,options); }; /* Parse a tiddler according to its MIME type */ exports.new_parseTiddler = function(title,options) { - var tiddler = this.getTiddler(title), + options = options || {}; + var cacheType = options.parseAsInline ? "newInlineParseTree" : "newBlockParseTree", + tiddler = this.getTiddler(title), self = this; - return tiddler ? this.getCacheForTiddler(title,"newParseTree",function() { - return self.new_parseText(tiddler.fields.type,tiddler.fields.text); + return tiddler ? this.getCacheForTiddler(title,cacheType,function() { + return self.new_parseText(tiddler.fields.type,tiddler.fields.text,options); }) : null; }; diff --git a/core/modules/wikivocabulary.js b/core/modules/wikivocabulary.js index f69f3232d..7fd955db4 100644 --- a/core/modules/wikivocabulary.js +++ b/core/modules/wikivocabulary.js @@ -22,8 +22,20 @@ var WikiVocabulary = function(options) { this.widgetClasses = $tw.modules.createClassesFromModules("widget",$tw.WidgetBase); }; -WikiVocabulary.prototype.parseText = function(type,text) { - return new $tw.WikiParser(this,type,text,{wiki: this.wiki}); +/* +Parse a block of text of a specified MIME type + type: content type of text to be parsed + text: text + options: see below +Options include: + parseAsInline: if true, the text of the tiddler will be parsed as an inline run +*/ +WikiVocabulary.prototype.parseText = function(type,text,options) { + options = options || {}; + return new $tw.WikiParser(this,type,text,{ + parseAsInline: options.parseAsInline, + wiki: this.wiki + }); }; exports.WikiVocabulary = WikiVocabulary; diff --git a/core/templates/NewPageTemplate.tid b/core/templates/NewPageTemplate.tid index 15a8d9888..6594fb41b 100644 --- a/core/templates/NewPageTemplate.tid +++ b/core/templates/NewPageTemplate.tid @@ -17,6 +17,8 @@ some
thing {{Acknowledgements}width:40;height:50;}.one +And this is an inline transclusion {{Acknowledgements}width:40;height:50;}.one + --- {{{