Everyone knows HTML, but new programmers are often intimidated by JavaScript and its code-looking syntax. Unfortunately, HTML does not have scripting abilities of its own. Until now!
npm install htmsEveryone knows HTML, but new programmers are often intimidated by JavaScript and
its code-looking syntax. Unfortunately, HTML does not have scripting abilities
of its own. Until now!
HyperText Markup Script provides a way to express computations using just HTML.
It even provides full interoperability with JavaScript code for a smooth
transition when you feel ready to use a "real" language.
1. Include the htms.min.js script on the page
2. Create your root element
3. Write your code!
The formal syntax of the language is exactly the same as HTML, though the tags
have slightly different meanings.
####
The root HTMS node defines where to start running your HTMS code. All exported
values will be placed in a global JavaScript object with the name given by thename attribute. (i.e. some_name, or window.some_name).
The final value of the node is automatically exported with the namedefault.
``html`
####
Provides no special purpose other than to execute its children in order. It can
be used to turn variables into strings and numbers (see and ).`html`
####
Assigns the final value of its children to the variable given by the name
attribute. This variable can then be referenced later by its name.
Note that there are a few built in identifiers which cannot be used as variable
names, namely true, false, and $_. These correspond to the Boolean true
and false values, and the "previous value".
$_ is often used internally, and so you should not need to reference it, but$_
you can. always holds the value of the previously executed node in the$_
current block. When no nodes have yet been run in the current block, the value
of is null. This is the only way to obtain the null value, which may be
useful at times.
`htmlHello world
string
`
####
Turns its final value into a string. If it is a text node, the text is used
literally. Otherwise, it is the return value of evaluating the final element.
`html`
3Hello world
x
x
####
Similar to but for numbers.
`html`5
3
x
x
####
Similar to but for Booleans.
`html`0
3
0
false
true false
x
x
####
Negates its final value as a Boolean. Note that this is an operator, and not a
type constructor, so untyped values are evaluated as variables automatically and
do not require being nested in a .
`html`
falsetrue 3 false x x
Produces the sum of all the elements in its final value, which must be an array
of numbers or strings. With strings, it performs concatenation.
####
Similar to , but performs subtraction. Does not work on strings.`html`
####
Similar to
, but performs division.
`html
- 10
- 2
- 5
`####
Similar to
, but performs multiplication.
`html
- 10
- 2
- 5
`####
Raises
$_ to the power of its final value. Both must be numbers.`html
32
`####
Performs a less than comparison between
$_ and its final value.`html
35
53
`####
Performs an equality comparison between
$_ and its final value. Types of both
arguments must be the same for this to evaluate to true.`html
33
53
`####
Creates an array, where each array element is the final value of each
`html
- 3
Hi
- 5
`####
Creates a dictionary where each key, denoted by
, corresponds to the value
of the following . The children of must start with and then
alternate `html
first_name
John
last_name
Smith
age
- 15
`####
Perform the subscript operation to extract the values of an array or object. The
final value of the
is the key to extract.`html
first_name
John
last_name
Smith
age
- 15
objfirst_name
- 3
Hi
- 5
arr1
`####
Defines a function. User-defined functions can take only one argument. If you
need more arguments, consider currying or passing an array or dictionary
instead.
The contents of the
tag define the body of the function. To
reference the argument, use the variable argument. The final value is used as
the return value.The function can be later referenced by its name, given by the name attribute.
`html
`####
Performs a function call, passing its final value to the function referred to
by the previous value (
$_). This node evaluates to the return value of the
function.`html
hello world
fnhello world
`####