The best practice for newline char in Tiddlywiki filter

97 views
Skip to first unread message

Mohammad Rahmani

unread,
Apr 29, 2021, 6:26:23 AM4/29/21
to tiddl...@googlegroups.com
It is known that the newline character is different for different OS (see Wikipedia). I am not sure if this is also true for the browsers or not!

Having that said, what is the best practice to treat a newline character in a Tiddlywiki filter to work everywhere!

Case i

<$list filter="[<source>splitregexp[\n]]" ...

Case ii
<$vars newline="
" >
<$list filter="[<source>splitregexp<newline>]" ...



Best wishes
Mohammad

PMario

unread,
Apr 29, 2021, 7:48:01 AM4/29/21
to TiddlyWiki
On Thursday, April 29, 2021 at 12:26:23 PM UTC+2 Mohammad wrote:
It is known that the newline character is different for different OS (see Wikipedia). I am not sure if this is also true for the browsers or not!

1) If you save a multiline tiddler in TW to the internal store `\n` will be used.
2) If you copy paste content from a file to TW it will use \n

3) If you import eg: test.txt from windows there will be "\r\n" in the tiddler.
The next time you edit the tiddler and save there will be  "\n" only.

 
Having that said, what is the best practice to treat a newline character in a Tiddlywiki filter to work everywhere!

Case i

<$list filter="[<source>splitregexp[\n]]" ...

So for case 3 it will look like, if it works, but it will keep the \r in memory.
If you want to remove it use:

<$list filter="[<source>splitregexp[\r?\n]]" ... this will always work for all OSes.

\r? .. means check for \r  optional ... only if it exists

 
Case ii
<$vars newline="
" >
<$list filter="[<source>splitregexp<newline>]" ...

hmm. This won't help since internally we only use \n

hope that helps
mario

PMario

unread,
Apr 29, 2021, 7:50:03 AM4/29/21
to TiddlyWiki
Hi,
Did you hit a problem, or is it just about curiosity?

We may be able to filter / sanitize imported tiddlers.
-mario

Jean-Pierre Rivière

unread,
Apr 29, 2021, 8:08:37 AM4/29/21
to TiddlyWiki
just to be pedantic, but in old Mac'OS the end of line was only \r. so your code would not work there

$list filter="[<source>splitregexp[(\r?\n|\r)]"

will do that (not tested yet). we obviously cannot use [\r?\n?]

Mohammad Rahmani

unread,
Apr 29, 2021, 9:16:33 AM4/29/21
to tiddl...@googlegroups.com, PMario
Thank you all for your reply!

I actually want to use the filter in real cases! Text is created in Tiddlywiki itself or important from the net. For example Fortran code downloaded from the net and imported into the wiki!
Most of these I think were created in the Unix system! So I like to make sure the filter works in all cases.

@Jean-Pierre
Thank for the suggestion! I will test it! I do not have a Mac computer but I think I should download text files created in Mac or use Notepad++ to use such newline chars.



Best wishes
Mohammad


--
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+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/2ea136f8-0151-48dc-bf9a-f4a75b7865d4n%40googlegroups.com.

Jean-Pierre Rivière

unread,
Apr 29, 2021, 10:26:33 AM4/29/21
to TiddlyWiki
Mohammad: I am speaking of really very old MacOS from circa 1990.

Mac from BSD era on are decent OS with \n end-of-lines as all unixes.

Mohammad Rahmani

unread,
Apr 29, 2021, 10:56:37 AM4/29/21
to tiddl...@googlegroups.com
On Thu, Apr 29, 2021 at 6:56 PM Jean-Pierre Rivière <jn.pierr...@gmail.com> wrote:
Mohammad: I am speaking of really very old MacOS from circa 1990.

Mac from BSD era on are decent OS with \n end-of-lines as all unixes.

Thank you Jean-Pierre!
I will test, the majority of old sources I use are Unix files!

 

Mohammad Rahmani

unread,
Apr 29, 2021, 12:11:19 PM4/29/21
to tiddl...@googlegroups.com
On Thu, Apr 29, 2021 at 4:38 PM Jean-Pierre Rivière <jn.pierr...@gmail.com> wrote:
just to be pedantic, but in old Mac'OS the end of line was only \r. so your code would not work there

$list filter="[<source>splitregexp[(\r?\n|\r)]"

will do that (not tested yet). we obviously cannot use [\r?\n?]


Created a source in Python and convert the EOL in Notepad++ to Macintosh, Unix and Windows
save and import to Tiddlywiki 5.1.24pre by drag and drop the below filter worked for all of them


filter="[<source>splitregexp[\r?\n|\r]]


 


Le jeudi 29 avril 2021 à 13:48:01 UTC+2, PMario a écrit :
On Thursday, April 29, 2021 at 12:26:23 PM UTC+2 Mohammad wrote:
It is known that the newline character is different for different OS (see Wikipedia). I am not sure if this is also true for the browsers or not!

1) If you save a multiline tiddler in TW to the internal store `\n` will be used.
2) If you copy paste content from a file to TW it will use \n

3) If you import eg: test.txt from windows there will be "\r\n" in the tiddler.
The next time you edit the tiddler and save there will be  "\n" only.

 
Having that said, what is the best practice to treat a newline character in a Tiddlywiki filter to work everywhere!

Case i

<$list filter="[<source>splitregexp[\n]]" ...

So for case 3 it will look like, if it works, but it will keep the \r in memory.
If you want to remove it use:

<$list filter="[<source>splitregexp[\r?\n]]" ... this will always work for all OSes.

\r? .. means check for \r  optional ... only if it exists

 
Case ii
<$vars newline="
" >
<$list filter="[<source>splitregexp<newline>]" ...

hmm. This won't help since internally we only use \n

hope that helps
mario

--
Reply all
Reply to author
Forward
0 new messages