Code: ListML

I’m sure the name has been used before, but I’m going to call this project ListML, standing for List Markup Language. It came about because I realized I write a lot of lists, almost always hierarchical, and then quite often I’d like to get those lists in HTML format. Normally I just write my lists in plain text, using tabs to indent things, and a few other minimal standards of markup, so I figured it couldn’t be that hard to write something to convert the plain text into HTML.

A little tinkering later and we have a basic set of formatting rules and a quick PHP script to convert plain text, hierarchical lists, into beautiful POSH + CSS. You can download the ListML script now, and then take that as a core parser to convert TXT to HTML, given the rules below.

Download   ListML 1.1 (3.4 KiB, 2,115 hits)

As an example, here is a source TXT file, and the resulting HTML output.

The formatting rules are as follows:

  1. Each line in your text file is a line item in your list
  2. Indent by one tab-stop (NOT spaces) to create an indented list underneath the previous item
  3. Put a “= ” (equals sign, followed by a space) at the start of a far-left-aligned line to create an H1 tag in your output
  4. Put more equals signs to create smaller headings (== is a H2, === is a H3, etc)
  5. Skip a line to put a HR
  6. Links (http://…) will be converted to live hyperlinks
  7. A line starting and ending with “#” will be “highlighted”
  8. A line starting and ending with “-” will be crossed out/struck through
  9. A line starting and ending with “`” (backtick) will be wrapped in <code> tags
  10. The first Hx tag created will be used as the page <title>
  11. All lists created will be OL (ordered lists) with default CSS attached. Feel free to change the CSS or use your list output elsewhere

You can consider this licensed under a GPL license.

How To Use

To use this specific ListML script, you need a host capable of running PHP.

  1. Drop listml.php (from the download archive) into a directory on your server/host
  2. Drop a correctly-formatted TXT file into the same directory, let’s call it “mylist.txt”
  3. Request the listml.php file via a browser, with the base of the filename as the “file” parameter, which will look something like this: http://myserver/listml.php?file=mylist
  4. Bask in the glory of your HTML list.

Obviously you could pull out the core of the parsing “engine” for ListML and use it in other places, but I’ll let you handle that.

What do you think?