Removing prefix https and http

69 views
Skip to first unread message

W Yan

unread,
Nov 23, 2020, 10:50:22 PM11/23/20
to tiddl...@googlegroups.com
Hi, I'm trying to remove https:// and http:// from url fields. I've tried <$text text={{{ [{!!url}removeprefix[https://]] }}} /> and it works, but I don't know how to make it work depending on whether url has https or http. Seems like just adding another removeprefix[http://] completely removes the url.
 
Also need help with using <img src="<$transclude field=image/>" > properly; I know why it doesn't work but I have no idea how to make it work. I would appreciate any help.
 
W Yan

Mohammad

unread,
Nov 23, 2020, 11:58:09 PM11/23/20
to TiddlyWiki
This is a simple solution

\define rmv(url) {{{ [[$url$]removeprefix[https://]] ~[[$url$]removeprefix[http://]] }}}

Examples:

<<rmv """https://google.com""">>
<<rmv """http://google.com""">>

W Yan

unread,
Nov 24, 2020, 1:01:20 AM11/24/20
to tiddl...@googlegroups.com
Mohammad, thank you for the solution! Just tried it and it worked great. Now I'm having a go with <img src> thing, and I think I am pretty close... I'm at
 
\define imgsrc(url)
<img src="$(url)$">
\end
<$set name=url value={{!!url}}>
<<imgsrc url>>
</$set>
 
right now, but can't get my head around using <$transclude field=image/> instead of {{!!url}}. The url field contains a syntax that renders image urls, and just transcluding with {{!!url}} doesn't seem to render the syntax at all. It only works when I use transclusion widget, but you can't include widgets inside attributes, so I'm stuck.

soren.b...@gmail.com

unread,
Nov 24, 2020, 8:21:39 AM11/24/20
to TiddlyWiki
Can you elaborate on "The url field contains a syntax that renders image urls"?

<$transclude field=url> should be the same thing as {{!!url}}, so I don't think that's actually your problem. If you mean that it contains wikitext references like transclusions, you need to wikify the contents of the URL field in order to get that URL. Probably what's happening is that you were able to use {{!!url}} as a parameter to the img tag, but were only able to use the transclude widget at the top level of your wikitext (where anything that comes out of a transclusion is automatically wikified), so it looks like the transclude widget is making the difference.

Wikifying the contents would look something like:

<$wikify name=wikifiedLink text={{!!url}}>
  <img src=<<wikifiedLink>>>
</$wikify>



W Yan

unread,
Nov 24, 2020, 12:29:16 PM11/24/20
to tiddl...@googlegroups.com
Thank you, that did the trick! I basically had similar widget <$text text=.../> I wrote above to combine several texts to get the url, and as you suggested wikifying was the solution I've been looking for.
Reply all
Reply to author
Forward
0 new messages