Why would this code strip line feeds?

Re: Why would this code strip line feeds?

Postby kunkel321 » Thu Mar 27, 2014 6:31 pm

Too weird...
That version expands the text, then smooshes it and also puts some erroneous characters in...
Here are the note contents:
Start with just the parent note:
Line one of notes
This is line two.
zzzzzzzzzzzz
and line 4.

Add subbranch "task one" and run the script. The note content becomes:
    
    
      Line one of notes
    
    
      This is line two.
    
    
      zzzzzzzzzzzz
    
    
      and line 4.
    
    
      
    
  


zzzzzzzzzz
Task: task one
Completed: 3/27/14 11:18 AM

Add "task 2" and run:
    
    
      Line one of notes
    
    
      This is line two.
    
    
      zzzzzzzzzzzz
    
    
      and line 4.
    
    
      
    
  


zzzzzzzzzz
Task: task one
Completed: 3/27/14 11:18 AM

zzzzzzzzzz
Task: task 2
Completed: 3/27/14 11:19 AM

Add "task three" and run:
    
    
      Line one of notes
    
    
      This is line two.
    
    
      zzzzzzzzzzzz
    
    
      and line 4.
    
    
      
    
  


zzzzzzzzzz
Task: task one
Completed: 3/27/14 11:18 AM

zzzzzzzzzz
Task: task 2
Completed: 3/27/14 11:19 AM

zzzzzzzzzz
Task: task 3
Completed: 3/27/14 11:19 AM

It's interesting that only the original note content gets messed up... The strings of text added by the script are all fine...
kunkel321
 
Posts: 131
Joined: Thu Aug 16, 2012 4:23 am

Re: Why would this code strip line feeds?

Postby boercher » Fri Mar 28, 2014 12:56 am

The ' ' (non-breakable space) characters are a real pain: They look like normal spaces but behave very bad since all other but our eyes treat them differently :roll:

Without having analyzed the problem thoroughly I guess that you picked up the evil "pseudo space characters" somehow via copy&paste from the browser and that the method I used for concatenation doesn't handle them well. Could you please test the following, slightly modified script (untested!) as htmlToPlain with the given arguments should preserve newlines?
Code: Select all
    def task = node.plainText
    def datetime = new Date()
    def student = node.parent
    def oldNote = parent.noteText
    def plainOldNote = (oldNote) ? htmlUtils.htmlToPlain(oldNote, true, false) : ""
    student.note = plainOldNote + """
    zzzzzzzzzz
    Task: ${task}
    Completed: ${format(datetime)}
    """
    node.delete()


Volker
boercher
 
Posts: 644
Joined: Tue Jul 26, 2011 7:13 am

Re: Why would this code strip line feeds?

Postby kunkel321 » Fri Mar 28, 2014 4:12 pm

“Non-breakable space?” Sheesh… I never even knew there was such a thing!
When you say that I may have picked them up from the browser, do your mean when copy-n-pasting code from the forums here, and pasting it to my groovy file, or do you mean pasting it into the note field on my map?? I haven’t pasted anything into the map notes (except the pasting that the script is doing).
I’ve noticed there are some possibly relevant Preference Options in Freeplane, such as Behavior >> Default paste mode. I’ve tried both settings and get the same result, but maybe there are other settings that would impact this script?

At any rate, here are the note contents with the latest version of the script that you added:
Add a new node “Jonny Doe” and type (not paste) some notes in:
Jonny's notes.
Line two.
zzzzzzzzzzzzz
Line 4.

Add branch “Task one” and run the script:
Jonny's notes.

Line two.

zzzzzzzzzzzzz

Line 4.
    zzzzzzzzzz
    Task: task one
    Completed: 3/28/14 8:49 AM

Create "task two" and run:
Jonny's notes.Line two.zzzzzzzzzzzzzLine 4.    zzzzzzzzzz    Task: task one    Completed: 3/28/14 8:49 AM    
    zzzzzzzzzz
    Task: task 2
    Completed: 3/28/14 8:49 AM

POSSIBLY IMPORTANT: I should point out that forcing my case notes into “plain text” is not a necessary part of my scheme… I’m assuming that my other script (which saves the Jonny Doe.txt file, allowing me to send the file to my Kindle Fire HD) will convert the notes to text format anyway—so it makes sense for this script to work with plain text. The reality is that lots of different junk will get pasted in to my case notes… I regularly past in stuff copied from Outlook, Word, and Excel, as well as from my Chrome browser and text-expansion from MacroExpress. (Though no pasting happened for the above tests!) So it probably doesn't matter if HTML or text is used...
And again, I really do appreciate the help, but please don’t stress yourself out on my account! :lol:
kunkel321
 
Posts: 131
Joined: Thu Aug 16, 2012 4:23 am

Previous

Return to Open Discussion

Who is online

Users browsing this forum: No registered users and 1 guest