logo

Highlighting Code in HTML

Ever wonder how people do things but you feel too silly to ask? I do sometimes. Take code highlighting on the web for example. I see people posting fully highlighted code snippets in their blogs and I have no idea how they managed it. Surely they weren't doing it all manually.

I still don't know how most people do it but I have found one way to do it. After what seems like an age, my favourite text editor, TextPad, has had an upgrade. One of the new features is the ability to:

Publish your code on the web, with full syntax highlighting, using the new "Copy as a HTML page" command.

Here's an example (and a piece of code worth keeping hold of):

//Remove leading and trailing spaces from a string
//Originally written by Jim Fricker
function trim(aStr) {
return aStr.replace(/^\s{1,}/, "").replace(/\s{1,}$/, "")
}

Nice. You can even create your own highlighting definitions. Thanks to Page Nix there's already one for LotusScript and @Formulas that we can download from the site along with many others. Not sure how useful it is to be able to have coloured HTML of your Notes function but it appeals to me as the owner of a code store ;o)

REM "Function to create a calendar of a month's blogs";
tmp := @DbLookup(""; ""; "calendar"; ShowBlogsFor; 2);
blogs:=@If(@IsError(tmp); ""; tmp);
startDate:=@Date( @TextToNumber(@Left(ShowBlogsFor;"-")); 
@TextToNumber(@Right(ShowBlogsFor; "-")); 1);
startDay := @Weekday( startDate );

Another nice new feature is the ability to paste text you've copied from IE or Mozilla in to an open .html document with all the markup intact. A bit like Domino Designer does with Pages but not as annoying ;o)

Comments

  1. Textpad is quite cool doing that, but even more cool is Julian's ls2html {Link} script that does the same thing but in LotusScript!

    • avatar
    • Dan
    • Thu 20 Mar 2003 13:41

    Speaking of Julian's ls2html routine, Joe Litton posted a cool LS example (Win API to mimic keystrokes) and rendered the LS using ls2html.

    URL: {Link}

    • avatar
    • Jake
    • Thu 20 Mar 2003 19:56

    Nice work. Joe Litton's blog looks good. Is it me is there a new Domino blog out every day. Finding it hard to keep up with it all at the moment ;o)

  2. Jake, it's not just you. There *IS* a new Domino blog just about every day. I was pretty late getting into this (been programming for 17 years and doing Notes for 7) -- only started looking at blogging a couple of months ago. MAN! there's some great stuff out there. Including tips for Domino hosting -- I read about Prominic on Codestore and that's where my site's hosted now.

  3. I've been with Prominic for about 18 months I believe, ever since Jake recommended them. I have to say I've yet to think of a negative comment.

    It's just a pitty I can't find a similar service for Coldfusion MX - the next thing I want to play with.

    • avatar
    • David Frahm
    • Fri 21 Mar 2003 12:39

    They may have Coldfusion MX hosting here...

    {Link}

    ...but I'm not sure. The content and links didn't make sense to me.

Your Comments

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


About This Page

Written by Jake Howlett on Thu 20 Mar 2003

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