Including newlines in a URL-encoding macro definition

89 views
Skip to first unread message

Soren Bjornstad

unread,
May 27, 2020, 5:52:44 PM5/27/20
to TiddlyWiki
I'm trying to implement a mailto: based mail-merge in TiddlyWiki and am 95% of the way there borrowing the code provided in this thread: https://groups.google.com/forum/#!searchin/tiddlywiki/tiddlywiki$20mail$20merge|sort:relevance/tiddlywiki/wNpULbptm4w/h3He4gbGAwAJ

However, the tiddlerencoded macro there seems to omit all paragraph breaks from the tiddler containing the email message when performing URL encoding (it doesn't insert %0A, or anything else, to represent a newline in the URL-encoded string where they are in the tiddler). It's kind of hard to write a non-trivial email without using any paragraph breaks, so this is a big problem! Is there any way I can make it keep them? I don't mind editing the tiddler containing the message, but I can't find any markup that will generate a paragraph break. If I write <br> at the end of a paragraph, it puts in one newline, but I need two for a proper paragraph break, and if I put more than one <br>, TiddlyWiki renders it as an extra newline, but the URL-encoding version only includes a single %0A.

I did modify the macro a little bit, so as to allow field references within the email tiddler (basically, I just added the || before $template$). The original macro didn't include newlines either, so this doesn't seem to be the fault of my modification. Here's what I have currently:
\define tiddlerencoded(template)
<$wikify name="mytext" text="{{||$template$}}">
 
<$list filter="[<mytext>encodeuri[]]" variable="mywikifiedtext">
   
<$text text=<<mywikifiedtext>>/>
  </
$list>
</$wikify>
\end

Example invocation: <<tiddlerencoded EmailTemplateTest>> -- where EmailTemplateTest is any tiddler containing newlines.

I tried changing the type of EmailTemplateTest to text/plain, and that made the paragraph breaks show up properly, but then the TextReferences in it don't get replaced, which I need to be able to do.

TonyM

unread,
May 28, 2020, 12:06:28 AM5/28/20
to TiddlyWiki
Soren,

Did you try using the <p> tags themself?

Most html is past through.

I feel your pain, I was using and modifying previous mailto implementation and something was so fragile I have up after hours of frustration each time.

Regards
Tony

Soren Bjornstad

unread,
May 28, 2020, 8:45:01 AM5/28/20
to TiddlyWiki
Thanks, this worked! ...But only when I also put a newline immediately inside the <p> and </p> tags. Go figure.

TonyM

unread,
May 30, 2020, 6:33:32 AM5/30/20
to TiddlyWiki
Siren

If you install the inside tiddly wiki plugin you get additional preview modes in edit. One shows the resulting html. Perhaps this would help you see but this?

do share if you solve it. If not provide a json file we can place on tiddlywiki.com or in an emplt.html so we can help solve this.
Regards
Tony

Reply all
Reply to author
Forward
0 new messages