On Monday, July 20, 2020 at 1:55:57 PM UTC-7, steve wrote:
>
> I am working on a macro to highlight target strings within the text field 
> of a tiddler.  
> The use case is to make it easier to for me see where the targetStrings 
> are (if any).   
>
 

> My question is how to highlight the targetString in the macro (ie. 
> treating 
> the macro as a string) as opposed to (apparently) executing the macro 
> and highlighting the targetString in the output.
>
>
There's nothing wrong with your filter and regexp usage.

To see the literal output text, I used the <$text> widget in the table, 
like this:
\define formatTid.highlightText(inputText targetString)
<$set name="outputText" filter="[[$inputText$]] 
 +[splitregexp[\b$targetString$\b]join[@@color:blue;$targetString$@@]]" 
select="0">

| ''outputText''|<$text text=<<outputText>>/>|
\end
<$macrocall $name="formatTid.highlightText" 
inputText={{highlightTest.sentence!!text}} targetString="goFish"/>

The result of the above (using your example input) is:
outputText \define @@color:blue;goFish@@() !!! This example has three 
instances of @@color:blue;goFish@@. \end <<@@color:blue;goFish@@>>

As you can see, your regexp filter DID find and replace all the 
targetString instances by wrapping them with "@@color:blue;...@@" as you 
intended.  Of course, that doesn't produce the output you want, which is to 
see the full input text *with the blue highlighting*.

The problem with using just <<outputText>> in the table stems from the way 
the TWCore parser processes and renders the "outputText" value.

1) anything from "\define" through "\end" is a macro definition, and the 
TWCore doesn't *render* macro definitions as output.

2) anything from "<<" through ">>" is a macro invocation, and if the macro 
isn't defined in the current context, then it produces no output.

Thus, only the normal wikitext content in your example is displayed as 
output and the macro definition and macro invocation are not shown.

Fortunately, I did find a way to get something closer to what you want.  
Try this:
\define formatTid.highlightText(inputText targetString)
<$set name="outputText" filter="[[$inputText$]] 
 +[splitregexp[\b$targetString$\b]join[@@color:blue;$targetString$@@]]" 
select="0">

| ''outputText''|<pre><<showOutput>></pre>|
\end

\define showOutput()
\rules only styleinline
$(outputText)$
\end

<$macrocall $name="formatTid.highlightText" inputText={{highlightTest.
sentence!!text}} targetString="goFish"/>

* The <pre>...</pre> in the table forces whitespace to be rendered as-is 
(the default rendering collapses all whitespace)
* The showOutput() macro uses the "\rules" pragma to disable all parsing 
except for "styleinline" (the "@@" syntax)

The result of the above (using your example input) is:
outputText 

\define goFish()

!!! This example has three instances of goFish.

\end
<<goFish>>


Which is, I think, very close to what you intended.

Tricky stuff, eh?

Let me know how it goes...

enjoy,
-e

-- 
You received this message because you are subscribed to the Google Groups 
"TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to tiddlywiki+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tiddlywiki/93917d0d-97f3-4182-b5dc-b6cbf810246co%40googlegroups.com.

Reply via email to