Browser : Chrome
OS: Windows 11
TiddlyWiki version: 5.3.5
I tried to make macro that can copy the text with WikiText formatting or any HTML code into clipboard.
But the copied output should be plain text.
<!------------------ MACROS DEFINITION ----------------->
\define text-to-copy(sentence)
<!-- I want to `$sentence$` variable to be plain text when copy even the text has style formatting-->
<<copy-to-clipboard """$sentence$""" style="position;relative; float:right;">>
<div style="background-color: #f5f5f5; border: 1px solid #8D8D8D;">
$sentence$
</div>
\end
<!------------------------------------------------------------>
<!------------------ EXAMPLE ----------------->
<<text-to-copy """This is @@color:red;red@@ and ''bold''.""">>
<!------------------------------------------------------------>
My desired output when copied to clipboard is only plain text This is red and bold NOT includes the WikiText like This is @@color:red;red@@ and ''bold''.
Can anyone help me on this or any reference that I can try? Thanks!
Note: because we now need to pass the clip variable to the copy-to-clipboard macro, we have to use the <$macrocall $name="copy-to-clipboard" .../> widget syntax with named parameters instead of the macro shortcut syntax (e.g. <<copy-to-clipboard ...>>)
Also note that \define and <$macrocall $name=.../> syntax have been “deprecated” (but can still be used if you want). The newer equivalent syntax is to use \procedure and <$transclude $variable=.../>, like this:
Thanks, @EricShulman
Cool! Seems like what I wanted.
<!-- Procedure definition-->
\procedure text-to-copy(sentence)
<$wikify name="clip" output="text" text="""<<sentence>>""">
<$transclude $variable="copy-to-clipboard" src=<<clip>> style="position;relative; float:right;"/>
<div style="background-color: #f5f5f5; border: 1px solid #8D8D8D;">
<<sentence>>
</div>
\end
<!-- Procedure call-->
<<text-to-copy """
First Line : Hello world. ''Bold'' and @@color:red;red@@ <br>*<br>
Second line : Hello world. ''Bold'' and @@color:red;red@@ <br>*<br>*<br>
Third line: Hello world. ''Bold'' and @@color:red;red@@
"""
>>
However, it did not let me to copy text with multi-line because when I copied, even it has 2 or 3 break line, the copied content assumes it just one break line.
Somehow I found workaround for my problem! I used <pre> tag in HTML to preserve the line breaks when copying the multi-line formatted text. I put the tag when entering the text, not inside procedure.
<!-- Procedure definition-->
\procedure text-to-copy(sentence)
<$wikify name="clip" output="text" text="""<<sentence>>""">
<$transclude $variable="copy-to-clipboard" src=<<clip>> style="position;relative; float:right;"/>
<div style="background-color: #f5f5f5; border: 1px solid #8D8D8D;">
<<sentence>>
</div>
\end
<!-- Procedure call-->
<<text-to-copy """<pre>First Line : Hello world. ''Bold'' and @@color:red;red@@
*
Second line : Hello world. //Italic// and @@color:red;red@@
*
*
Third line: @@Hello world@@. __Underline__ and @@color:red;red@@
*
*
*
Last Line</pre>"""
>>
I suppose there might be a use-case where you don’t want to preserve newlines, but it seems to me that you could put the <pre>...</pre> tags inside the procedure, like this: