Wkify Widget and Macro Variable: Formatting is removed

154 views
Skip to first unread message

Mohammad

unread,
Feb 27, 2019, 5:25:04 AM2/27/19
to TiddlyWiki
Consider the below example in which a macro output contains some wikitext has been fed to a wikify widget!


\define mc() This is a `code` and __underline__.



<$wikify name="result"  text="""<<mc>>""">

<<result>>

</$wikify>

Result is:

This is a code and underline.

While I expect an output like this:

This is a code and underline.


What is the problem? Note to the code and underlined text!

--Mohammae

Note: The use case is to store the result and send it to another widget (another scope)


S. S.

unread,
Feb 27, 2019, 6:33:09 AM2/27/19
to TiddlyWiki


The $wikify widget remains an enigma.
I believe the default output method is: output="text"
Documentation for text : Return the plain text of the rendered output (ie HTML tags are omitted)

Perhaps try: output="html"
Documentation for html : Return the rendered HTML of the output

\define mc() This is a `code` and __underline__.
<$wikify name="result"  text="""<<mc>>""" output=html>
<<result>>
</$wikify>

Result:  This is a code and underline.

Mohammad

unread,
Feb 27, 2019, 6:48:02 AM2/27/19
to TiddlyWiki
Hi S.S,
 Thanks for your reply!

Consider this

\define mc() This is a `code` and __underline__.
<$wikify name="result"  text="""<<mc>>""" output=html>
<<result>>


<$button>do
<$action-setfield $tiddler="hodii" $field="text" $value=<<result>> />
</
$button>
</$wikify>

This makes to write html tags in hodii tiddler! I wish to keep the wikitext if possible!

--Mohammad

S. S.

unread,
Feb 27, 2019, 7:20:46 AM2/27/19
to TiddlyWiki

Perhaps using the $wikify widget is not the right method then?
The other widgets for storing info into a variable (that I am aware of) are:
$set $vars $list with $set probably being the one you want to look at?
It's hard to make guesses as looking at the work you are doing, many of your end-use cases are quite complicated!

S. S.

unread,
Feb 27, 2019, 7:25:31 AM2/27/19
to TiddlyWiki
For example, why not just directly do:

<$action-setfield $tiddler="hodii" $field="text" $value=<<mc>> />

But I imagine you also need to be doing other things, so it's hard to guess.

BurningTreeC

unread,
Feb 27, 2019, 7:41:16 AM2/27/19
to TiddlyWiki
Hi Mohammad, in cases like this, the wikiparser does its magic first ... 

do you remember the example I gave you, where I wikified the text field of another tiddler, but viewing it with <$view tiddler="bla" mode="block" format="text"/> 

<$wikify name="something" text="""<$view tiddler="bla" mode="block" format="text"/>""">

<<something>>

</$wikify>

the view widget here assures that the plain text comes in ...

in your example here you have no such "helper"

...

if you change your mc macro to

\define mc()
\rules only
This is a `code` and __underline__.
\end

... you prevent the parser from kicking in in this macro block and it works

Mohammad

unread,
Feb 27, 2019, 7:42:19 AM2/27/19
to TiddlyWiki
Hi S.S,

Thanks for your help. I try to keep things simple, but as you said some cases there is no simple solution!
By the way, the use case here, the mc macro has some processing itself. I say this as nested processing!
I mean macro itself may call widgets or other macros. So in the below example, I cannot directly set the macro to $value!

I really appreciate your time and idea!

Cheers
Mohammad

Mohammad

unread,
Feb 27, 2019, 7:45:51 AM2/27/19
to TiddlyWiki
Hi BTC,

 You did the magic!

Thank you! It works.

Cheers
Mohammad

Mohammad

unread,
Feb 27, 2019, 7:50:54 AM2/27/19
to tiddl...@googlegroups.com
BTC,

I am still struggling with search-n-replace with no success! (also split[]joing[] failed)
I even tried to use  JavaScript replace macro (while I really want to stick to TW script) it simply receives the tiddler text field
searchValue and replcaeValue, but amazingly it removes some of formatting! 

So, these questions raised from trial and error with TW scripts to see how can I figure out this, using Tiddlywiki widgets, filters, operators...

Any light you can shed to this case is highly appreciated!

--Mohammad


On Wednesday, February 27, 2019 at 4:11:16 PM UTC+3:30, BurningTreeC wrote:

Mohammad

unread,
Feb 27, 2019, 8:07:49 AM2/27/19
to TiddlyWiki
Added to TW-Scripts.


On Wednesday, February 27, 2019 at 4:11:16 PM UTC+3:30, BurningTreeC wrote:

BurningTreeC

unread,
Feb 27, 2019, 8:10:44 AM2/27/19
to TiddlyWiki
BTC,

