diff --git a/core/modules/filterrunprefixes/then.js b/core/modules/filterrunprefixes/then.js new file mode 100644 index 000000000..9f6d5c76a --- /dev/null +++ b/core/modules/filterrunprefixes/then.js @@ -0,0 +1,32 @@ +/*\ +title: $:/core/modules/filterrunprefixes/then.js +type: application/javascript +module-type: filterrunprefix + +Replace results of previous runs unless empty + +\*/ +(function(){ + +/*jslint node: true, browser: true */ +/*global $tw: false */ +"use strict"; + +/* +Export our filter prefix function +*/ +exports.then = function(operationSubFunction) { + return function(results,source,widget) { + if(results.length !== 0) { + // Only run if previous run(s) produced results + var thisRunResult = operationSubFunction(source,widget); + if(thisRunResult.length !== 0) { + // Replace results only if this run actually produces a result + results.clear(); + results.pushTop(thisRunResult); + } + } + }; +}; + +})(); diff --git a/core/modules/filters/substitute.js b/core/modules/filters/substitute.js new file mode 100644 index 000000000..655ef7321 --- /dev/null +++ b/core/modules/filters/substitute.js @@ -0,0 +1,36 @@ +/*\ +title: $:/core/modules/filters/substitute.js +type: application/javascript +module-type: filteroperator + +Filter operator for substituting variables and embedded filter expressions with their corresponding values + +\*/ +(function(){ + +/*jslint node: true, browser: true */ +/*global $tw: false */ +"use strict"; + +/* +Export our filter function +*/ +exports.substitute = function(source,operator,options) { + var results = [], + operands = []; + $tw.utils.each(operator.operands,function(operand,index){ + operands.push({ + name: (index + 1).toString(), + value: operand + }); + }); + source(function(tiddler,title) { + if(title) { + results.push(options.wiki.getSubstitutedText(title,options.widget,{substitutions:operands})); + } + }); + return results; +}; + +})(); + \ No newline at end of file diff --git a/core/modules/parsers/parseutils.js b/core/modules/parsers/parseutils.js index 6a0902c6f..1f86dd909 100644 --- a/core/modules/parsers/parseutils.js +++ b/core/modules/parsers/parseutils.js @@ -305,10 +305,11 @@ exports.parseAttribute = function(source,pos) { start: pos }; // Define our regexps - var reAttributeName = /([^\/\s>"'=]+)/g, - reUnquotedAttribute = /([^\/\s<>"'=]+)/g, + var reAttributeName = /([^\/\s>"'`=]+)/g, + reUnquotedAttribute = /([^\/\s<>"'`=]+)/g, reFilteredValue = /\{\{\{([\S\s]+?)\}\}\}/g, - reIndirectValue = /\{\{([^\}]+)\}\}/g; + reIndirectValue = /\{\{([^\}]+)\}\}/g, + reSubstitutedValue = /(?:```([\s\S]*?)```|`([^`]|[\S\s]*?)`)/g; // Skip whitespace pos = $tw.utils.skipWhiteSpace(source,pos); // Get the attribute name @@ -361,8 +362,15 @@ exports.parseAttribute = function(source,pos) { node.type = "macro"; node.value = macroInvocation; } else { - node.type = "string"; - node.value = "true"; + var substitutedValue = $tw.utils.parseTokenRegExp(source,pos,reSubstitutedValue); + if(substitutedValue) { + pos = substitutedValue.end; + node.type = "substituted"; + node.rawValue = substitutedValue.match[1] || substitutedValue.match[2]; + } else { + node.type = "string"; + node.value = "true"; + } } } } diff --git a/core/modules/widgets/transclude.js b/core/modules/widgets/transclude.js index 9902f7632..7e63ff156 100755 --- a/core/modules/widgets/transclude.js +++ b/core/modules/widgets/transclude.js @@ -177,7 +177,7 @@ TranscludeWidget.prototype.getTransclusionTarget = function() { var variableInfo = this.getVariableInfo(this.transcludeVariable,{params: this.getOrderedTransclusionParameters()}), srcVariable = variableInfo && variableInfo.srcVariable; if(variableInfo.text) { - if(srcVariable.isFunctionDefinition) { + if(srcVariable && srcVariable.isFunctionDefinition) { var result = (variableInfo.resultList ? variableInfo.resultList[0] : variableInfo.text) || ""; parser = { tree: [{ @@ -207,7 +207,7 @@ TranscludeWidget.prototype.getTransclusionTarget = function() { if(variableInfo.isCacheable && srcVariable[cacheKey]) { parser = srcVariable[cacheKey]; } else { - parser = this.wiki.parseText(this.transcludeType,variableInfo.text || "",{parseAsInline: parseAsInline, configTrimWhiteSpace: srcVariable.configTrimWhiteSpace}); + parser = this.wiki.parseText(this.transcludeType,variableInfo.text || "",{parseAsInline: parseAsInline, configTrimWhiteSpace: srcVariable && srcVariable.configTrimWhiteSpace}); if(variableInfo.isCacheable) { srcVariable[cacheKey] = parser; } @@ -215,7 +215,7 @@ TranscludeWidget.prototype.getTransclusionTarget = function() { } if(parser) { // Add parameters widget for procedures and custom widgets - if(srcVariable.isProcedureDefinition || srcVariable.isWidgetDefinition) { + if(srcVariable && (srcVariable.isProcedureDefinition || srcVariable.isWidgetDefinition)) { parser = { tree: [ { @@ -234,7 +234,7 @@ TranscludeWidget.prototype.getTransclusionTarget = function() { } $tw.utils.addAttributeToParseTreeNode(parser.tree[0],name,param["default"]) }); - } else if(srcVariable.isMacroDefinition || !srcVariable.isFunctionDefinition) { + } else if(srcVariable && (srcVariable.isMacroDefinition || !srcVariable.isFunctionDefinition)) { // For macros and ordinary variables, wrap the parse tree in a vars widget assigning the parameters to variables named "__paramname__" parser = { tree: [ diff --git a/core/modules/widgets/widget.js b/core/modules/widgets/widget.js index 8ffee0ab7..0394c636f 100755 --- a/core/modules/widgets/widget.js +++ b/core/modules/widgets/widget.js @@ -182,8 +182,7 @@ Widget.prototype.getVariableInfo = function(name,options) { } return { text: text, - resultList: [text], - srcVariable: {} + resultList: [text] }; }; @@ -380,6 +379,8 @@ Widget.prototype.computeAttribute = function(attribute) { } else if(attribute.type === "macro") { var variableInfo = this.getVariableInfo(attribute.value.name,{params: attribute.value.params}); value = variableInfo.text; + } else if(attribute.type === "substituted") { + value = this.wiki.getSubstitutedText(attribute.rawValue,this) || ""; } else { // String attribute value = attribute.value; } diff --git a/core/modules/wiki.js b/core/modules/wiki.js index ca31da8d2..93e818f21 100755 --- a/core/modules/wiki.js +++ b/core/modules/wiki.js @@ -1063,6 +1063,34 @@ exports.getTextReferenceParserInfo = function(title,field,index,options) { return parserInfo; } +/* +Parse a block of text of a specified MIME type + text: text on which to perform substitutions + widget + options: see below +Options include: + substitutions: an optional array of substitutions +*/ +exports.getSubstitutedText = function(text,widget,options) { + options = options || {}; + text = text || ""; + var self = this, + substitutions = options.substitutions || [], + output; + // Evaluate embedded filters and substitute with first result + output = text.replace(/\$\{([\S\s]+?)\}\$/g, function(match,filter) { + return self.filterTiddlers(filter,widget)[0] || ""; + }); + // Process any substitutions provided in options + $tw.utils.each(substitutions,function(substitute) { + output = $tw.utils.replaceString(output,new RegExp("\\$" + $tw.utils.escapeRegExp(substitute.name) + "\\$","mg"),substitute.value); + }); + // Substitute any variable references with their values + return output.replace(/\$\((\w+)\)\$/g, function(match,varname) { + return widget.getVariable(varname,{defaultValue: ""}) + }); +}; + /* Make a widget tree for a parse tree parser: parser object diff --git a/core/ui/MoreSideBar/Tags.tid b/core/ui/MoreSideBar/Tags.tid index 0a4727bc3..b1b67bb67 100644 --- a/core/ui/MoreSideBar/Tags.tid +++ b/core/ui/MoreSideBar/Tags.tid @@ -3,15 +3,14 @@ tags: $:/tags/MoreSideBar caption: {{$:/language/SideBar/Tags/Caption}} \whitespace trim - <$let tv-config-toolbar-icons="yes" tv-config-toolbar-text="yes" tv-config-toolbar-class="">
- {{$:/core/ui/Buttons/tag-manager}} + {{$:/core/ui/Buttons/tag-manager}}
<$list filter={{$:/core/Filters/AllTags!!filter}}>
- <$transclude tiddler="$:/core/ui/TagTemplate"/> + <$transclude tiddler="$:/core/ui/TagTemplate"/>

diff --git a/core/ui/TagPickerTagTemplate.tid b/core/ui/TagPickerTagTemplate.tid index 6329f86ae..9e8689153 100644 --- a/core/ui/TagPickerTagTemplate.tid +++ b/core/ui/TagPickerTagTemplate.tid @@ -2,22 +2,29 @@ title: $:/core/ui/TagPickerTagTemplate \whitespace trim <$button class=<> tag="a" tooltip={{$:/language/EditTemplate/Tags/Add/Button/Hint}}> -<$list filter="[minlength[1]]"> -<$action-listops $tiddler=<> $field=<> $subfilter="[]"/> - -<$set name="currentTiddlerCSSEscaped" value={{{ [escapecss[]] }}}> -<$action-sendmessage $message="tm-focus-selector" $param=<> preventScroll="true"/> - -<> -<$list filter="[minlength[1]]"> -<$action-setfield $tiddler=<> text="yes"/> - -<> -<$set name="backgroundColor" value={{{ [] :cascade[all[shadows+tiddlers]tag[$:/tags/TiddlerColourFilter]!is[draft]get[text]] }}}> -<$wikify name="foregroundColor" text="""<$macrocall $name="contrastcolour" target=<> fallbackTarget=<> colourA=<> colourB=<>/>"""> -> data-tag-title=<> > -{{||$:/core/ui/TiddlerIcon}}<$view field="title" format="text"/> - - - + <$list filter="[minlength[1]]"> + <$action-listops $tiddler=<> $field=<> $subfilter="[]"/> + + <$set name="currentTiddlerCSSEscaped" value={{{ [escapecss[]] }}}> + <$action-sendmessage $message="tm-focus-selector" $param=<> preventScroll="true"/> + + <> + <$list filter="[minlength[1]]"> + <$action-setfield $tiddler=<> text="yes"/> + + <> + <$set name="backgroundColor" + value={{{ [] :cascade[all[shadows+tiddlers]tag[$:/tags/TiddlerColourFilter]!is[draft]get[text]] }}} + > + <$wikify name="foregroundColor" + text="""<$macrocall $name="contrastcolour" target=<> fallbackTarget=<> colourA=<> colourB=<>/>""" + > + > + data-tag-title=<> + > + {{||$:/core/ui/TiddlerIcon}}<$view field="title" format="text"/> + + + diff --git a/core/ui/TagTemplate.tid b/core/ui/TagTemplate.tid index f137f22a0..49e836671 100644 --- a/core/ui/TagTemplate.tid +++ b/core/ui/TagTemplate.tid @@ -3,16 +3,23 @@ title: $:/core/ui/TagTemplate \whitespace trim >> <$set name="transclusion" value=<>> -<$macrocall $name="tag-pill-body" tag=<> icon={{{ [] :cascade[all[shadows+tiddlers]tag[$:/tags/TiddlerIconFilter]!is[draft]get[text]] }}} colour={{{ [] :cascade[all[shadows+tiddlers]tag[$:/tags/TiddlerColourFilter]!is[draft]get[text]] }}} palette={{$:/palette}} element-tag="""$button""" element-attributes="""popup=<> dragFilter='[all[current]tagging[]]' tag='span'"""/> -<$reveal state=<> type="popup" position="below" animate="yes" class="tc-drop-down"> -<$set name="tv-show-missing-links" value="yes"> -<$transclude tiddler="$:/core/ui/ListItemTemplate"/> - -<$list filter="[all[shadows+tiddlers]tag[$:/tags/TagDropdown]!has[draft.of]]" variable="listItem"> -<$transclude tiddler=<>/> - -
-<$macrocall $name="list-tagged-draggable" tag=<>/> - + <$macrocall $name="tag-pill-body" + tag=<> + icon={{{ [] :cascade[all[shadows+tiddlers]tag[$:/tags/TiddlerIconFilter]!is[draft]get[text]] }}} + colour={{{ [] :cascade[all[shadows+tiddlers]tag[$:/tags/TiddlerColourFilter]!is[draft]get[text]] }}} + palette={{$:/palette}} + element-tag="$button" + element-attributes="""popup=<> dragFilter="[all[current]tagging[]]" tag='span'""" + /> + <$reveal state=<> type="popup" position="below" animate="yes" class="tc-drop-down"> + <$set name="tv-show-missing-links" value="yes"> + <$transclude tiddler="$:/core/ui/ListItemTemplate"/> + + <$list filter="[all[shadows+tiddlers]tag[$:/tags/TagDropdown]!has[draft.of]]" variable="listItem"> + <$transclude tiddler=<>/> + +
+ <$macrocall $name="list-tagged-draggable" tag=<>/> +
diff --git a/core/wiki/macros/tag.tid b/core/wiki/macros/tag.tid index 3616fb97d..03dd8cb98 100644 --- a/core/wiki/macros/tag.tid +++ b/core/wiki/macros/tag.tid @@ -9,26 +9,50 @@ color:$(foregroundColor)$; \define tag-pill-inner(tag,icon,colour,fallbackTarget,colourA,colourB,element-tag,element-attributes,actions) +\whitespace trim <$vars foregroundColor=<> - backgroundColor="""$colour$""" -><$element-tag$ + backgroundColor=<<__colour__>> +> +<$element-tag$ $element-attributes$ class="tc-tag-label tc-btn-invisible" style=<> ->$actions$<$transclude tiddler="""$icon$"""/><$view tiddler=<<__tag__>> field="title" format="text" /> +> + <<__actions__>> + <$transclude tiddler=<<__icon__>>/> + <$view tiddler=<<__tag__>> field="title" format="text" /> + \end \define tag-pill-body(tag,icon,colour,palette,element-tag,element-attributes,actions) -<$macrocall $name="tag-pill-inner" tag=<<__tag__>> icon="""$icon$""" colour="""$colour$""" fallbackTarget={{$palette$##tag-background}} colourA={{$palette$##foreground}} colourB={{$palette$##background}} element-tag="""$element-tag$""" element-attributes="""$element-attributes$""" actions="""$actions$"""/> +\whitespace trim +<$macrocall $name="tag-pill-inner" + tag=<<__tag__>> + icon=<<__icon__>> + colour=<<__colour__>> + fallbackTarget={{$palette$##tag-background}} + colourA={{$palette$##foreground}} + colourB={{$palette$##background}} + element-tag=<<__element-tag__>> + element-attributes=<<__element-attributes__>> + actions=<<__actions__>> +/> \end \define tag-pill(tag,element-tag:"span",element-attributes:"",actions:"") \whitespace trim >> -<$let currentTiddler=<<__tag__>>> -<$macrocall $name="tag-pill-body" tag=<<__tag__>> icon={{{ [] :cascade[all[shadows+tiddlers]tag[$:/tags/TiddlerIconFilter]!is[draft]get[text]] }}} colour={{{ [] :cascade[all[shadows+tiddlers]tag[$:/tags/TiddlerColourFilter]!is[draft]get[text]] }}} palette={{$:/palette}} element-tag="""$element-tag$""" element-attributes="""$element-attributes$""" actions="""$actions$"""/> - + <$let currentTiddler=<<__tag__>>> + <$macrocall $name="tag-pill-body" + tag=<<__tag__>> + icon={{{ [] :cascade[all[shadows+tiddlers]tag[$:/tags/TiddlerIconFilter]!is[draft]get[text]] }}} + colour={{{ [] :cascade[all[shadows+tiddlers]tag[$:/tags/TiddlerColourFilter]!is[draft]get[text]] }}} + palette={{$:/palette}} + element-tag=<<__element-tag__>> + element-attributes=<<__element-attributes__>> + actions=<<__actions__>>/> + \end diff --git a/editions/prerelease/tiddlers/Release 5.3.0.tid b/editions/prerelease/tiddlers/Release 5.3.0.tid index cf1ce0098..a92cb7b5a 100644 --- a/editions/prerelease/tiddlers/Release 5.3.0.tid +++ b/editions/prerelease/tiddlers/Release 5.3.0.tid @@ -1,6 +1,6 @@ caption: 5.3.0 -created: 20230506164543446 -modified: 20230506164543446 +created: 20230624100932287 +modified: 20230624100932287 tags: ReleaseNotes title: Release 5.3.0 type: text/vnd.tiddlywiki @@ -28,31 +28,52 @@ The approach taken by this release is to add new functionality by extending and These changes lay the groundwork for macros and related features to be deprecated (which is the point at which users are advised not to use old features, and instead given clear pointers to the equivalent modern functionality). -The new transclusion architecture is not by itself sufficient to enable us to fully deprecate macros yet. To handle the remaining use cases we propose a new backtick quoted attribute format that allows for the substitution of variable values. See https://github.com/Jermolene/TiddlyWiki5/issues/6663 for details. +! Text Substitution Improvements + +<<.link-badge-added "https://github.com/Jermolene/TiddlyWiki5/pull/7526">> The new transclusion architecture is not by itself sufficient to enable us to fully deprecate macros yet. To handle most of the remaining use cases this release adds convenient new ways of using textual substitution without having to create a macro: + +Firstly, the new [[text substitution syntax for widget attributes|Substituted Attribute Values]] allows widget attributes to be assigned the value of a string with certain placeholders being replaced by their processed contents. For example: + +* Substitute variable names with the value with <$codeblock code="attr=`Current tiddler is $(currentTiddler)$`"/> +* Substitute filter expressions with the first value they return with <$codeblock code="attr=```There are ${ [tag[Done]count[]] }$ completed tasks```"/> + +Secondly, the new [[substitute operator|substitute Operator]] allows the same textual substitutions to be performed via a filter operator with the addition of positional parameters that use placeholders of the form `$1$`, `$2$`, `$3$` etc. + +``` +[[https://$1$/$(currentTiddler)$]substitute] +``` + +! HTTP Requests in WikiText + +<<.link-badge-added "https://github.com/Jermolene/TiddlyWiki5/pull/7422">> new [[WidgetMessage: tm-http-request]] for performing HTTP requests in WikiText. This opens up some exciting new opportunities: + +* Integration with Web-based APIs. The documentation includes an [[example of using the Zotero API|WidgetMessage: tm-http-request Example - Zotero]] to retrieve academic citation data +* Dynamic content loading: additional tiddlers can be imported dynamically after the main wiki has loaded ! Defaulting to Disabling CamelCase Links -<<.link-badge-updated "https://github.com/Jermolene/TiddlyWiki5/pull/7513">> CamelCase linking is now disabled by default. (Note that this wiki has CamelCase linking explicitly enabled) +<<.link-badge-updated "https://github.com/Jermolene/TiddlyWiki5/pull/7513">> CamelCase linking is now disabled by default for new wikis. (Note that this wiki has CamelCase linking explicitly enabled) ! Plugin Improvements +* <<.link-badge-updated "https://github.com/Jermolene/TiddlyWiki5/pull/7554">> Google Analytics plugin to use new GA4 code. Note that the update requires manual configuration to use the new "measurement ID" instead of the old "account ID" * <<.link-badge-extended "https://github.com/Jermolene/TiddlyWiki5/pull/7260">> Dynannotate pugin to support three additional search modes * <<.link-badge-fixed "https://github.com/Jermolene/TiddlyWiki5/pull/7365">> problem with [[BrowserStorage Plugin]] unnecessarily saving shadow tiddlers + +* <<.link-badge-improved "https://github.com/Jermolene/TiddlyWiki5/pull/7398">> [[BrowserStorage Plugin]] to request that browser storage be persisted without eviction * <<.link-badge-improved "https://github.com/Jermolene/TiddlyWiki5/pull/7493">> [[CodeMirror Plugin]] to add an option to make trailing spaces visible ! Translation improvement Improvements to the following translations: -* - -! Accessibility Improvements - -* +* German +* Polish +* Chinese ! Usability Improvements -* +* <<.link-badge-improved "https://github.com/Jermolene/TiddlyWiki5/pull/7524">> consistency of layout of "Settings" tab in $:/ControlPanel ! Widget Improvements @@ -62,15 +83,18 @@ Improvements to the following translations: * <<.link-badge-added "https://github.com/Jermolene/TiddlyWiki5/pull/7511"> new [[deserialize Operator]] for converting various textual representations of tiddlers into JSON data * <<.link-badge-extended "https://github.com/Jermolene/TiddlyWiki5/pull/7292">> [[format Operator]] to support converting Unix timestamps to TiddlyWiki's native date format - +* <<.link-badge-added "https://github.com/Jermolene/TiddlyWiki5/pull/7392">> new [[':then' filter run prefix|Then Filter Run Prefix]] ! Hackability Improvements * <<.link-badge-extended "https://github.com/Jermolene/TiddlyWiki5/pull/7413">> [[Core Icons]] to allow the size to be controlled with a parameter ** <<.warning """This change can cause problems with non-standard usage of the core icons where the text is directly rendered instead of being transcluded""">> * <<.link-badge-added "https://github.com/Jermolene/TiddlyWiki5/pull/7182">> new [[thisTiddler Variable]] that refers to the tiddler currently being rendered +* <<.link-badge-added "https://github.com/Jermolene/TiddlyWiki5/pull/7530">> `data-tag-title` attribute to all tag pills, allowing easier [[Custom tag pill styles]] * <<.link-badge-improved "https://github.com/Jermolene/TiddlyWiki5/pull/7332">> [[Story Tiddler Template Cascade]] handling to fall back to the default template if the output of the cascade is not valid * <<.link-badge-fixed "https://github.com/Jermolene/TiddlyWiki5/pull/7378">> missing file extensions for "audio/mpeg" files +* <<.link-badge-extended "https://github.com/Jermolene/TiddlyWiki5/pull/7417">> [[Table-of-Contents Macros]] to add consistent support for an ''exclude'' parameter +* <<.link-badge-added "https://github.com/Jermolene/TiddlyWiki5/commit/190613ad2989f70526f86eef17f524087f60eb72">> [[tv-config-static Variable]] for indicating static rendering ! Bug Fixes @@ -84,10 +108,6 @@ Improvements to the following translations: * <<.link-badge-fixed "https://github.com/Jermolene/TiddlyWiki5/commit/8e132948b6bec623d81d300fbe6dc3a0307bcc6d">> crash when transcluding a lazily loaded tiddler as an attribute value * <<.link-badge-fixed "https://github.com/Jermolene/TiddlyWiki5/issues/7462">> DiffTextWidget crash with missing or empty attributes -! Developer Improvements - -* - ! Node.js Improvements * <<.link-badge-extended "https://github.com/Jermolene/TiddlyWiki5/pull/7471">> [[WebServer Parameter: authenticated-user-header]] to require URI encoding of authenticated username header, permitting non-ASCII characters in usernames @@ -103,10 +123,15 @@ Improvements to the following translations: [[@Jermolene|https://github.com/Jermolene]] would like to thank the contributors to this release who have generously given their time to help improve TiddlyWiki: <<.contributors """ +AnthonyMuscio Arlen22 BramChen btheado +buggyj +carlo-carlombo +cdruan donmor +EvidentlyCube flibbles GameDungeon JoshuaFontany @@ -122,4 +147,5 @@ saqimtiaz tavin twMat yaisog +Zacharia2 """>> diff --git a/editions/test/tiddlers/tests/data/filters/substitute.tid b/editions/test/tiddlers/tests/data/filters/substitute.tid new file mode 100644 index 000000000..873d8e0ba --- /dev/null +++ b/editions/test/tiddlers/tests/data/filters/substitute.tid @@ -0,0 +1,40 @@ +title: Filters/substitute +description: Test substitute operator +type: text/vnd.tiddlywiki-multiple +tags: [[$:/tags/wiki-test-spec]] + +title: substitute filter data 1 +tags: Hello There [[Welcome to TiddlyWiki]] GettingStarted + +TiddlyWiki ++ +title: substitute filter data 2 + +The output of the filter `[[substitute filter data 1]tags[]]` is ${[[substitute filter data 1]tags[]]}$. ++ +title: substitute filter data 3 + +Welcome to $(projectname)$ $1$ $2$ $3$. Tiddlers starting with `substitute`: ${[prefix[substitute]format:titlelist[]join[ ]]}$. ++ +title: Output + +\whitespace trim +<$let projectname="TiddlyWiki"> +(<$text text={{{ [[]substitute[]] }}}/>) +(<$text text={{{ [[Hello There, welcome to $TiddlyWiki$]substitute[]] }}}/>) +(<$text text={{{ [[Welcome to $(projectname)$]substitute[]] }}}/>) +(<$text text={{{ [[Welcome to $(projectname)$ $1$]substitute[today]] }}}/>) +(<$text text={{{ [[This is not a valid embedded filter ${ hello )$]substitute[]] }}}/>) +(<$text text={{{ [{substitute filter data 2}substitute[]] }}}/>) +(<$text text={{{ [{substitute filter data 3}substitute[every],[day]] }}}/>) + ++ +title: ExpectedResult + +

() +(Hello There, welcome to $TiddlyWiki$) +(Welcome to TiddlyWiki) +(Welcome to TiddlyWiki today) +(This is not a valid embedded filter ${ hello )$) +(The output of the filter `[[substitute filter data 1]tags[]]` is Hello.) +(Welcome to TiddlyWiki every day $3$. Tiddlers starting with `substitute`: [[substitute filter data 1]] [[substitute filter data 2]] [[substitute filter data 3]].)

\ No newline at end of file diff --git a/editions/test/tiddlers/tests/data/widgets/SubstitutedAttributes.tid b/editions/test/tiddlers/tests/data/widgets/SubstitutedAttributes.tid new file mode 100644 index 000000000..408d202c6 --- /dev/null +++ b/editions/test/tiddlers/tests/data/widgets/SubstitutedAttributes.tid @@ -0,0 +1,19 @@ +title: Widgets/SubstitutedAttributes +description: Attributes specified as string that should have substitution performed. +type: text/vnd.tiddlywiki-multiple +tags: [[$:/tags/wiki-test-spec]] + +title: Output + +\whitespace trim +<$let project="TiddlyWiki" disabled="true"> +
+
+ + ++ +title: ExpectedResult + +

\ No newline at end of file diff --git a/editions/test/tiddlers/tests/test-html-parser.js b/editions/test/tiddlers/tests/test-html-parser.js index cdc8dee47..d2266ca5e 100644 --- a/editions/test/tiddlers/tests/test-html-parser.js +++ b/editions/test/tiddlers/tests/test-html-parser.js @@ -161,6 +161,16 @@ describe("HTML tag new parser tests", function() { expect($tw.utils.parseAttribute(" attrib1>",0)).toEqual( { type : 'string', value : 'true', start : 0, name : 'attrib1', end : 8 } ); + expect($tw.utils.parseAttribute("p=`blah` ",1)).toEqual(null); + expect($tw.utils.parseAttribute("p=`blah` ",0)).toEqual( + { start: 0, name: 'p', type: 'substituted', rawValue: 'blah', end: 8 } + ); + expect($tw.utils.parseAttribute("p=```blah``` ",0)).toEqual( + { start: 0, name: 'p', type: 'substituted', rawValue: 'blah', end: 12 } + ); + expect($tw.utils.parseAttribute("p=`Hello \"There\"`",0)).toEqual( + { start: 0, name: 'p', type: 'substituted', rawValue: 'Hello "There"', end: 17 } + ); }); it("should parse HTML tags", function() { diff --git a/editions/test/tiddlers/tests/test-prefixes-filter.js b/editions/test/tiddlers/tests/test-prefixes-filter.js index 62f329d66..a8d109d73 100644 --- a/editions/test/tiddlers/tests/test-prefixes-filter.js +++ b/editions/test/tiddlers/tests/test-prefixes-filter.js @@ -434,6 +434,15 @@ describe("'reduce' and 'intersection' filter prefix tests", function() { expect(wiki.filterTiddlers("[tag[shopping]] :map[get[title]addprefix[-]addprefixaddprefix[of]addprefix]").join(",")).toBe("0of4-Brownies,1of4-Chick Peas,2of4-Milk,3of4-Rice Pudding"); }); + it("should handle the :then prefix", function() { + expect(wiki.filterTiddlers("[[one]] :then[[two]]").join(",")).toBe("two"); + expect(wiki.filterTiddlers("[[one]] :then[tag[shopping]]").join(",")).toBe("Brownies,Chick Peas,Milk,Rice Pudding"); + expect(wiki.filterTiddlers("[[one]] [[two]] [[three]] :then[[four]]").join(",")).toBe("four"); + expect(wiki.filterTiddlers("[[one]] :then[tag[nonexistent]]").join(",")).toBe("one"); + expect(wiki.filterTiddlers(":then[[two]]").length).toBe(0); + expect(wiki.filterTiddlers("[[notatiddler]is[tiddler]] :then[[two]]").length).toBe(0); + }); + it("should handle macro parameters for filter run prefixes",function() { var widget = require("$:/core/modules/widgets/widget.js"); var rootWidget = new widget.widget({ type:"widget", children:[ {type:"widget", children:[]} ] }, diff --git a/editions/tw5.com/tiddlers/features/Deserializers.tid b/editions/tw5.com/tiddlers/features/Deserializers.tid new file mode 100644 index 000000000..1da4813df --- /dev/null +++ b/editions/tw5.com/tiddlers/features/Deserializers.tid @@ -0,0 +1,20 @@ +created: 20230627093650105 +modified: 20230627094356394 +tags: Features +title: Deserializers +type: text/vnd.tiddlywiki + +Deserializer [[modules|Modules]] parse text in various formats into their JSON representation as tiddlers. The deserializer modules available in a wiki can be seen using the [[deserializers operator|deserializers Operator]] and can be used with the [[deserialize Operator]]. + +The TiddlyWiki core provides the following deserializers: + +|!Deserializer |!Description | +|(DOM)|Extracts tiddlers from a DOM node, should not be used with the <<.op deserialize[]>> operator | +|application/javascript|Parses a JavaScript module as a tiddler extracting fields from the header comment| +|application/json|Parses [[JSON|JSON in TiddlyWiki]] into tiddlers| +|application/x-tiddler|Parses the [[.tid file format|TiddlerFiles]] as a tiddler| +|application/x-tiddler-html-div|Parses the [[
.tiddler file format|TiddlerFiles]] as a tiddler| +|application/x-tiddlers|Parses the [[MultiTiddlerFile format|MultiTiddlerFiles]] as tiddlers| +|text/css|Parses CSS as a tiddler extracting fields from the header comment| +|text/html|Parses an HTML file into tiddlers. Supports ~TiddlyWiki Classic HTML files, ~TiddlyWiki5 HTML files and ordinary HTML files| +|text/plain|Parses plain text as a tiddler| \ No newline at end of file diff --git a/editions/tw5.com/tiddlers/filters/Conditional Operators.tid b/editions/tw5.com/tiddlers/filters/Conditional Operators.tid index 7028e6dad..6d21e0864 100644 --- a/editions/tw5.com/tiddlers/filters/Conditional Operators.tid +++ b/editions/tw5.com/tiddlers/filters/Conditional Operators.tid @@ -1,12 +1,12 @@ created: 20190802113703788 -modified: 20190802132727925 +modified: 20230501175143648 tags: Filters title: Conditional Operators type: text/vnd.tiddlywiki -<<.from-version "5.1.20">>The conditional filter operators allow ''if-then-else'' logic to be expressed within filters. +<<.from-version "5.1.20">>The conditional filter operators allow for ''if-then-else'' logic to be expressed within filters. -The foundation is the convention that an empty list can be used to represent the boolean value ''false'' and a list with at one (or more) entries to represent ''true''. +The foundation is the convention that an empty list can be used to represent the Boolean value <<.value false>> and a list with at one (or more) entries to represent <<.value true>>. The conditional operators are: @@ -19,10 +19,12 @@ The conditional operators are: These operators can be combined. For example: -<<.inline-operator-example "[[New Tiddler]is[missing]then[I am missing]else[No I am not missing]]">> +<<.operator-example 1 "[[New Tiddler]is[missing]then[I am missing]else[No I am not missing]]">> -The [[else Operator]] can be used to apply a defaults for missing values. In this example, we take advantage of the fact that the [[get Operator]] returns an empty list if the field or tiddler does not exist: +The <<.olink else>> operator can be used to apply a defaults for missing values. In this example, we take advantage of the fact that the <<.olink get>> operator returns an empty list if the field or tiddler does not exist: -<<.inline-operator-example "[[HelloThere]get[custom-field]else[default-value]]">> +<<.operator-example 2 "[[HelloThere]get[custom-field]else[default-value]]">> -<> +! Filter Run Prefixes + +The [[:then|:then Filter Run Prefix]] and [[:else|:else Filter Run Prefix]] filter run prefixes serve a similar purpose as the conditional operators. Refer to their documentation for more information. \ No newline at end of file diff --git a/editions/tw5.com/tiddlers/filters/deserialize Operator.tid b/editions/tw5.com/tiddlers/filters/deserialize Operator.tid index 616e5ae19..7205d09c6 100644 --- a/editions/tw5.com/tiddlers/filters/deserialize Operator.tid +++ b/editions/tw5.com/tiddlers/filters/deserialize Operator.tid @@ -1,7 +1,7 @@ caption: deserialize created: 20230601195749377 from-version: 5.3.0 -modified: 20230602105513132 +modified: 20230627094109762 op-input: a selection of strings op-output: JSON representations of tiddlers extracted from input titles. op-parameter: the deserializer module to be used to extract tiddlers from the input @@ -10,17 +10,8 @@ tags: [[Filter Operators]] [[Special Operators]] title: deserialize Operator type: text/vnd.tiddlywiki -<<.tip "Deserializer modules parse text in various formats into their JSON representation as tiddlers. You can see the deserializers available in a wiki using the [[deserializers operator|deserializers Operator]].">> +{{Deserializers}} + -|!Deserializer |!Description | -|(DOM)|Extracts tiddlers from a DOM node, should not be used with the <<.op deserialize[]>> operator | -|application/javascript|Parses a JavaScript module as a tiddler extracting fields from the header comment| -|application/json|Parses [[JSON|JSON in TiddlyWiki]] into tiddlers| -|application/x-tiddler|Parses the [[.tid file format|TiddlerFiles]] as a tiddler| -|application/x-tiddler-html-div|Parses the [[
.tiddler file format|TiddlerFiles]] as a tiddler| -|application/x-tiddlers|Parses the [[MultiTiddlerFile format|MultiTiddlerFiles]] as tiddlers| -|text/css|Parses CSS as a tiddler extracting fields from the header comment| -|text/html|Parses an HTML file into tiddlers. Supports ~TiddlyWiki Classic HTML files, ~TiddlyWiki5 HTML files and ordinary HTML files| -|text/plain|Parses plain text as a tiddler| <<.operator-examples "deserialize">> \ No newline at end of file diff --git a/editions/tw5.com/tiddlers/filters/deserializers Operator.tid b/editions/tw5.com/tiddlers/filters/deserializers Operator.tid index 2501553e8..7691be970 100644 --- a/editions/tw5.com/tiddlers/filters/deserializers Operator.tid +++ b/editions/tw5.com/tiddlers/filters/deserializers Operator.tid @@ -1,14 +1,14 @@ caption: deserializers created: 20210506115203172 from-version: 5.2.0 -modified: 20210506130322593 +modified: 20230627094238610 op-input: ignored op-output: the title of each available deserializer op-parameter: none -tags: [[Filter Operators]] [[Special Operators]] [[Selection Constructors]] +tags: [[Filter Operators]] [[Special Operators]] [[Selection Constructors]] title: deserializers Operator type: text/vnd.tiddlywiki -<<.tip "You can specify a specific deserializer for a DropzoneWidget to use">> +<<.tip "You can specify a specific [[deserializer|Deserializers]] for a DropzoneWidget to use">> <<.operator-examples "deserializers">> diff --git a/editions/tw5.com/tiddlers/filters/examples/substitute Operator (Examples).tid b/editions/tw5.com/tiddlers/filters/examples/substitute Operator (Examples).tid new file mode 100644 index 000000000..ece8aecf6 --- /dev/null +++ b/editions/tw5.com/tiddlers/filters/examples/substitute Operator (Examples).tid @@ -0,0 +1,37 @@ +created: 20230614225302905 +modified: 20230614233448662 +tags: [[Operator Examples]] [[substitute Operator]] +title: substitute Operator (Examples) +type: text/vnd.tiddlywiki + +\define time() morning +\define field() modified +\procedure sentence() This tiddler was last $(field)$ on ${[{!!modified}format:date[DDth MMM YYYY]]}$ +\define name() Bugs Bunny +\define address() Rabbit Hole Hill + +!Substitute <<.op substitute[]>> operator parameters +<<.operator-example 1 "[[Hi, I'm $1$ and I live in $2$]substitute[Bugs Bunny],[Rabbit Hole Hill]]">> + +!Substitute variables +This example uses the following variables: + +* name: <$codeblock code=<>/> +* address: <$codeblock code=<
>/> + +<<.operator-example 2 "[[Hi, I'm $(name)$ and I live in $(address)$]substitute[]]">> + +!Substitute variables and operator parameters +This example uses the following variable: + +* time: <$codeblock code=<