Plugin request: Tiddler highlight summary

Hi, My idea is, that I have in tiddler text some important parts of text marked as MARK html especially using HLP and HLS macro of Shiraz. It may be nice that at bottom of the tiddler displaying summary as bullet list of marks contents. Is it possible?

Yeah.

  1. Use regex filter to extract the marked text
  2. Display it by adding a $:/tags/ViewTemplate tiddler

The only issue is that all the “marks” should have a consistent pattern.

I have created an example. Please check out

https://random-2022-12-22-1671651440.tiddlyhost.com/

Possible improvements

  1. Make regex more robust
  2. Prettier UI for the “All highlights” section
  3. Do not show “All highlights” if there are none

Regex in TW

I used @Mohammad’s example.

If you plan to take on this task then do checkout this regex in TW guide.

https://tw-regexp.tiddlyspot.com/


<h1>All highlights</h1>


<$list filter="""[all[current]get[text]splitregexp[\n]join[ ]splitregexp[<<hl ".*?]butfirst[1]]""" variable=item>
<$list filter="""[<item>splitregexp[" ]butlast[1]]""" variable=item2>
<$text text=<<item2>>/><br/>
</$list>
</$list>

2 Likes

@talha131 Instead of regex you could use split :

https://demos.tiddlyhost.com/#List%20marked%20text

Welcome to <mark>TiddlyWiki</mark>, a unique non-linear notebook for capturing, organising and sharing complex information

Use it to <mark>keep your to-do list</mark>, to plan an essay or novel, or to organise your wedding. Record every thought that crosses your brain, or build a flexible and responsive website.

Unlike conventional online services, TiddlyWiki lets you choose where to keep your data, guaranteeing that in the decades to come you will still be able to use the notes you take today.

---

<ul>
<$list filter="[{!!text}split[<mark]split[</mark>]prefix[>]trim[>]]">
<li>{{!!title}}</li>
</$list>
</ul>

EDIT: You can even use custom attributes and CSS to make things more interesting :

Welcome to <mark href="https://tiddlywiki.com" title="Tiddlywiki is a non-linear notebook" other="test">TiddlyWiki</mark>, a unique non-linear notebook for capturing, organising and sharing complex information

Use it to <mark title="A todo list is a list of task">keep your to-do list</mark>, to plan an essay or novel, or to organise your wedding. Record every thought that crosses your brain, or build a flexible and responsive website.

Unlike conventional online services, TiddlyWiki lets you choose where to keep your data, guaranteeing that in the decades to come you will still be able to use the notes you take today.

---

<ol>
<$list filter="[{!!text}split[<mark]split[</mark>]]
:filter[<index>remainder[2]match[1]]
+[search[>]]">
<$let 
title={{{  [{!!title}split[="]split[" ]trim[ ]after[title]split["]first[]] }}}
href={{{  [{!!title}split[="]split[" ]trim[ ]after[href]split["]first[]] }}}
text={{{ [<title>minlength[3]]:else[{!!title}split[>]last[]] }}} 
>
<li>
<$list filter=<<href>> emptyMessage=<<text>>>
<a href=<<href>> > <<text>> </a></$list>
</li>
</$let>
</$list>
</ol>

<style>
.tc-tiddler-body{
counter-reset: mark-count;
}

.tc-tiddler-body mark{
font-weight:bold;
background:unset;
}

.tc-tiddler-body mark:after{
  counter-increment: mark-count;
  content: " [" counter(mark-count) "]";
}

</style>
4 Likes

@telumire regex or split I have wanted this for a long time, and gone down many rabbit holes, now embarrassed I see it was easier than expected. Thanks for sharing.

  • The key learning for me is the same filter splits the beginning and end thus works on all occurrence’s in the tiddler.
  • also your adding the prefix so you then trim the prefix, which I have not completely understood (at time of writing)

Complementary features would be to

  • Provide the tiddlername and “tag” eg mark, to a macro
  • extract the values between <mark and >
    • An advanced feature would be to set variables with the parameters key=value pairs.

@TW_Tones Check my edit, funny enough I extended my example with custom attribute handling before seeing your comment :grin:

I THINK using the new genesis widget would be much better than my hacky wikitext to handle the variables, but I didnt took the time to learn it yet.

Another idea would be to use text substitution to put the key value pair in a let widget, that way it would be more robust than using filters.

EDIT: it works !

\define list-item(wikitext) <$let $(variables)$>$wikitext$</$let>

<$tiddler tiddler="List marked text">

<$list filter="[{!!text}split[<mark]split[</mark>]]
:filter[<index>remainder[2]match[1]]
+[search[>]]">

<$let text={{{ [{!!title}split[>]last[]] }}} variables={{{ [{!!title}split[>]first[]] }}}>


<<list-item """<a href=<<href>>> <<text>> </a> - <<title>>""">>

</$let>

</$list>

With this you can easily use turn any attribute you use on the <mark> into a variable.

3 Likes

You @telumire and the oroginal @michalradacz may be interested in my editor toolbar wrapper which can be used to apply the <mark>selection</mark> or any html even widget tag.

EditorToolbar-wrapper.json (5.4 KB)

But now with your solution including parsing the parametrized tags I will need to build a new tool that accommodates providing the parameters, or selecting from a list of premade wrappers and parameter sets, just to make it even easier.

but

  • I think this excludes nested tags.
1 Like

This solution is very interesting. It can be used for partial transclusion and also extract part of text inside a delimiter like <description>....</description>

2 Likes

Yes, this has being a long held interest of mine, given html allows arbitrary tag names a user can arrange their content into semantic units that can be styled differently but with @telumire’s help can also be easily extracted for special treatment.

My recent details discussion also helps here by allowing you to toggle such sections as if it were a details tag, either after the toggle or later in the text.

  • eg: Display’s answers to questions <answer1></answer1> <answers></answers>
  • Display multiple extra details <verbose><verbose>

A point being that content held hidden in a tiddler can also be “collected/collated” and displayed conditionally using the method implied by @telumire’s work in the viewTemplate or elsewhere.

But, this dont works if there are attributes in macros, yes, it works for classical MARK element, but not for HLP macro with additional parameter - for example highlight color. But this method may solve my another problem, listing of inserts in revision of tiddler text when INS and DEL marks presents.