Back to


This page isn't meant for public consumption but there's nothing confidential here so read away if you want.

CSS Problems



Microsoft Word: How to Create a numbered list within a numbered list.

This works in MS Word 2003. I have no idea if it'll work in other versions of Word because I haven't tried it. I'm going to avoid the question of whether this is a good idea or not.

First a little background: I've written an instruction manual with sections auto-numbered 1, 2, 3... and sub-sections numbered 1.1, 1.2, 1.3... and 1.1.1, 1.1.2, 1.2.3. In some of those sections I needed to add simple numbered lists for sequences that the user should follow, for example:
1. Unscrew the yellow connector.
2. Remove the end cap.
...and so on.

What I wanted to avoid was: Unscrew the yellow connector. Remove the end cap.

I had a hell of a job trying to get one independently-numbered list within another -- Word wanted to join the two lists and selecting "restart numbering" would reset my section numbers back to the start. After a lot of trial and error I found a way to do it:

1. Create your primary numbered list as normal.
2. Create the secondary numbered list within your numbered list. The numbering will wrong.
3. Convert the secondary list to bullets.
4. Convert back to a numbered list.

Ta-dah! The primary numbering now 'jumps' the secondary list and resumes counting after it.

Creating a numbered list within a numbered list step 1 Creating a numbered list within a numbered list step 2 Creating a numbered list within a numbered list step 3 Creating a numbered list within a numbered list step 4

PHP nl2p() function

Performs a similar function to nl2br() but returns properly paragraphed HTML code.
Add headings by starting a line with 'hx:' (no quotes) where x is a single-digit number.

function nl2p($str) {

	// Convert any new line/carriage return pairs to new line.
	$str = str_replace(array("\n\r", "\r\n"), "\n", $str);
	$lines = explode("\n", $str);

	$p_open = false;
	foreach ($lines as $key => $line) {
		$line = trim($line);
		$heading = check_heading($line);
		if ($heading != "") {
			// Add a heading using <hx> tags.  
			// No need to check if we need to close a <p> block as we look-ahead and will already 
			//have closed them on the previous line. 
			$line = "<$heading>".substr($line, 3)."</$heading>";
		} elseif ($line != "" && strtolower($line) != "<hr>") {
			// If we've got to this point we'll be writing paragraph text.
			// Open <p> block
			if (!$p_open) {
				$line = "<p>".$line;
				$p_open = true;
			// Close the <p> block if:
			//  The next line is blank (double new-line = new paragraph)
			//  The next line is an <hr> (can't have <hr> in a paragraph)
			//  The next line is a heading (we'll be opening <hx> tags)
			// Note: if this is the last line, $lines[$key+1] isn't set, evaluates to "", and so we'll close the <p> block.
			if ($lines[$key+1] == "" || strtolower($lines[$key+1]) == "<hr>" || check_heading($lines[$key+1]) != "") {
				$line .= "</p>"; 
				$p_open = false;
			} else $line .= "<br />";
		//Compile result to $rtn
		if ($line !=  "") $rtn .= $line.chr(10);
	return $rtn;

function check_heading($line) {
	// If left part of the string is "hx:" where x is numeric, returns hx, else returns empty string.
	// e.g. if line = "h1:This is a heading", function returns "h1"
	$line = strtolower($line);
	if (substr($line, 0, 1) == "h" && is_numeric(substr($line, 1, 1)) && substr($line, 2, 1) == ":") return substr($line, 0, 2); 
	else return "";

Ruby on Rails

Am I ever going to get started on Ruby? Maybe I'll dive in this summer. I think I need to mooch around Nuby on Rails a bit more. I feel like php's doing everything I need at the moment.