logo

Domino Inserts Random Paragraphs and Breaks HTML

On Friday I go away on my stag weekend. Next Thursday I get married. Tomorrow I have to deliver the finished article for my latest client's project. Needless to say life is a little hectic at the moment.

The last thing I need is another problem on my plate. So, you can imagine my stress levels went up a notch when said client called to say a test page had gone "all strikethrough". I took a lot at the page to find that the majority of the page was indeed marked-up as strikethrough. Not good.

At first I thought it might be the TinyMCE editor at fault. The problem is in fact with Domino and is something you really need to know about if you use this technique. The solution is simple though. First the problem.

Looking at the source code at the point where strikethough began the HTML looked like this.

<s
trong>This bit was all was strikethrough

Obvious what's happened isn't it? A line break has been inserted in the tag and so the browser baulks at it and decides to simply render it as the start of a <s> tag, to which there is no corresponding end tag and so the whole page goes crazy. Example.

The quick solution is to save the page again, which, more often than not, gets rid of the problem. Like lightning the new line never strikes in the same place twice (see what I did there?). But it will always come back to haunt you sooner or later. Although it doesn't always manifest itself in the same way, this new line insertion is a real pain of a bug.

To debug it the first thing I did was see what Notes was storing in the back-end. So I opened up my copy of ScanEZ and looked inside the document. Here's what I saw:

Here we're looking at the Body field and its composite items. As you can see there are lots of chunks of text. However, stuck in the middle of it all is an empty Paragraph. If we look at the Text chunk after the Paragraph we see that it starts with "trong>". The one before the Paragraph ended with "<s". And there lies the problem.

At this point I remembered having read about something like this before. Sure enough, a quick Google for "domino inserts paragraph in rich text" immediately returned the solution from IBM.

Domino inserts "random" line breaks at around the 16,000th character. It's a regression bug that came back in with release 6.0 and has only now been fixed with the release of 6.5.5. A quick call to the client and they're happy to upgrade to this release before launch tomorrow.

Big sigh of relief and back to worrying about my speech.

