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, 1,352 hits)
The formatting rules are as follows:
- Each line in your text file is a line item in your list
- Indent by one tab-stop (NOT spaces) to create an indented list underneath the previous item
- 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
- Put more equals signs to create smaller headings (== is a H2, === is a H3, etc)
- Skip a line to put a HR
- Links (http://…) will be converted to live hyperlinks
- A line starting and ending with “#” will be “highlighted”
- A line starting and ending with “-” will be crossed out/struck through
- A line starting and ending with “`” (backtick) will be wrapped in <code> tags
- The first Hx tag created will be used as the page <title>
- 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.
- Drop listml.php (from the download archive) into a directory on your server/host
- Drop a correctly-formatted TXT file into the same directory, let’s call it “mylist.txt”
- 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
- 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.