I am still struggling with search-n-replace with no success! (also split[]joing[] failed)
I even tried to use  JavaScript replace macro (while I really want to stick to TW script) it simply receives the tiddler text field
searchValue and replcaeValue, but amazingly it removes some of formatting! 

So, these questions raised from trial and error with TW scripts to see how can I figure out this, using Tiddlywiki widgets, filters, operators...

Any light you can shed to this case is highly appreciated!

What's the problem? The snr macro already had search and replace working with the use of the example I gave you in the other thread

What do you want to use the split op for?

I need a real code example

Mohammad

unread,
Feb 27, 2019, 8:22:45 AM2/27/19
to TiddlyWiki
The problem is writing back to the tiddler, where it loses some formatting!
Also, it cannot distinguish the whole words like change "is" to "was" in

This is test!

--Mohammad

BurningTreeC

unread,
Feb 27, 2019, 8:31:02 AM2/27/19
to TiddlyWiki
The problem is writing back to the tiddler, where it loses some formatting!
Also, it cannot distinguish the whole words like change "is" to "was" in

I believe you just need to get the first part right, instead of making it more complex through the use of a split operator

How does your macro look like?

Mohammad

unread,
Feb 27, 2019, 8:36:21 AM2/27/19
to TiddlyWiki
BTC,
 I have uploaded the latest change with your comment applied to 


Please have a look! I also sent you already the credential to be able to revise it!

I have two macros with almost the same things

  1. macro/Search-Replace-new to make the search and replace using snr [I removed split as you recommended)
  2. macro/Search-Replace-Apply-new to write the result in a temporarily tiddler: hodiii ( I will change this later to write back to the tiddler)

Please have a look.

--Mohammad

Mohammad

unread,
Feb 27, 2019, 9:15:47 AM2/27/19
to tiddl...@googlegroups.com
Hi again BTC,

\define snr(source:"", searchValue:"", replaceValue:"")

\whitespace trim
<$vars
 src  
=<<__source__>>
 sval
=<<__searchValue__>>
 rval
=<<__replaceValue__>>
>
<$list filter="[<src>search<sval>]" emptyMessage="""<$text text=<<src>> />"""  >
<$list variable="p1" filter="[<src>splitbefore<sval>]">
<$list variable="p2" filter="[<src>removeprefix<p1>]">
<$list variable="p3" filter="[<p1>removesuffix<sval>addsuffix<rval>]" emptyMessage="""<$text text=<<src>>/>""">
<$text text=<<p3>>/>
<$macrocall $name="snr"

source=<<p2>>
searchValue=<<sval>>
replaceValue=<<rval>>
/
>
</$list>
</
$list>
</$list>
</
$list>
</$vars>
\end

The above is the final snr macro! As you see the splitbefore actually get the source and find the character, word, pharse. It seems case-sensitive, so for case-insensitive search
I dont know how can I revise the code to distinguish this!

Temporarily demo is at: http://kookma.tiddlyspot.com/

--Mohammad

BurningTreeC

unread,
Feb 27, 2019, 9:42:51 AM2/27/19
to TiddlyWiki
Mohammad, I had a look at it and changed and added some things,

have a look at the attached file, try the replace-text-ui macro, simply

<<replace-text-ui>>


if it works well, have a look how everything is done.
I've called the snr macro snr123. I'm not fully sure if all cases are covered where an emptyMessage needs to contain the remaining text, but til now it worked fine. needs a lot of testing though!

BurningTreeC

unread,
Feb 27, 2019, 9:43:21 AM2/27/19
to TiddlyWiki
Here's the file
replace-text-macros.json

Mohammad

unread,
Feb 27, 2019, 9:56:18 AM2/27/19
to TiddlyWiki
Hi BTC,
 Lets do some experiments with it and I return with the result.

--Mohammad

Mohammad

unread,
Feb 27, 2019, 10:05:47 AM2/27/19
to TiddlyWiki
BTC, 
 One more question, is it possible to add
  • case-INsensitive search-n-replace
  • Whole words search-n-replace
--Mohammad

BurningTreeC

unread,
Feb 27, 2019, 10:10:01 AM2/27/19
to TiddlyWiki
BTC, 
 One more question, is it possible to add
  • case-INsensitive search-n-replace
  • Whole words search-n-replace

yes that's possible

Mohammad

unread,
Feb 27, 2019, 10:20:40 AM2/27/19
to tiddl...@googlegroups.com
I am testing it and seems to work on all fields
  • On title change it creates new Tiddler, seems okay!
  • All fields seems supported
  • I was not able to search-n-replace whole words except manually add spaces around words manually! but I had to do this also for replaceText
  • I was not able to search-n-replace in case-insensitive mode!
Please advise!

--Mohammad
Reply all
Reply to author
Forward
0 new messages