How to split a dragged paragraph of text into individual sentences with unordered list formatting

Here I am trying to create a note-generator using droppable widget. I plan to drag and drop text and images into this dropzone to create new note tiddlers. A function similar to web clippers.
These two post were the building steps in this process -1 and 2. What I want now is to split a dragged paragraph of text into individual sentences with unordered list formatting.
May be split the dragged text at period or full-stop and join them with period+line-break+bullet

This is the relevant part of the code

\procedure droppable-text-actions()
<$action-createtiddler $basetitle={{{ [<actionTiddler>split[/]last[]] }}} $template=<<actionTiddler>> >
<$wikify name=import-text text=<<actionTiddler>>>
<$let
lf="""
"""
ul=* 
2ul=** 
>
<$action-setfield $tiddler=<<createTiddler-title>> 
    text={{{ [<actionTiddler>] }}}
   class="card-3"/>
<$list filter="[<modifier>match[normal]]" variable=nul>
<$action-setfield $tiddler="$:/arsheth/new_note/form" text={{{[[$:/arsheth/new_note/form]get[text]addsuffix<lf>addsuffix<lf>addsuffix<import-text>else<import-text>] }}} />
</$list>
<$list filter="[<modifier>match[ctrl]]" variable=nul>
<$action-setfield $tiddler="$:/arsheth/new_note/form" text={{{[[$:/arsheth/new_note/form]get[text]addsuffix<lf>addsuffix<ul>addsuffix<import-text>else<import-text>] }}} />
</$list>
<$list filter="[<modifier>match[ctrl-shift]]" variable=nul>
<$action-setfield $tiddler="$:/arsheth/new_note/form" text={{{[[$:/arsheth/new_note/form]get[text]addsuffix<lf>addsuffix<2ul>addsuffix<import-text>else<import-text>] }}} />
</$list>
</$let>
</$wikify>
<$action-deletetiddler $tiddler=<<createTiddler-title>>/>
</$action-createtiddler>
\end

How to modify the above code to get the result ?

nospace-text={{{[<import-text>search-replace:g:regexp[\s+\n],[ ]search-replace:g:regexp[\s+],[ ]search-replace:g:regexp[\.],[.\r\n*]] }}}

Using this code (taken from a solution by @etardiff) , I was able to remove extra spaces and line breaks.
But I want to replace period with period+line-break+bullet
How to make this work?

This should work:

<!-- functions for cr & lf (I have these saved in a tiddler with tag `$:/tags/Global` ) -->
\function cr()[charcode[13]]
\function lf()[charcode[10]]
<!-- \s matches any whitespace including \n, so [\s+],[ ] will match any number of whitespaces and replace with a single space.  -->
<!-- [\.\s*] matches period with any number of trailing whitespace.  -->
<!-- [\.\s*|^] also adds period & bullet at the start of the line -->
<!-- removeprefix<.lf> removes the leading .\n -->
<!-- removesuffix[* ] removes the trailing bullet & space -->
<$let
  .lf={{{ [[.]addsuffix<lf>]}}}
  .lfbullet={{{ [[.]addsuffix<lf>addsuffix[* ]]  }}}
  .lfbullet2={{{ [[.]addsuffix<lf>addsuffix[** ]]  }}}
  nospace-text={{{ [<import-text>search-replace:g:regexp[\s+],[ ]search-replace:g:regexp[\.\s*|^],<.lfbullet>removeprefix<.lf>removesuffix[* ]] }}}
>

<$codeblock code=<<nospace-text>> />
1 Like

@VikingMage thank you for taking time to look into this. I am at workplace now …I will check it once I am back home.

@VikingMage i was not able to make it work. Can you give me an example code which can be tested in tiddlywiki.com

@VikingMage The code you gave was not working in my setting. Can you help me to correct it.

Or can some regexp experts help to achieve this goal.

