From 698224556ea0901adf2d04cd5d536edd652f700f Mon Sep 17 00:00:00 2001 From: Jermolene Date: Tue, 6 Nov 2018 15:29:13 +0000 Subject: [PATCH] Avoid wikify widget in TOC macro Fixing the most egregious problem from #3517 @pmario can you kindly retest? --- core/modules/widgets/qualify.js | 66 +++++++++++++++++++++++++++++++++ core/wiki/macros/toc.tid | 24 ++++-------- 2 files changed, 74 insertions(+), 16 deletions(-) create mode 100644 core/modules/widgets/qualify.js diff --git a/core/modules/widgets/qualify.js b/core/modules/widgets/qualify.js new file mode 100644 index 000000000..7597198ef --- /dev/null +++ b/core/modules/widgets/qualify.js @@ -0,0 +1,66 @@ +/*\ +title: $:/core/modules/widgets/qualify.js +type: application/javascript +module-type: widget + +Qualify text to a variable + +\*/ +(function(){ + +/*jslint node: true, browser: true */ +/*global $tw: false */ +"use strict"; + +var Widget = require("$:/core/modules/widgets/widget.js").widget; + +var QualifyWidget = function(parseTreeNode,options) { + this.initialise(parseTreeNode,options); +}; + +/* +Inherit from the base widget class +*/ +QualifyWidget.prototype = new Widget(); + +/* +Render this widget into the DOM +*/ +QualifyWidget.prototype.render = function(parent,nextSibling) { + this.parentDomNode = parent; + this.computeAttributes(); + this.execute(); + this.renderChildren(parent,nextSibling); +}; + +/* +Compute the internal state of the widget +*/ +QualifyWidget.prototype.execute = function() { + // Get our parameters + this.qualifyName = this.getAttribute("name"); + this.qualifyText = this.getAttribute("text"); + // Set context variable + if(this.qualifyName) { + this.setVariable(this.qualifyName,this.qualifyText + "-" + this.getStateQualifier()); + } + // Construct the child widgets + this.makeChildWidgets(); +}; + +/* +Selectively refreshes the widget if needed. Returns true if the widget or any of its children needed re-rendering +*/ +QualifyWidget.prototype.refresh = function(changedTiddlers) { + var changedAttributes = this.computeAttributes(); + if(changedAttributes.name || changedAttributes.text) { + this.refreshSelf(); + return true; + } else { + return this.refreshChildren(changedTiddlers); + } +}; + +exports.qualify = QualifyWidget; + +})(); diff --git a/core/wiki/macros/toc.tid b/core/wiki/macros/toc.tid index b2c0459e0..5ff68e8a2 100644 --- a/core/wiki/macros/toc.tid +++ b/core/wiki/macros/toc.tid @@ -32,9 +32,7 @@ tags: $:/tags/Macro \define toc-linked-expandable-body(tag,sort:"",itemClassFilter,exclude,path) -<$wikify name="toc-state" text=""" - <$macrocall $name="qualify" title={{{ [[$:/state/toc]addsuffix<__path__>addsuffix[-]addsuffix] }}} /> -"""> +<$qualify name="toc-state" text={{{ [[$:/state/toc]addsuffix<__path__>addsuffix[-]addsuffix] }}}> <$set name="toc-item-class" filter=<<__itemClassFilter__>> emptyValue="toc-item" value="toc-item-selected">
  • >> <$link> @@ -55,14 +53,12 @@ tags: $:/tags/Macro
  • - + \end \define toc-unlinked-expandable-body(tag,sort:"",itemClassFilter:" ",exclude,path) -<$wikify name="toc-state" text=""" - <$macrocall $name="qualify" title={{{ [[$:/state/toc]addsuffix<__path__>addsuffix[-]addsuffix] }}} /> -"""> +<$qualify name="toc-state" text={{{ [[$:/state/toc]addsuffix<__path__>addsuffix[-]addsuffix] }}}> <$set name="toc-item-class" filter=<<__itemClassFilter__>> emptyValue="toc-item" value="toc-item-selected">
  • >> <$reveal type="nomatch" state=<> text="open"> @@ -82,7 +78,7 @@ tags: $:/tags/Macro
  • - + \end \define toc-expandable-empty-message() @@ -102,9 +98,7 @@ tags: $:/tags/Macro \end \define toc-linked-selective-expandable-body(tag,sort:"",itemClassFilter:" ",exclude,path) -<$wikify name="toc-state" text=""" - <$macrocall $name="qualify" title={{{ [[$:/state/toc]addsuffix<__path__>addsuffix[-]addsuffix] }}} /> -"""> +<$qualify name="toc-state" text={{{ [[$:/state/toc]addsuffix<__path__>addsuffix[-]addsuffix] }}}> <$set name="toc-item-class" filter=<<__itemClassFilter__>> emptyValue="toc-item" value="toc-item-selected" >
  • >> <$link> @@ -127,13 +121,11 @@ tags: $:/tags/Macro
  • - + \end \define toc-unlinked-selective-expandable-body(tag,sort:"",itemClassFilter:" ",exclude,path) -<$wikify name="toc-state" text=""" - <$macrocall $name="qualify" title={{{ [[$:/state/toc]addsuffix<__path__>addsuffix[-]addsuffix] }}} /> -"""> +<$qualify name="toc-state" text={{{ [[$:/state/toc]addsuffix<__path__>addsuffix[-]addsuffix] }}}> <$set name="toc-item-class" filter=<<__itemClassFilter__>> emptyValue="toc-item" value="toc-item-selected">
  • >> <$list filter="[all[current]tagging[]limit[1]]" variable="ignore" emptyMessage="<$button class='tc-btn-invisible'>{{$:/core/images/blank}} <$view field='caption'><$view field='title'/>"> @@ -155,7 +147,7 @@ tags: $:/tags/Macro
  • - + \end \define toc-selective-expandable-empty-message()