How does a DSML help?
Here’s what I want to write:
This is starting to look like XML, without accidentally becoming XHTML. The joy of my DSML is that I’m writing a language that knows what I mean, not that I want a new layer of quoting rules.
Rewriting Custom Tags into HTML
Let’s start with the easy work, let’s convert the
<steps>
list and the <step>
elements back into <ol>
and <li>
s. I’m using the QueryPath library. It’s a very similar API to jQuery, and because I do the transform server-side, I can provide well-formed pages to clients without JavaScript (like search engine spiders).Adding Application Logic and Error Checking
Of course, nobody’s perfect, so let’s add some rules to catch operator error:
While I’m writing lessons, my
warn()
function adds bold red error messages to the top of the parsed document. In production, warn()
will quietly log them.Tags that are Smarter than HTML
Those were simple replacements, you can do that with a regular expression and some duck tape. Let’s make this
<cli>
tag fix my problems with HTML’s <pre>
:- I want to be able to indent the content for easier editing.
- I want the
</pre>
tag on its own line, without showing the student an empty line at the bottom of the code block.
In other words, I want it to work like this:
But let me edit it like this:
Here’s the code that does it:
DSML my Users Care About
In lessons, when we introduce new terms, the student can hover over them to get a Bootstrap Popover that loads the definition from our glossary, dynamically. Here’s how that used to look in our code:
Here’s how I want it to look:
And here’s how we do it:
Now we get warnings about terms we haven’t written glossary entries for (and we don’t call attention to them, to avoid embarrassment in front of students). Tagging glossary entries is easier (so we’ll do it more). And we’re free to make dramatic changes to the way we present glossary terms without touching a zillion lesson files. For example:
- We could slipstream in all the definitions into data attributes instead of fetching via AJAX.
- We could paste all the definitions as numbered footnotes on the page.
- We could switch the HTML we emit to the browser to use the
<dfn>
tag instead of<abbr>
.
Now go forth, and HTML no more.
HTML is pretty great, but I wouldn’t want to write in it.
- A DSML can get you closer to your problem domain, not just in code, but in presentation.
- A DSML can free you to write content without bogging you down in implementation details.
- A DSML can even make it easier to develop and update features spread across content.
http://www.wingtiplabs.com/blog/posts/2013/03/18/domain-specific-markup-language/
https://docs.google.com/file/d/0B5nZNPW48dpFUTI1Mi1qZWhVVkE/edit?usp=sharing