Experiment: A WikiText Solution for Link Preview

Tobias Beer Preview plugin lets preview a link to tiddler before opening it. It is a very useful tool; however, it is in JS and hard to customize. Here is an experiment to reproduce it in WikiText.

This is an experimental procedure (the CSS part will be moved to its own tiddler later).

\procedure link-preview(tiddler, id:0)
<style>
.kk-popup{
	padding:25px;
	max-height:400px;
	max-width:40vw;
	overflow-y:scroll;
}
</style>
<$let stateTid={{{ [<qualify $:/state/link-preview>addsuffix<id>] }}} >
<$button class="tc-btn-invisible tc-tiddlylink" popup=<<stateTid>> >
	<$text text=<<tiddler>> />
</$button>
<$reveal type="popup" state=<<stateTid>> >
	<div class="tc-drop-down kk-popup">
        <$link to=<<tiddler>> />
		<$transclude $tiddler=<<tiddler>> $mode=block/>
	</div>
</$reveal>
</$let>
\end link-preview

and here is an example on https://tiddlywiki.com

Hello, this is a test for <<link-preview "A Gentle Guide to TiddlyWiki">> and it works as expected.

Another example <<link-preview "Examples" 1>>

and the is the screenshot:
msedge_img_320_20241017

To give a try download link-preview.json (931 Bytes) and import to https://tiddlywiki.com and change the example as you like.

Questions:

  1. The id is used to create unique state tiddler, as qualify will create duplicate state if used several times in the same tiddler. How avoid this id and how to create unique state automatically? Or you may suggest better solution?

  2. How improve the css to have nice looking preview windows on small and large screen?

  3. How to use custom widget to overwrite the link widget and its shortcut [[..]] to add preview to links?

3 Likes

Here is a custom link widget which adds a pop up button also. This was done using an example given by @TW_Tones in that thread. Since this custom widget add an extra button, it may not be ideal.