Wordscript Versus HTML

HTML is a popular text markup language. This article discusses how Wordscript compares to HTML. There is nothing HTML can do that Wordscript cannot do with less verbosity, clearer readability, and greater extensibility.

Similiarities

Elements

Both languages involve marking up text with elements. Elements have opening markers, closing markers, and tagnames.

Attributes

Both languages support applying attributes to elements and text.

Namespace

Both languages support namespaces for elements and attributes.

Whitespace

Both languages normalize whitespace, making the layout of text and elements up to the designer without affecting rendering.

Well Formed and Valid

Both languages produce an abstract syntact tree (AST) that can be well-formed. If well-formed, the document may or not be valid.

Differences

Structure

  • The HTML Document Object Model (DOM) considers text nodes to be a different type of node than element nodes. Attributes are also a completely different type.
  • HTML requires a top level HTML element, and has a head and body element.
  • In HTML, structure needs to be nested.
  • In Wordscript, text can contain attributes and attributes can contain text
  • Wordscript has scopes that can inherit other scopes, and be reused.
  • Wordscript is a list of elements. They can be text (dialogue), attribute, or other. There is no document, head, or body element.
  • Wordscripts top level structure is an array of elements (a fragment). This makes it very easy to combine documents.
  • In Wordscript, an empty document is a valid file, that being a Script Fragment with no elements.
  • In Wordscript, all elements are self closing but can contain other elements, including text and attribute elements.
  • Worscript uses nested scopes, and scopes do not need to be physical elements such as divs or spans.

    Attributes

  • HTML assumes all elements can have attributes.
  • HTML attributes are declared in the element start tag, and apply to the entire element.
  • In Wordscript, content is defined by the tag provider. Attributes can be defined anywhere.

    Text

  • Wordscript includes a dedicated whitespace element. HTML only has a &nbsp entity.

    Elements

    HTML uses heading tag names that include the level. Wordscript gets the level from a parameter. Wordscript can use dynamic parameters to increment and decrement the level.

<h1>Heading 1</h1>
<h2>Heading 2</h2>
[[h 1 Heading 1]]
[[h + Heading 2]]
[[h = Also Heading 2]]

Style

  • HTML uses styles, but Wordscript uses expressions. In Wordscript, style refers to how and where expressions are used and interpreted, and not to the expression values.

Escaping

  • HTML has special characters must be escaped using entities.
  • Wordscript uses pairs of characters, only the [[ ]] and \\. For the most part, no escaping is ever needed, unless the author is trying to use Wordscript as text and not script. And in that case, a special tag exists to avoid needing to escape.

Examples

HTML

<span style="color:red;">
  Hello
</span>
<span style="color:blue;">
  Strange
</span>
<span style="color:red;">
  World
</span>
<span style="color:red;">
  Hello
  <span style="color:blue;">
  Strange
</span>
World
</span>

Wordscript

An attribute element with no content will be applied to all text in the current scope that follows. Unlike HTML, attributes can be changed within the scope. This avoids nesting.

[[@ color:red;]]
Hello
[[@ color:blue;]]
Strange
[[@ color:red;]]
World

This example clearly show how clear and terse Wordscript is.

[[@ color:red;]]
Hello
[[@ color:blue; [[ Strange ]] ]]
World

All content in an attribute element is expression by default. Dialogue is added using the explicit text element.

[[@ color:red; ]]
[[ This is red ]]
This is red too.

A text element can be place within the attribute. When an attribute has text elements in the content, the attribute is only applied to its content, and not the surrounding scope.

[[@ color:red;
  [[ This is red ]]
]]
This is not red.