Convert Everythingese to HTML from the Command Line!
Make E2 a less laggy place!
Get rid of that unwanted nose hair!

E2 Offline Scratchpad won't run on your system? Tired of server lag, or just want to disconnect for a bit, but you still need your noding fix? Now, with de2™ version 1.0, you can test your writeups in your favorite web browser, without bogging down the server! (You know you love it.)

This is a tiny bit of illegibility I smashed together for my Mac OS X-running computer because I was tired of having to go to the Scratch Pad every time I wanted to preview a new writeup. I haven't had the opportunity to test it on other systems; all I know is that it works under tcsh for me in Mac OS X 10.2.3. However, it seems logical that it should also work on most UNIX variants running tcsh or csh; it's really not very complicated. As Everythingese, aside from the brackety links, is a subset of HTML, all that needs to be done to convert is to change the bracket links to proper anchor tags, making sure to do the pipelinks right. Sed to the rescue!

N.B.: I was learning sed and regular expressions as I wrote this thing, so I'm sure some of it could be better written.

Without further ado, I present de2 1.0:

foreach FILE ( `ls *.e2 | awk -F"." '{print $1}'` )
        sed -e 's/\[\([A-Z a-z0-9,-;:()]*\)\|\([A-Z a-z0-9,-;:()]*\)\]/<a
         href=\"http:\/\/www\.everything2\.com\/\?node=\1\">\2<\/a>/g' -e 
's/\[\([A-Z a-z0-9,-;:()]*\)\]/<a 
href=\"http:\/\/www\.everything2\.com\/\?node=\1\">\1<\/a>/g' $FILE.e2 > $FILE.html
I couldn't get the line breaks to post in any rational way, so: this code won't work until you make everything from "sed" to "> $FILE.html" into one line (there should be three lines in all: foreach...; sed...; and end). Once you get it formatted properly it would be a good idea to save the result as a text file to copy out of (see next paragraph).

So here's how to work the darn thing:

  1. Make your writeups in a text editor
  2. Save them as plain text files with .e2 extensions
  3. cd to the directory that holds your new pearls of wisdom
  4. paste the (line-corrected) code onto the command line (hit enter if necessary), and shazam! it magically takes all your .e2 files, converts the links into HTML links, and saves the results as new files with .html extensions.

If you're using Mac OS X, you can add ; open $FILE.html to the end of the second line (the one that starts with sed) to open the files in your default web browser after conversion. According to the man, the open command first appeared in NextStep, so I doubt it will work in Linux, etc. (which is why I didn't just tag it onto the end of the above code).

A few more details:

  • I didn't write the foreach line, so I'm not sure exactly how it works...
  • The following characters work for links:
    • letters
    • numbers
    • spaces
    • and any of these: , - ; : ( )
    Any other character in a link, including the apostrophe, is quite likely not to work, and to produce unreliable results for the rest of the file.
  • I'm not used to doing this kind of stuff. This thing isn't going to delete any important files (or any files at all), and it's very probable that it won't destabilize your system or anything, but all the same, I can't guarantee that it's going to work. At all.
  • If any of you more experienced types can improve this, please do! (Post your own wu's or /msg me and I'll edit mine).
  • On a related note, y'all should feel free to use this any way you want to.
I'm not a programmer... please don't hurt me...
aaah, the backslashes! they are conspiring against me!

Log in or register to write something here or to contact authors.