on c19bc7a help sign in
626 lines 16 kB history raw
1:- :~ navhome/'/docs/'
2 sort/'5'
3 next/'true'
4 title/'Udon'
5 ==
6;>
8# Udon: A Guide
10### What is Udon?
12Udon is a way to write content for the web. It's a minimalist
13markup language for creating and rendering text documents, with a
14Markdown-inspired syntax. It's integrated with our Hoon programming language,
15allowing it to be used as standalone prose in its own file or embedded inside a
16Hoon source file, in which case it will be parsed into a tree of HTML nodes
17using Hoon's XML-templating syntax, Sail.
19This document is itself written in Udon, and its source file is of the
20Udon `.udon` extension. As such, we use some `formatted text` to make
21it clear what is and isn't code, and to display that code to you instead of
22actually using its semantics for formatting.
24There are quite a few similarities between Udon and the
25CommonMark standard, but there are enough differences that you shouldn't rely on
26existing knowledge of the latter. Udon generally supports only one
27syntax for each type of HTML node it emits. Udon is also stricter than
28Markdown: some syntax errors will prevent the file from being parsed at all.
30We provide a few simple examples [here](#examples) of how to publish
31Udon files using our web interface.
34### Getting Started
36Before starting, make sure that your urbit is
37[mounted to Unix](https://urbit.org/docs/using/setup/)
39To host Udon and other kinds of files, your ship also has a
40web-server, called [Eyre](https://urbit.org/docs/using/web/), that can be found
41at `http://localhost:8080/` if it’s your first ship that’s running on the
42machine, `http://localhost:8081/` if it’s the second ship on that same machine,
43and so on. If you can't find your ship on one of these for some reason, try the
44next one. When a ship starts, it will print a message like
45`http: live (insecure, public) on 8081` to let you know what port it's using.
47That server has access to source files located in `/<your-urbit>/home/web` and
48any sub-folders thereof (except for `/home/web/pages`, which has special
49rendering rules.) Your ship's `%home` desk is served by default. You can
50[change](https://urbit.org/docs/using/web/) which desk you're serving, however.
52Everything in the `/<your-urbit>/home/web/` directory, with the exception of
53`/home/web/pages`, knows how to interpret and files of `.udon` type. So, to
54experiment with UM, create a `.udon` file in that path, and then try to access it
55at `http://localhost:8080/<yourfile>` in your browser -- no `.udon` required in
56the URL. It's a good idea to copy-paste the following examples into your file to
57see how the code works.
59Make sure that you have proper syntax throughout, and check often that it
60renders properly as you add more code. If you have parser-breaking syntax, then
61the default renderer won't tell you much.
63## Syntax
65### Front Matter
67The first thing on your file is a chunk of code called the front matter. It
68contains metadata about your page, such as date, title, and position relative
69to sibling pages.
71As an example, let's look at the front matter of this very page:
73```
74:- :~ navhome/'/docs/'
75 sort/'11'
76 title/'Udon'
77 ==
78;>
79```
81What's going on here?
83`:-`, the Hoon rune for creating a cell, creates a cell composed of
84the `:~` Hoon rune for creating a list, and `;>`, which is a Sail rune
85for Udon.
87`:~` creates a list out of the three elements: `navhome/'/docs/'`, which
88indicates that navigating "home" will bring you to the urbit.org/docs section
89of the website; `sort/'28',` which assigns it the 28th position of the
90immediate section that contains it, the one you see in the sidebar;
91and `title/'Udon'`, which gives the page its title. The `==` digraph
92terminates the list.
94`;>` is a Sail rune that creates a node that contains everything that follows
95it, telling the parser that that text should be interpreted as Udon.
96It's not technically front matter, but you'll always find it following the
97front matter, since all Udon must come after this rune.
99The categories listed in the example above -- `navhome`, `sort`, and `title` --
100make sense to Eyre by default, but any arbitrary category can be used. The code
101below is valid front matter.
103```
104:- :~ date/~2018.9.12
105 author/~lodleb-ritrul
106 music/'rad'
107 ==
108```
110Note that `~2018.9.12`, `~lodleb-ritrul`, and `'rad'` are all of of atom
111types: `@da`(date), `@p` (ship name), and `@t` (cord), respectively. Only atom
112types work here. Having `music/"rad"` would prevent the source file from
113parsing.
115### Headers
117Headers in Udon begin the line with one or more `#` characters,
118'followed by a single space. After that space comes the actual text to be
119displayed. The number of leading `#`s corresponds to the resulting HTML
120header-size element: `#` yields an `<h1>`, `##` yields an `<h2>`, and so on,
121through `<h6>`. The header for this section is `### Headers`.
123*Example:*
124```
125#### Header (h4)
127##### Header (h5)
128```
129###### Produces:
131#### Header (h4)
133##### Header (h5)
135### Italics and Bold
137Enclosing text with `_` will cause that text to appear italicized, using an <i>
138element.
140Enclosing text with `*` will cause that text to appear bolded, using a <b>
141element.
144*Example:*
146```
147To get their *attention*, you need that _je ne sais quoi_.
148```
150###### Produces:
152To get their *attention*, you need that _je ne sais quoi_.
154### Line Break
156After a blank link is interpreted as a line break, creating a distinct
157paragraph. However, a newline on its own is merely interpreted as a space on
158the _same line_.
160*Example:*
162```
163Here's the first line.
165This second line is separated by two newlines, so it's a separate paragraph.
167This line looks like a distinct paragraph, but...
168It's only separated by a single newline, so it's included in the same paragraph.
169```
170###### Produces:
173Here's the first line.
175This second line is separated by two newlines, so it's a separate paragraph.
177This line looks like a distinct paragraph, but...
178It's only separated by a single newline, so it's included in the same paragraph.
180#### Backslash Line Break
182A backslash at the end of a line inserts a line break (`<br>`)
183after that line. This contrasts with the normal udon behavior of
184converting newlines to spaces.
186*Example:*
187```
188I wonder how long each line
189will be if I put backslashes\
190at the ends of the lines.
191```
192###### Produces:
194I wonder how long each line
195will be if I put backslashes\
196at the ends of the lines.
198### Escape
200A backslash directly _before_ a word (with no spaces) will be interpreted
201as an escape character, causing it to be rendered raw.
203*Example:*
205```
206Here is some *bold* text.
207Here is some \*not bold* text.
208```
210###### Produces:
212Here is some *bold* text.
213Here is some \*not bold* text.
216### List
218A line beginning with a `-` followed by a space is interpreted as an
219element of an *unordered list* (`<ul>`). Each line in an unordered list is
220prepended with a bullet point.
222A line beginning with a `+` followed by a space is interpreted as an element
223of an *ordered list* (`<ol>`). Each line in an ordered list is prepended with
224a number corresponding to its position in that list.
226New list elements are delineated by newlines beginning with list symbols of
227the appropriate type (`-` or `+`).
229Just as with non-list text, text on a bare newline will appear on line before,
230separated by a space. A `\\` is used to create a line-break that isn't the list
231itself and isn't a list. Both of these kinds of newlines must be indented by two
232spaces, or else the page will not parse.
234Indentation is also used for creating nested sub-lists. Sub-lists of one kind
235can be used with parent lists of the other kind. Sub-lists can't be nested
236directly after either kind of aforementioned newline that isn't a list element;
237only lines that are themselves list elements can nest sub-lists.
239A newline after a blank line is interpreted as a new paragraph in normal text.
240Between to list elements, however, a blank line is semantically equivalent to
241a bare newline. To separate two lists with blank space, create a blank line
242followed by a `\\` on its own line.
244*Example:*
246```
247- Eggs
248 (cage-free)
249- Milk
250- Butter
251- Chicken\
252 Make sure that you get enough for the barbecue
253- Bread
254 + Ask the baker what's fresh
255 + Buy the second-freshest batch
256- Cereal
259+ First, separate eggs into a bowl.
260+ Then, add a splash of cream.
261 - If you don't have cream, you can use milk, but cream is preferred.
262 + If you don't have milk or cream, melt an eighth of a stick of butter on
263 a skillet
264 + Scrambled the eggs in the bowl.
265 + Pour the eggs onto the skillet before the butter browns
266+ Heat the skillet
268+ Scramble eggs and put them into skillet
271+ Cool
272+ Alright
273```
275Produces
277- Eggs
278 (cage-free)
279- Milk
280- Butter
281- Chicken\
282 Make sure that you get enough for the barbecue
283- Bread
284 + Ask the baker what's fresh
285 + Buy the second-freshest batch
286- Cereal
289+ First, separate eggs into a bowl.
290+ Then, add a splash of cream.
291 - If you don't have cream, you can use milk, but cream is preferred.
292 + If you don't have milk or cream, melt an eighth of a stick of butter on
293 a skillet
294 + Scrambled the eggs in the bowl.
295 + Pour the eggs onto the skillet before the butter browns
296+ Heat the skillet
298+ Scramble eggs and put them into skillet
301+ Cool
302+ Alright
304### Link
306There are two ways to create links, but both contain the text be hyperlinked
307in `[]` followed by the destination in `()`.
309The first type is an inline-style link, which simply uses the full URL as its
310destination.
312*Example:*
314```
315[I'm an inline-style link](https://www.urbit.org/docs/hoon/library)
316```
318###### Produces:
320[I'm an inline-style link](https://www.urbit.org/docs/hoon/library)
322The second type is a reference-style link, which uses a relative path, based on
323the current page's location. Instead of the full url, we use `..` to fill in
324the all of the URL that the destination has in common with the origin page.
326*Example:*
328```
329[I'm a reference-style link](../library)
330```
332###### Produces:
334[I'm a reference-style link](../library)
336If this page is located at `https://www.urbit.org/docs/hoon/`, then these two
337examples should have the same destination.
339#### Anchor Link
341A link to a section of the same page is in the style of
342`[text to be linked](#the-destination)`.
344The destination for the anchor link is designated with the HTML element `id`,
345so we need to use some [Sail](#sail). If there are two or more anchors with
346the same `id` on the page, you will arrive at the earliest instance of the the
347anchor.
349###### Example:
351```
352Check out this [section](#the-destination) that we want to jump to.
354Four score and seven years ago....
356It was the best of times, it was the worst of times...
358;=
359 ;h2
360 ;div(id "the-destination"): Here we are!
361 ==
362==
363```
365###### Produces
367Check out this [section](#the-destination) that we want to jump to.
369Four score and seven years ago....
371It was the best of times, it was the worst of times...
373;=
374 ;h2
375 ;div(id "the-destination"): Here we are!
376 ==
377==
379### Double Quote
381Text enclosed in double quotes (`"`) will be rendered with
382opening and closing quotes -- that is, `“` and `”`.
384*Example:*
385```
386"Yes," he said. "That is the way with him."
387```
389###### Produces:
391"Yes," he said. "That is the way with him."
394### Code Literal
396There are two ways to show the literal text of code without running it: inline
397and block. Both highlight the contained text in another color.
399Note that the backslash, due to its role as the escape character, can only be
400displayed in a code block literal and not as inline code literal. This is a
401bug.
403```
405```
407##### Inline Code Literal
409Enclosing some text in
410```
412```
413characters will cause it to be displayed as code,
414inside a `<code>` HTML element with monospace font and highlighted with a
415different background color.
417Using `` ` \`` is useful when you want to designated only part of a line as code.
418Since this page is written in Udon, we've been using this operation
419throughout this guide to `format text` to distinguish code from prose.
421*Example:*
422```
423`*[a 2 b c] -> *[*[a b] *[a c]]` is like lisp's `apply`.
424```
425###### Produces:
427`*[a 2 b c] -> *[*[a b] *[a c]]` is like lisp's `apply`.
429Also, using the `++` prefix before a word will cause the word to be rendered as
430code with the `++` displayed, since that's the standard notation for an arm in
431Hoon.
433*Example:*
435```
436The ++add arm is used to sum two numbers.
437```
439###### Produces:
441The ++add arm is used to sum two numbers.
443#### Block Code Literal
445By enclosing a block of text in ``` on their own lines
446before and after the contained text, the text will be treated as a code block.
448Most of our examples so far have used.
450*Example:*
453```
454 ```
455 (def Y (fn [f]
456 ((fn [x]
457 (x x))
458 (fn [x]
459 (f (fn [y]
460 ((x x) y)))))))
461 ```
462```
464###### Produces:
466```
467(def Y (fn [f]
468 ((fn [x]
469 (x x))
470 (fn [x]
471 (f (fn [y]
472 ((x x) y)))))))
473```
475### Hoon Constants
477Hoon has several syntactic forms for literals (numbers, strings, dates, etc.)
478that can be used in udon as well. Udon detects such code, and so these
479forms will automatically appear inside a `<code>` element like inline code.
481Example:
483```
484~2017.8.29 \
4850xdead.beef \
486%term
487```
489produces:\
491~2017.8.29 \
4920xdead.beef \
493%term
496### Horizontal Rule
498Three or more hyphens, such as `---`, on their own line produce an `<hr>`
499element, the 'horizontal rule'. This is rendered as a horizontal line the
500width of its containing paragraph.
502###### Example:
504```
505Above the line
506---
507Below the line
508-----
509And below this line, too
510```
512###### Produces:
515Above the line
516---
517Below the line
518-----
519And below this line, too
521### Block Quote
523A section of text with the first line beginning with `>` and a space,
524and each successive newline indented by two spaces yields a
525`<blockquote>` HTML element. This block quote can itself contain more Udon,
526including more block quotes to render nested levels of quotation.
527Inline italicization with `_` does not work, however.
529Blank newlines do not end the block quote, but a blank newline followed by an
530unindented line of text _will_ end the quote.
532*Example:*
534```
535> As Gregor Samsa awoke one morning from uneasy dreams, he
536 found himself transformed in his bed into a *monstrous* vermin.
538Quote break.
540> _See_ the child.
542 He is pale and thin, he wears a thin and ragged linen shirt.
543```
545###### Produces:
547> As Gregor Samsa awoke one morning from uneasy dreams
548 he found himself transformed in his bed into a *monstrous* vermin.
550Quote break.
552> _See_ the child.
554 He is pale and thin, he wears a thin and ragged linen shirt.
557### Poem
559A poem is a section of text with meaningful newlines. Recall that,
560normally in Udon, newlines are treated as spaces and do not create a
561new line of text. If you want to embed text where newlines are retained, then
562indent the text in question with *eight spaces*.
564###### Example:
566```
567 A shape with lion body and the head of a man,
568 A gaze blank and pitiless as the sun,
569 Is moving its slow thighs, while all about it
570 Reel shadows of the indignant desert birds.
571```
572###### Produces:
574 A shape with lion body and the head of a man,
575 A gaze blank and pitiless as the sun,
576 Is moving its slow thighs, while all about it
577 Reel shadows of the indignant desert birds.
580;=
581 ;h2
582 ;div(id "sail"): Sail Expressions
583 ==
584==
586It's possible to use Udon as an HTML templating language akin to
587PHP, ERB, JSP, or Handlebars templates. This facility derives
588in part from the support for embedding Hoon code inside the markup.
591You can Sail is a domain-specific language within Hoon for creating XML nodes,
592including HTML. It can be used directly within Udon to provide
593scripting capability with Hoon and also to provide more precise control over the
594resulting HTML. The [Sail guide](../sail) is a good place to learn the
595specifics.
597Example:
599```
600;=
601 ;p
602 ;strong: Don't panic!
603 ;br;
604 ;small: [reactive publishing intensifies]
605 ==
606==
607```
609Produces:
612;=
613 ;p
614 ;strong: Don't panic!
615 ;br;
616 ;small: [reactive publishing intensifies]
617 ==
618==
619;h2
620 ;div(id "examples"): Examples
621==
623We've created a few simple examples of how to get set up publishing content from
624your Urbit. Feel free to ask questions in the comments.
626;list;