Comments

    • avatar
    • Lee
    • Wed 5 Apr 2006 04:43 AM

    Hi Jake

    Didn't you know it was bad luck to do April fool jokes after the event? ,-)

    • avatar
    • Jake
    • Wed 5 Apr 2006 05:00 AM

    I wish it was a joke Lee...

    • avatar
    • Yogi
    • Wed 5 Apr 2006 06:58 AM

    As the problem relies on the NotesRichTextItem.AppendText() method, you might use DXL instead to compose your RTF (i can provide samples).

    • avatar
    • Jake
    • Wed 5 Apr 2006 07:13 AM

    Sounds interesting Yogi. Can you send examples over?

  1. Hi Jake...

    I currently have this problem too... I found that in the new version of the "TinyMCE", that they have a "save_callback" function where you can modify the html that is being saved.

    The reason why i say this, is that the HTML you are saving from "TinyMCE" is being saved in one continuous string. Therefore domino needs to insert a paragraph break if the string goes over it's paragraph size limit for a RichText field.

    Using the "save_callback" function for "TinyMCE", you can insert your own paragraph break (i.e. '\n') into the HTML.

    Example:

    HTML = ReplaceSubString(HTML, "</p>", "</p>\n")

    Using the example above, the code will append a "\n" after each new paragraph. Domino will interpret this as a new paragraph (i.e. carriage return). Thus fixing your problem!!!

    Later

    Patrick

    P.S. This solution is currently working in a Domino 6.5.4 environment.

    P.P.S. Can you let me know if the fix for 6.5.5. works???

    • avatar
    • Jake
    • Wed 5 Apr 2006 07:26 AM

    Interesting Patrick. I'd not thought of attacking it from that angle. If the 6.5.5 fix doesn't work I'll let you know and switch to using your workaround. Cheers.

  2. Hi Jake,

    Let me tell you, i found out that solution the hard way.... Currently working in a Civil Service department with over 300+ users....

    That problem caused me alot of grief!!!

    Later

    Patrick

  3. Jake, I did two best man's speeches before doing my groom's one.

    The groom's one was easy, I said what I felt about my wife, thanked the mums with bouquets and never mentioned "tiny mice" once.

    Get those rich text editors out of your head and have a great day. I hope the sun shines, the bride turns up on time and the DJ is awesome. Everything else is handled by somebody else. Enjoy yourself!

  4. All the best next week and ever after Jake, to you and Karen (and Quinn!). Just wanted to second Andy's sentiments. Relax and Enjoy and if something doesn't go just right, just laugh (maybe not out loud) and set your mind at ease. :-)

  5. I'll second Jerry's comments, for seconding Andy's comments, to say have fun!

    On the tech side, I have used the triggerSave() event of the TinyMce object to do validation and when using AJAX and TinyMCE.

    {Link}

    I think Patrick's method is doing roughly the same thing but I would have to check the code.

    • avatar
    • Chris Brewer
    • Wed 5 Apr 2006 01:27 PM

    I'll echo everyone else's comments to say good luck and I know what you're going through as I'm getting married myself on Sunday. My last day of work was yesterday but it was spent running around tieing up loose ends.

    Now I can start worrying about the wedding proper! :)

    • avatar
    • Fredrik
    • Wed 5 Apr 2006 04:33 PM

    hehe, funny I ran into the same problem last week. Solved it in the same way as Patrick did:

    return html.split("</p>").join("</p>\n");

    • avatar
    • Mark Vincenzes
    • Wed 5 Apr 2006 07:08 PM

    Would it be possible for you to store your HTML as a MIME type item rather than as passthru html in a rich text item?

  6. Wow, thanks everyone! I was just about to run into the same problem, and here is even the solution :-)

    • avatar
    • Jake
    • Thu 6 Apr 2006 02:31 AM

    Patrick. I can confirm that 6.5.5 does indeed fix the bug.

    Gerald. MIME? Hmmm, I don't know. I seem to remember not, but I could be wrong.

  7. Jake, I'm sure you meant Mark.

    For all the ones who need to write the HTML inside LotusScript (e.g. I'm using it after I've read a whole web page into memory), the following subroutine could help. It safely inserts a paragraph after 7000 characters after the next '>' character. Use at your own risk (has been only marginally tested).

    Sub SaveHTMLToRTItem(rnrti As NotesRichTextItem, rstr_HTML As String)

    %REM

    This is a workaround for the following Domino bug:

    "AppendText method of LotusScript inserts carriage returns into RichText item"

    {Link}

    If the carriage return is inserted in the middle of an HTML tag, the HTML breaks.

    This sub will break up the HTML into chunks of 7000 characters, look for the next

    closing tag '>' and then append a new line.

    The parameter rstr_HTML has been passed by reference in ordrer to avoid

    copying large amounts of data in memory.

    %END REM

    Dim lng_Pos As Long

    Dim lng_PosOld As Long

    Const lng_CHUNK_LENGTH = 7000&

    lng_Pos = Instr(lng_CHUNK_LENGTH, rstr_HTML, ">")

    If lng_Pos = 0 Then

    rnrti.AppendText(rstr_HTML)

    rnrti.AddNewline(1)

    Else

    lng_PosOld = 0

    Do Until lng_Pos = 0

    rnrti.AppendText(Mid$(rstr_HTML, lng_PosOld + 1, lng_Pos - lng_PosOld))

    rnrti.AddNewline(1)

    lng_PosOld = lng_Pos

    lng_Pos = Instr(lng_Pos + lng_CHUNK_LENGTH, rstr_HTML, ">")

    Loop

    rnrti.AppendText(Mid$(rstr_HTML, lng_PosOld + 1))

    rnrti.AddNewline(1)

    End If

    End Sub

  8. Hi Jake,

    Thanks for that.... Not sure whether they will update to 6.5.5 here. Most likely they will leap to 7 instead, but that's way, way down the line.

    I suppose it's good to know that there are a couple of solutions to the problem.

    Later

    Patrick

    • avatar
    • James Jennett
    • Fri 7 Apr 2006 05:51 AM

    Whatever happens, it won't be as hard as the bike ride... ;)

  9. My I suggest an alternative way of implementing TinyMCE in a page which would avoid this problem.

    1. First create a editable text field at the top of your form.( for this example its name is aTextField ). Hide of from the web and notes.

    Now where you actually want the text area and content to appear create some computed text marked as pass thru html.

    Add the following formula to the comuted text.

    prefix := "<textarea name=\"aTextField\" style=\"visibility:hidden;\">";

    suffix := "</textarea>";

    @If (@IsDocBeingEdited;

    prefix+aTextField+suffix;

    aTextField )

    I have been using this at work and it works fine.

Your Comments

Name:
E-mail:
(optional)
Website:
(optional)
Comment:


About This Page

Written by Jake Howlett on Wed 5 Apr 2006

Share This Page

# ( ) '

Comments

The most recent comments added:

Skip to the comments or add your own.

You can subscribe to an individual RSS feed of comments on this entry.

Let's Get Social


About This Website

CodeStore is all about web development. Concentrating on Lotus Domino, ASP.NET, Flex, SharePoint and all things internet.

Your host is Jake Howlett who runs his own web development company called Rockall Design and is always on the lookout for new and interesting work to do.

You can find me on Twitter and on Linked In.

Read more about this site »

Elsewhere

Here are the external links posted on the same day.

More links are available in the archive »

More Content