Hi ,
i am trying to make this effect where a
" very very very long title" is shortened and displayed as
" very very very lo…"
to save space.
which operator should i use ?
thank you
Hi ,
i am trying to make this effect where a
" very very very long title" is shortened and displayed as
" very very very lo…"
to save space.
which operator should i use ?
thank you
If you can address the problem using CSS…
@CodaCoder’s answer is the right one, it will probably be way more flexible. however i took it as a challenge, so here’s my macro:
\procedure truncate(length text)
<$let
filter="[<text>split[]prepend[⨷]move:$1$[⨷]allbefore[⨷]join[]]"
sub={{{[<filter>substitute<length>]}}}>
<$text text={{{[subfilter<sub>addsuffix[...]]}}}/>
</$let>
\end
<<truncate 13 "here is a long text that will be truncated">>
gives
here is a lon...
the primary operator i used was allbefore[]
, but because you can’t use a variable in the suffix of a filter operator directly i had to break it out and substitute[]
it in as text before running it with subfilter[]
.
i also used a strange unicode character i found ⨷
as a marker because if the marker is naturally in the tiddler title it will break.
Thanks. But pure wikitext solutions are always welcome
This may be a useful feature in can add to my alt-title solution however the biggest annoyance is catering for the spaces available given the number of buttons and zoom level.
Thanks all,
i used the wikitext solution:)
sorry to revive this old thread, but i realized this wikitext will put the ellipsis at the end even if the string is shorter than the truncation limit (e.g <<truncate 30 "short">>
→ short...
) which is not desirable. i dug this up because i needed to use it and found it didn’t work how i intended
here’s a corrected version that checks for that:
\procedure truncate(length text)
<$let
filter="[<text>split[]prepend[⨷]move:$1$[⨷]allbefore[⨷]join[]]"
sub={{{[<filter>substitute<length>]}}}>
<$text text={{{[<text>length[]compare:number:gt<length>] :then[subfilter<sub>addsuffix[...]] :else[<text>]}}}/>
</$let>
\end
Would this achieve the same goal?
\procedure truncate(length text)
<$text text={{{[<text>length[]compare:number:gt<length>] :then[<text>split[]first<length>butlast[3]join[]addsuffix[...]] :else[<text>]}}}/>
\end