diff --git a/editions/tw5.com/tiddlers/TestCases_WikifyWidget_RenderHTML.tid b/editions/tw5.com/tiddlers/TestCases_WikifyWidget_RenderHTML.tid new file mode 100644 index 00000000000..7a0ac231f8a --- /dev/null +++ b/editions/tw5.com/tiddlers/TestCases_WikifyWidget_RenderHTML.tid @@ -0,0 +1,28 @@ +created: 20241201235747500 +description: Exporting rendered html +tags: $:/tags/wiki-test-spec +title: TestCases/WikifyWidget/RenderHTML +type: text/vnd.tiddlywiki-multiple + +title: Narrative + +You can use <<.wid wikify>> to copy your wikitext as a formated HTML. ++ +title: Output + +<$wikify name="code" text={{code}} output="html"> + +<$codeblock code=<> /> + +<$macrocall $name="copy-to-clipboard" src=<>/> + + ++ +title: code +text: + +!! A nice list + +* Item 1 +* Item 2 +* Item 3 \ No newline at end of file diff --git a/editions/tw5.com/tiddlers/TestCases_WikifyWidget_WidgetValue_Fail.tid b/editions/tw5.com/tiddlers/TestCases_WikifyWidget_WidgetValue_Fail.tid new file mode 100644 index 00000000000..c07005786d8 --- /dev/null +++ b/editions/tw5.com/tiddlers/TestCases_WikifyWidget_WidgetValue_Fail.tid @@ -0,0 +1,33 @@ +created: 20241202000005087 +description: Using a widget as a value +tags: $:/tags/wiki-test-spec-failing +title: TestCases/WikifyWidget/WidgetValue/Fail +type: text/vnd.tiddlywiki-multiple + +title: Narrative + +If you try to directly use a widget as a value, you will instead get the raw wikitext of the widget and not the rendered value. ++ +title: Output + + + {{widget}} text on {{target}} is a good contrast + ++ +title: widget +text: <$transclude $variable="contrastcolour" target={{target}} fallbackTarget=<> colourA={{colourA}} colourB={{colourB}} /> ++ +title: target +text: purple ++ +title: colourA +text: white ++ +title: colourB +text: black ++ +title: ExpectedResult + +

> colourA={{colourA}} colourB={{colourB}} />;background:purple;"> + white text on purple is a good contrast +

\ No newline at end of file diff --git a/editions/tw5.com/tiddlers/TestCases_WikifyWidget_WidgetValue_Success.tid b/editions/tw5.com/tiddlers/TestCases_WikifyWidget_WidgetValue_Success.tid new file mode 100644 index 00000000000..ba147f2b7e3 --- /dev/null +++ b/editions/tw5.com/tiddlers/TestCases_WikifyWidget_WidgetValue_Success.tid @@ -0,0 +1,43 @@ +created: 20241202003148804 +description: Using a widget as a value +tags: $:/tags/wiki-test-spec +title: TestCases/WikifyWidget/WidgetValue/Success +type: text/vnd.tiddlywiki-multiple + +title: Narrative + +If you use <<.wid wikify>>, you can get the rendered output and use it as a value. ++ +title: Output + +<$wikify name="wikified-color" text={{widget}} > + > style.background={{target}}> + {{widget}} text on {{target}} is a good contrast + + ++ +title: widget + +<$transclude $variable="contrastcolour" + target={{target}} + fallbackTarget=<> + colourA={{colourA}} + colourB={{colourB}} +/> ++ +title: target +text: purple ++ +title: colourA +text: white ++ +title: colourB +text: black ++ +title: ExpectedResult + +

+ + white text on purple is a good contrast + +

\ No newline at end of file diff --git a/editions/tw5.com/tiddlers/TestCases_WikifyWidget_WordCount_Fail.tid b/editions/tw5.com/tiddlers/TestCases_WikifyWidget_WordCount_Fail.tid new file mode 100644 index 00000000000..570f85fffa0 --- /dev/null +++ b/editions/tw5.com/tiddlers/TestCases_WikifyWidget_WordCount_Fail.tid @@ -0,0 +1,19 @@ +created: 20241201235746062 +description: Accurate word count +tags: $:/tags/wiki-test-spec-failing +title: TestCases/WikifyWidget/WordCount/Fail +type: text/vnd.tiddlywiki-multiple + +title: Narrative + +If a tiddler transclude some content, or use widgets to generate content, filters that try to calculate the word count won’t be accurate: they will instead count the raw text words. ++ +title: Output + +Word count = <$count filter="[{lorem}split[ ]!is[blank]]"/> ++ +title: lorem +text: <$list filter="[range[1],[3]]"><$text text=" word "/> ++ +title: ExpectedResult +text:

Word count = 3

\ No newline at end of file diff --git a/editions/tw5.com/tiddlers/TestCases_WikifyWidget_WordCount_Success.tid b/editions/tw5.com/tiddlers/TestCases_WikifyWidget_WordCount_Success.tid new file mode 100644 index 00000000000..be214b97a6a --- /dev/null +++ b/editions/tw5.com/tiddlers/TestCases_WikifyWidget_WordCount_Success.tid @@ -0,0 +1,19 @@ +created: 20241202011409888 +description: Accurate word count +tags: $:/tags/wiki-test-spec +title: TestCases/WikifyWidget/WordCount/Success +type: text/vnd.tiddlywiki-multiple + +title: Narrative + +If you use wikify, you can calculate an accurate word count. ++ +title: Output + +<$wikify name="lorem" text={{lorem}} output="text">Word count = <$count filter="[split[ ]!is[blank]]"/> ++ +title: lorem +text: <$list filter="[range[1],[3]]"><$text text=" word "/> ++ +title: ExpectedResult +text:

Word count = 3

\ No newline at end of file diff --git a/editions/tw5.com/tiddlers/widgets/WikifyWidget.tid b/editions/tw5.com/tiddlers/widgets/WikifyWidget.tid index 87b76a99d74..e8af7ef8297 100644 --- a/editions/tw5.com/tiddlers/widgets/WikifyWidget.tid +++ b/editions/tw5.com/tiddlers/widgets/WikifyWidget.tid @@ -1,13 +1,13 @@ caption: wikify created: 20160321144949700 -modified: 20220122191540121 +modified: 20241202014354100 tags: Widgets title: WikifyWidget type: text/vnd.tiddlywiki ! Introduction -The wikify widget parses and renders a string of text and assigns the result to a specified [[variable|Variables]]. The new value of the variable is available to the content within the wikify widget. +The <<.wid wikify>> widget parses and renders a string of text and assigns the result to a specified [[variable|Variables]]. The new value of the variable is available to the content within the wikify widget. ! Content and Attributes @@ -28,3 +28,19 @@ The available output types are: |html |Return the rendered HTML of the output | |parsetree |Return a formatted JSON representation of the parse tree | |widgettree |Return a formatted JSON representation of the widget tree | + +! Examples + +!! Using a widget as a value + +<> +<> + +!! Accurate word count + +<> +<> + +!! Exporting rendered html + +<>