\procedure droppable-text-actions()
<$action-createtiddler $basetitle={{{ [<actionTiddler>split[/]last[]] }}} $template=<<actionTiddler>> >
<$wikify name=import-text text=<<actionTiddler>>>
<$let
  .lf={{{ [[.]addsuffix<lf>]}}}
  .lfbullet={{{ [[.]addsuffix<lf>addsuffix[* ]]  }}}
  .lfbullet2={{{ [[.]addsuffix<lf>addsuffix[** ]]  }}}
  nospace-text={{{ [<import-text>search-replace:g:regexp[\s+],[ ]search-replace:g:regexp[\.\s*|^],<.lfbullet>removeprefix<.lf>removesuffix[* ]] }}}
>
<$action-setfield $tiddler=<<createTiddler-title>> 
    text={{{ [<actionTiddler>] }}}
   class="card-3"/>
<$list filter="[<modifier>match[normal]]" variable=nul>
<$action-setfield $tiddler="$:/arsheth/new_note/form" text={{{[[$:/arsheth/new_note/form]get[text]addsuffix<nospace-text>else<nospace-text>] }}} />
</$list>
<$list filter="[<modifier>match[ctrl]]" variable=nul>
<$action-setfield $tiddler="$:/arsheth/new_note/form" text={{{[[$:/arsheth/new_note/form]get[text]addsuffix<nospace-text>else<nospace-text>] }}} />
</$list>
</$let>
</$wikify>
<$action-deletetiddler $tiddler=<<createTiddler-title>>/>
</$action-createtiddler>
\end

Here is the demo

2 Likes

Interesting. If nobody solves this by the time I’ve gotten to my desk I will take a look, as I find it interesting and sounds a bit similar to what I was trying to do with unfusing fused streams

Is this something like what you’re going for?

\procedure droppable-text-actions()
<$action-createtiddler $basetitle={{{ [<actionTiddler>split[/]last[]] }}} $template=<<actionTiddler>> >
<$wikify name=import-text text=<<actionTiddler>>>
<$let
lf="""
"""
ul=* 
2ul=** 
>
<$action-setfield $tiddler=<<createTiddler-title>> 
    text={{{ [<actionTiddler>] }}}
   class="card-3"/>
<$list filter="[<modifier>match[normal]]" variable=nul>
<$action-setfield $tiddler="$:/arsheth/new_note/form" text={{{
  [<import-text>split[.]trim[]addprefix[* ]addsuffix[.]join<lf>]
  +[prefix{$:/arsheth/new_note/form}addsuffix<lf>]
}}} />
</$list>
<$list filter="[<modifier>match[ctrl]]" variable=nul>
<$action-setfield $tiddler="$:/arsheth/new_note/form" text={{{
  [<import-text>split[.]trim[]addprefix[* ]addsuffix[.]join<lf>]
  +[prefix{$:/arsheth/new_note/form}addsuffix<lf>]
}}} />
</$list>
<$list filter="[<modifier>match[ctrl-shift]]" variable=nul>
<$action-setfield $tiddler="$:/arsheth/new_note/form" text={{{
  [<import-text>split[.]trim[]addprefix[** ]addsuffix[.]join<lf>]
  +[prefix{$:/arsheth/new_note/form}addsuffix<lf>]
}}} />
</$list>
</$let>
</$wikify>
<$action-deletetiddler $tiddler=<<createTiddler-title>>/>
</$action-createtiddler>
\end
1 Like

@well-noted It is working well. I need to do some more testing to remove some unwanted extra spaces within single sentences which occurs when a paragraph of text is dragged and dropped. Thank you for helping me out.

Sort of similar problem to what I faced with the unfusion, so it was fresh in my mind. Will be enthusiastic to see what you come up with. I actually am still needing to check out the image to text conversion to see how you’ve pulled it off.

EDIT:

Is that not working currently? Perhaps I misunderstand how it’s supposed to work? :slight_smile:

Are you taking about dropping images ?
It was working when I checked last time in my local wiki. I use mostly local images only and I use a custom image widget. So the current set up will only work in such a setting.

I used this method by @Charlie_Veniot . This might be useful for you.

In this method, if I drag and drop any text the second time, the already existing text gets deleted and currently dragged text is not getting appended to the text field.

Edit: This modified code seem to works without deleting the already existing text. But it creates an extra bullet at the end. Any way to remove it

