Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide examples for the wikify widget #8792

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions editions/tw5.com/tiddlers/TestCases_WikifyWidget_RenderHTML.tid
Original file line number Diff line number Diff line change
@@ -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=<<code>> />

<$macrocall $name="copy-to-clipboard" src=<<code>>/>

</$wikify>
+
title: code
text:

!! A nice list

* Item 1
* Item 2
* Item 3
Original file line number Diff line number Diff line change
@@ -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

<span style.color={{widget}} style.background={{target}}>
{{widget}} text on {{target}} is a good contrast
</span>
+
title: widget
text: <$transclude $variable="contrastcolour" target={{target}} fallbackTarget=<<fallbackTarget>> colourA={{colourA}} colourB={{colourB}} />
+
title: target
text: purple
+
title: colourA
text: white
+
title: colourB
text: black
+
title: ExpectedResult

<p><span style="color:white<$transclude $variable="contrastcolour" target={{target}} fallbackTarget=<<fallbackTarget>> colourA={{colourA}} colourB={{colourB}} />;background:purple;">
white text on purple is a good contrast
</span></p>
Original file line number Diff line number Diff line change
@@ -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}} >
<span style.color=<<wikified-color>> style.background={{target}}>
{{widget}} text on {{target}} is a good contrast
</span>
</$wikify>
+
title: widget

<$transclude $variable="contrastcolour"
target={{target}}
fallbackTarget=<<fallbackTarget>>
colourA={{colourA}}
colourB={{colourB}}
/>
+
title: target
text: purple
+
title: colourA
text: white
+
title: colourB
text: black
+
title: ExpectedResult

<p>
<span style="color:white;background:purple;">
white text on purple is a good contrast
</span>
</p>
Original file line number Diff line number Diff line change
@@ -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 "/></$list>
+
title: ExpectedResult
text: <p>Word count = 3</p>
Original file line number Diff line number Diff line change
@@ -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="[<lorem>split[ ]!is[blank]]"/></$wikify>
+
title: lorem
text: <$list filter="[range[1],[3]]"><$text text=" word "/></$list>
+
title: ExpectedResult
text: <p>Word count = 3</p>
20 changes: 18 additions & 2 deletions editions/tw5.com/tiddlers/widgets/WikifyWidget.tid
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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

<<testcase "TestCases/WikifyWidget/WidgetValue/Success">>
<<testcase "TestCases/WikifyWidget/WidgetValue/Fail">>

!! Accurate word count

<<testcase "TestCases/WikifyWidget/WordCount/Success">>
<<testcase "TestCases/WikifyWidget/WordCount/Fail">>

!! Exporting rendered html

<<testcase "TestCases/WikifyWidget/RenderHTML">>
Loading