UNPKG

2.21 kBMarkdownView Raw
1# Concise syntax
2
3Marko's concise syntax is very similar to the HTML syntax, except it's more... concise. Essentially, you take an HTML tag, remove the angle brackets (`<>`) and use indentation rather than a closing tag:
4
5_input.marko_
6
7```marko
8div class="thumbnail"
9 img src="https://example.com/thumb.png"
10```
11
12_output.html_
13
14```html
15<div class="thumbnail"><img src="https://example.com/thumb.png" /></div>
16```
17
18## Shorthand attributes
19
20Marko provides a shorthand for declaring classes and ids on an element:
21
22_input.marko_
23
24```marko
25div.my-class
26span#my-id
27button#submit.primary.large
28```
29
30Yields this HTML:
31
32_output.html_
33
34```html
35<div class="my-class"></div>
36<span id="my-id"></span> <button id="submit" class="primary large"></button>
37```
38
39> **ProTip:** These shorthand attributes are available within the HTML syntax as well
40
41## Text
42
43Text in concise mode is denoted by two or more dashes (`--`).
44
45If there is text on the same line following `--`, it is single-line text:
46
47_single-line-text.marko_
48
49```marko
50-- Hello world
51```
52
53The dashes can also follow an element to give it a single text node as a child
54
55_single-line-text.marko_
56
57```marko
58div -- Hello world
59```
60
61If there is a line break immediately following `--`, everything following the `--` at the current indentation is parsed as multi-line line text.
62
63_multi-line-text.marko_
64
65```marko
66div
67 --
68 Hello world
69 this text
70 is multi-line
71
72div
73 --
74 this is more
75 text
76```
77
78A multi-line text block can be ended by the same number of dashes that opened it. This allows it to have siblings:
79
80_multi-line-text.marko_
81
82```marko
83div
84 img src="https://example.com/photo.png"
85 --
86 Hello world
87 this text
88 is multi-line
89 --
90 span -- text after
91```
92
93### Root level text
94
95There is one "gotcha" that you need to be aware of. The Marko parser starts out in the concise mode. Therefore, given the following template:
96
97_input.marko_
98
99```marko
100Hello World
101Welcome to Marko
102```
103
104The output would be the following:
105
106_output.html_
107
108```html
109<Hello World></Hello> <Welcome to Marko></Welcome>
110```
111
112Instead, prefix the lines with `--` so they are parsed as text:
113
114_input.marko_
115
116```marko
117-- Hello World
118-- Welcome to Marko
119```