SWL, the Short Web Language
From 2000 to 2005, I wrote and rewrote a language of my own for writing web
pages: SWL, the Short Web Language.
It began on July 28, 2000, as a Perl script called HT.pl, was rebuilt as
SWL 2 in 2001, and came to its tenth and last distribution, version 2.10, on
August 15, 2005.
From 2005 to 2009, I wrote the posts on my old blog,
Ask a Wizard, in it.
SWL was made irrelevant by a combination of style sheets and Markdown. At the time, SWL allowed users to create macros that allowed a template to emit appropriate typographic and color choices based on semantic tags, so style could be edited orthogonal to content.
This is what it was, and why that was worth doing then. The compiler still runs. Every output on this page is from SWL 2.10, run under a current Perl, and recompiling its documentation today gives the same HTML it gave in September 2005, byte for byte, but for the timestamp in a comment.
Abbreviated HTML #
In the SWL README, I state:
When writing web-sites, you typically either write the HTML code or use a ‘WYSIWYG’ (What You See Is What You Get) editor to make it for you. Some sites use dynamic content languages, e.g., ASP or PHP, to generate their code for them on the fly. SWL is an efficient alternative to each of these.
SWL is, simply put, abbreviated HTML.
The line is the unit.
Every line is a paragraph unless a line-tag begins it: a short name,
usually one character, and a >.
A tag takes one line, tag> content, or a block of indented lines closed by
/>, and blocks nest.
Anything SWL does not recognize passes through to the HTML untouched, so the
inline formatting was HTML’s own <b> and <i>.
This SWL:
2>Benefits
SWL is, simply put, abbreviated HTML.
Each line is a paragraph unless a tag starts it.
*>
<b>Easy</b> to learn.
<b>Brevity.</b> SWL code is as short as it gets.
/>
t>
A1 B1
A2 B2
/>
< //cixar.com/~swilly "Swilly's Homepage" >
becomes this HTML:
<h2>
Benefits
</h2>
<p>SWL is, simply put, abbreviated HTML.</p>
<p>Each line is a paragraph unless a tag starts it.</p>
<ul>
<li><b>Easy</b> to learn.</li>
<li><b>Brevity.</b> SWL code is as short as it gets.</li>
</ul>
<p><table border="1" cellpadding="4" cellspacing="0">
<tr>
<td>
A1
</td>
<td colspan=2>
B1
</td>
</tr>
<tr>
<td>
A2
</td>
<td colspan=2>
B2
</td>
</tr>
</table></p>
<p><a href="//cixar.com/~swilly">Swilly's Homepage</a></p>
A table is a row per line and a tab between cells.
A link is a URL in spaced angle brackets, with its text after it.
An address ending in .gif, .jpg, .jpeg, .png or .svg became an
image, one with an @ in it became a mailto: link, and ~/ stood for the
root of the site, so that a site could move by changing one variable.
The tags were few:
| Tag | Makes |
|---|---|
1> to 6> |
headings |
*>, #> |
bulleted and numbered lists |
t> |
a table |
->> |
a horizontal rule |
p> |
paragraphs, the default |
:> |
plain HTML, untouched |
P> |
a stanza: one paragraph, with a break between lines |
j> |
an anchor |
o> |
an outline, by indentation |
"> |
preformatted text |
+> |
an include: SWL, text, HTML, tab-separated or CSV |
!> |
a comment |
c> |
a calendar, from dated events |
^> |
a macro |
=> |
template variables |
Templates #
Every page was compiled into a template.
SWL looked for a template named @.swlt or local.swlt beside the page, and
then up the directory tree, so one template at the root of a site dressed
every page beneath it.
A template set variables, and the template variable was the page itself,
with <swl /body> where the document went.
My standard template, from SWL’s library:
@>
=>
author>SWL <swl version>
title>SWL Document
template>
<html>
<!-- by <swl author> <swl date> -->
<head>
<title><swl title></title>
<meta http-equiv=Expires content=0>
<style>
body
{
font-family: Verdana,Helvetica,Arial,Sans Serif;
font-size: 15px;
color: #000000;
}
p, tr, thred, tfoot, th, td, dl, ol, ul, blockquote, span, br
{
font-size: 15px;
}
</style>
</head>
<body>
<table border=0 cellspacing=0 cellpadding=0 width=700></tr><td>
<swl /body>
</td></tr></table>
</body>
</html>
/>
/>
table>
border >1
cellspacing >>0
cellpadding >4
/>
/>
The @> block holds the defaults for HTML attributes: every table on the
site got a border, and its spacing and padding, from these three lines.
The template I wrote for SWL’s documentation went on to color things:
table>
border >1
cellspacing >>0
cellpadding >2
bgcolor >eeeeee
/>
th>
bgcolor >aaeeff
/>
calendar>
week.bgcolor>bbddee
blank.bgcolor>cccccc
date.bgcolor>ffcccc
event.bgcolor>bbddee
/>
Macros and semantic tags #
The ^> tag defines new tags.
A macro says what HTML goes around a block (top and bottom), what goes
around each of its lines (left and right), and what replaces the first
colon on each line (colon), with variants for a tag used on one line or on
many.
In SWL’s documentation, I suggested overriding even the horizontal rule this
way, “with a graphic that fits in your document’s theme.”
This one is from a post I wrote in January 2007:
^.argument>
left><p><b>
colon>:</b>
right></p>
/./>
argument>
Given: In raw speed, a hare is faster than a tortoise.
Given: In raw determiniation, a toirtise is faster than a hare.
Query: How fast would a tortihare be?
Answer: Who cares. Strap a rocket on its back.
/>
<p><b>Given:</b> In raw speed, a hare is faster than a tortoise.</p>
<p><b>Given:</b> In raw determiniation, a toirtise is faster than a hare.</p>
<p><b>Query:</b> How fast would a tortihare be?</p>
<p><b>Answer:</b> Who cares. Strap a rocket on its back.</p>
My blog had a few of these.
chat set out a conversation, a speaker to a line, in a post of September
2006.
defs turned name: description lines into a definition list, <dl>, <dt>
and <dd>, for the methods of a JavaScript collection library in March 2008.
And my blog’s template redefined the level-one heading, so that each
post’s title compiled to the bare line that its blog engine, PyBlosxom,
wanted for a title.
The page says what its lines are: an argument, a chat, a list of definitions. The macro says what they look like. Move the macro out of the page and into the site’s template, and the look of every argument on the site is one edit away, made once and compiled into every page. Here is the same page, with its macro taken out:
1>Toirtise and the Hare
argument>
Given: In raw speed, a hare is faster than a tortoise.
Given: In raw determiniation, a toirtise is faster than a hare.
Query: How fast would a tortihare be?
Answer: Who cares. Strap a rocket on its back.
/>
and a site template that dresses arguments in the manner of the day, a table
for the layout and <font> for the face, size and color, in the navy that my
documentation used for its links:
^>
argument>
top><table border=0 cellpadding=4 cellspacing=0 bgcolor="#eeeeee">
left><tr><td align=right valign=top><font face="Verdana,Arial" size=2 color="#000077"><b>
colon></b></font></td><td><font face="Verdana,Arial" size=2>
right></font></td></tr>
bottom></table>
/>
/>
=>
template>
<swl /body>
/>
/>
<h1>
Toirtise and the Hare
</h1>
<table border=0 cellpadding=4 cellspacing=0 bgcolor="#eeeeee">
<tr><td align=right valign=top><font face="Verdana,Arial" size=2 color="#000077"><b>Given</b></font></td><td><font face="Verdana,Arial" size=2> In raw speed, a hare is faster than a tortoise.</font></td></tr>
<tr><td align=right valign=top><font face="Verdana,Arial" size=2 color="#000077"><b>Given</b></font></td><td><font face="Verdana,Arial" size=2> In raw determiniation, a toirtise is faster than a hare.</font></td></tr>
<tr><td align=right valign=top><font face="Verdana,Arial" size=2 color="#000077"><b>Query</b></font></td><td><font face="Verdana,Arial" size=2> How fast would a tortihare be?</font></td></tr>
<tr><td align=right valign=top><font face="Verdana,Arial" size=2 color="#000077"><b>Answer</b></font></td><td><font face="Verdana,Arial" size=2> Who cares. Strap a rocket on its back.</font></td></tr>
</table>
I wrote that template for this page; my blog’s macros lived in the posts that used them. Swap it for one with the first macro in it, and the same page compiles back to the paragraphs above. The writing does not change.
Its time #
In 2000, style lived in the markup.
The standards had already moved on.
Cascading Style Sheets had been a W3C Recommendation since December 1996, and
HTML 4.01, in December 1999, deprecated <font> and bgcolor in their favor.
The browsers had not.
In February 2001, Jeffrey Zeldman’s editorial for A List Apart, “To Hell With
Bad Browsers,” argued that designers should write to the standards anyway,
because “in the year 2000, Microsoft, Netscape, and Opera began delivering the
goods,” while many readers still used browsers, “like Netscape 4, that date
back to 1997,” which read style sheets but “bungle it so badly” that A List
Apart turned its styles off for them.
His case was “the separation of style from content.”
In 2003, the CSS Zen Garden made it a demonstration: one page, many designers’
style sheets, and “the code remains the same, the only thing that has changed
is the external .css file.”
So for a few years, a page that had to look right in the browsers people
had was written with tables and <font>, on every element, in every page.
Writing that by hand was tedious, and a WYSIWYG editor wrote it for you, but
filled it with what I called, in my README, “junk line breaks and font
information.”
A macro in a template wrote it for me, from tags that said what things were,
and I could restyle a site by editing the template and recompiling.
In the README, I also wrote that “SWL is perfect for use with CSS,” and my
standard template has both: a style sheet for the font, and a table seven
hundred pixels wide for the layout.
SWL lived on both sides of that change.
In March 2004, John Gruber released Markdown, “a text-to-HTML formatting tool” for web writers, also in Perl, and also a plain-text format that compiled to HTML. Its goal was that a document “should be publishable as-is, as plain text, without looking like it’s been marked up with tags or formatting instructions.”
What took its place #
Style sheets took the presentation.
A semantic tag became a class on an element, and the typography and colors
moved into one file that the browser applied, with no compiler and no
recompiling.
That is the orthogonality the macros were for, done by the browser.
What a style sheet cannot do is change the markup: a macro could turn lines
into a definition list or a table, and replace the colon on each line with
the tags around a speaker’s name.
Style sheets came closer with generated content, but the structure still
has to be in the HTML.
Markdown took the writing.
Its paragraphs are separated by blank lines, its lists and headings look like
lists and headings in an email, and it reads well before it is compiled,
which SWL, with its t> and />, did not quite.
It was also shared.
Gruber’s release worked as a plug-in for the blog engines Movable Type and
Blosxom, and as a filter for a text editor.
In SWL’s documentation, I counted the users of the version before it:
“me, my friend, and my imaginary goldfish.”
What Markdown does not have is definitions.
There is no way to make a new tag in a Markdown document, nor to set a
variable, and it has no calendars and no definition lists.
The macros went somewhere else: into the template languages of static site generators, which came back around to compiling a site once and serving the files. This page is Markdown, compiled into a Nunjucks template and dressed by a style sheet. That is SWL’s arrangement, in three languages instead of one.
Sources #
- SWL 2.10: kriskowal/swl,
its README,
doc/,lib/std.swlt,lib/swl_doc.swlt, and the revision history at the head ofswl.pm. - Ask a Wizard, my blog, in SWL: kriskowal/blog,
with the macros
chat(2006-09-11),argument(2007-01-23) anddefs(2008-03-24), and its template. - Cascading Style Sheets, level 1, W3C Recommendation, 17 December 1996.
- HTML 4.01, § 15.2.2, Font modifier elements, W3C Recommendation, 24 December 1999.
- Jeffrey Zeldman, To Hell With Bad Browsers, A List Apart 99, 16 February 2001.
- css Zen Garden, as of October 2003.
- John Gruber, Introducing Markdown, 15 March 2004, and the Markdown project page, for Markdown 1.0.1, 17 December 2004.
- Previous: AOL Lamp
- Next: Blizzard Resume