logo

Test: Replacing Square Brackets in Blog Posts

For the ten years I've been running this site the square bracket has been the bane of my life.

I compose all of my blog posts in Windows Live Writer. Every now and then I include code snippets. If the code uses square brackets, which it invariably does, then it makes publishing the post a real pain in the backside.

I tend to use TextPad to create highlighted code, as it lets you copy as colour-coded HTML. Take this simple code nugget:

image

TextPad produces HTML that looks like this:

image

Nothing wrong with it, per se, but seasoned Domino-heads will see the problem immediately. If you stick this in to a Domino document then, when Domino outputs the content to the web, it will assume you want to turn on PassThru HTML mode. The results vary but at the very least you lose the square brackets and the code snippets becomes unintelligible.

The fix I've always used involves me launching Notes, finding the CodeStore database, opening it, finding the most recent blog document, opening it in ScanEZ, replacing square brackets with [ and ] before saving the document.

Now though, I've changed the Java Agent that Live Writer posts to and made it replace the brackets for me. Here's the test:

        for (var i:uint = 0; i < people.length(); i++){
                items.setItemAt(people[i], token + i);
        }

Fingers crossed, the code above will still have square brackets after I've posted.

Edit: Yay, it worked! Life just became a little easier!

For those interested the Java code is now ("content" is a Hashtable):

newPost.replaceItemValue("Body",
    content.get("description").toString()
        .replaceAll("\\[", "&#91;")
        .replaceAll("\\]", "&#93;")
);

I can't believe I waited this long to do it...

Comments

    • avatar
    • Dragon Cotterill
    • Wed 5 Jan 2011 06:02 AM

    And remember folks, allowing square brackets unmolested on comments opens a whole world of pain. Don't even go there.

    • avatar
    • Jim Fricker
    • Thu 6 Jan 2011 10:14 PM

    How about using...

    $$HTMLOptions

    "DisablePassThruHTML=1"

    to disable square bracket passthru completely?

      • avatar
      • Jake Howlett
      • Fri 7 Jan 2011 02:57 AM

      I remember thinking about that but, for some reason, not using it. Possibly as there are parts of the *design* of the Forms which rely on the brackets through one hack or another.

      Anyway, Jim, is that you? The same Jim I sat next to for a year at Merrill Lynch? You can't just turn up after ten years and post a comment like that. Where's the update on how life is treating you?

      Show the rest of this thread

Your Comments

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


About This Page

Written by Jake Howlett on Wed 5 Jan 2011

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 »

More Content