\procedure droppable-text-actions()
<$action-createtiddler $basetitle={{{ [<actionTiddler>split[/]last[]] }}} $template=<<actionTiddler>> >
<$wikify name=import-text text=<<actionTiddler>>>
<$let
lf={{{ [charcode[10]] }}}
nospace-text={{{[<import-text>search-replace:g:regexp[\s+\n],[ ]search-replace:g:regexp[\s+],[ ]] }}}
linebreak-text={{{ [<nospace-text>search-replace:g:regexp[(\n)(\n+)],[$1]search-replace:g:regexp[\ +],[ ]]}}}
bullet-text={{{[<import-text>split[.]trim[]addprefix[* ]addsuffix[.]butlast[]join<lf>]}}}
bullet2-text={{{[<import-text>split[.]trim[]addprefix[** ]addsuffix[.]butlast[]join<lf>]}}}
>
<$action-setfield $tiddler=<<createTiddler-title>> 
    text={{{ [<actionTiddler>] }}}
   class="card-3"/>
<$list filter="[<modifier>match[normal]]" variable=nul>
<$action-setfield $tiddler="$:/arsheth/new_note/form" text={{{[[$:/arsheth/new_note/form]get[text]addsuffix<lf>addsuffix<lf>addsuffix<nospace-text>else<nospace-text>] }}} />
</$list>
<$list filter="[<modifier>match[alt]]" variable=nul>
<$action-setfield $tiddler="$:/arsheth/new_note/form" text={{{[[$:/arsheth/new_note/form]get[text]addsuffix<lf>addsuffix<lf>addsuffix<linebreak-text>else<linebreak-text>] }}} />
</$list>
<$list filter="[<modifier>match[ctrl]]" variable=nul>
<$action-setfield $tiddler="$:/arsheth/new_note/form" text={{{[[$:/arsheth/new_note/form]get[text]addsuffix<lf>addsuffix<lf>addsuffix<bullet-text>else<bullet-text>] }}} />
</$list>
<$list filter="[<modifier>match[ctrl-shift]]" variable=nul>
<$action-setfield $tiddler="$:/arsheth/new_note/form" text={{{[[$:/arsheth/new_note/form]get[text]addsuffix<lf>addsuffix<lf>addsuffix<bullet2-text>else<bullet-text>] }}} />
</$list>
</$let>
</$wikify>
<$action-deletetiddler $tiddler=<<createTiddler-title>>/>
</$action-createtiddler>
\end

Edit-2: Adding butlast operator removed this extra bullet

Thank you @well-noted the new filter ideas which helped me solve this atleast for the time being. I will update the demo wiki

1 Like

Sorry for the late response, I’m glad you were able to get it working.

I was focused on the $let statement and forgot to put it back into the context of your procedure.

Here’s what it should have looked like.

\function cr()[charcode[13]]

\function lf()[charcode[10]]

\procedure droppable-text-actions()
<$action-createtiddler $basetitle={{{ [<actionTiddler>split[/]last[]] }}} $template=<<actionTiddler>> >
<$wikify name=import-text text=<<actionTiddler>>>
<$let
  .lf={{{ [[.]addsuffix<lf>]}}}
  .lfbullet={{{ [[.]addsuffix<lf>addsuffix[* ]]  }}}
  .lfbullet2={{{ [[.]addsuffix<lf>addsuffix[** ]]  }}}
  nospace-text={{{ [<import-text>search-replace:g:regexp[\s+],[ ]search-replace:g:regexp[\.\s*|^],<.lfbullet>removeprefix<.lf>removesuffix[* ]] }}}
>
<$action-setfield $tiddler=<<createTiddler-title>> 
    text={{{ [<actionTiddler>] }}}
   class="card-3"/>
<$list filter="[<modifier>match[normal]]" variable=nul>
<$action-setfield $tiddler="$:/arsheth/new_note/form" text={{{[[$:/arsheth/new_note/form]get[text]addsuffix<lf>addsuffix<lf>addsuffix<nospace-text>else<nospace-text>] }}} />
</$list>
</$let>
</$wikify>
<$action-deletetiddler $tiddler=<<createTiddler-title>>/>
</$action-createtiddler>
\end
1 Like

@VikingMage thank you. I will test it out when I am back home. On a small vacation now.