-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathspecification.gain
666 lines (496 loc) · 14.9 KB
/
specification.gain
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
base: http://gaintext.org/doc/gaintext-lang/specification.gain
vocab: TBD
title: GainText specification
author: Martin Waitz <tali@admingilde.org>
chapter: GainText specification
===============================
Document structure
~~~~~~~~~~~~~~~~~~
Paragraphs
----------
Normal text can be written without paying attention to line breaks.
Consecutive lines are joined into one paragraph.
One or several blank lines can be used to separate paragraphs.
It is recommended to add a line break at the end of each sentence,
as that makes it easier to edit the document without having
to reformat too many lines.
Named elements
--------------
Elements add structure to the document.
They are used to describe what is being written.
example:
`````
section: title of the section
`````
This defines a new section of the document, with the given title.
The name of an element may consist of several words.
However, the name is not free but has to be defined by the used template.
The first word of the name selects if and which additional information can be used within the element name.
example:
`````
abbreviation CPU: Central Processing Unit.
abbreviation OS: Operating System.
`````
Common first words of an element name may be written on one line, with the rest indented on the following lines.
example:
`````
abbreviation
CPU: Central Processing Unit.
OS: Operating System.
`````
Only previously defined element names (e.g. by a template) are recognized.
All other names simply represent normal text.
Elements are only recognized when they start a new block.
TBD: and only allow elements in this block.
example:
`````
location: Berlin
location: New York
`````
This defines two elements (given a definition for element name "location"), while the following is parsed as one text paragraph:
`````
We meet in the following
location: central station, Nuremberg.
`````
If normal text would be misinterpreted as an element, it can be escaped by enclosing it in `~`.
example:
`````
~location:~ is rendered as normal text.
`````
As a convention, GainText element names start with a lowercase character and are therefor less likely
to conflict with the start of a text paragraph.
Attributes
----------
Elements may contain attributes.
These can either be put next to the element name (before the colon)
or within braces at the end of the line.
example:
`````
section #id .class attr=value: title of the section
`````
`````
section: title of the section {#id .class attr=value}
`````
this is an abbreviation for:
`````
section: title of the section
id: id
class: class
key: value
`````
TBD:
Some attributes are added implicitly.
Having an ID for every section of the document would be important, for example.
But adding this to every element might be overkill and generating a good ID for all elements might not be easy.
Maybe whis would simply be solved by offloading this to the element definition (implementing a genID function for sections)?
Maybe don't explain attributes here at all and concentrate on the semantic structure.
Element definitions could then generate attributes automatically, based on RDF properties.
The *title* has to be handled by the element definition, too.
Simple elements may use it as the element content, while section-like elements will put it into its own `<title>` tag.
Move down!
Indentation
-----------
Elements can also contain content.
Everything which is indented further than the element is considered to be content of the element.
example:
`````
example:
This is an example.
This is the second paragraph of the example.
`````
The text after the element definition usually contains some title or identifier
while the indented lines afterwards define the actual contents.
example:
`````
section: This is the title of the section
This is a paragraph within the section.
And another.
`````
Indentation can be used to define a hierarchical structure.
The indented content of an element can contain new elements.
Those also belong to the content of the parent element.
They may be used to further describe that element or to
restrict the scope of the inner element.
example:
`````
requirement: #req-id
The example shall be understandable.
rationale:
Otherwise it is futile.
test: #test-id
Ask a new user if he understands the example.
verifies: [#req-id]
`````
TBD: Syntax for links?
example:
`````
TBD hierarchical structure
`````
`````
TBD scoped elements
`````
Indentation can also be used to introduce elements without any introduction line.
When text is indented at least four spaces or one tab, then it is considered
to be a verbatim (code) block.
example:
`````
Normal Text within one paragraph.
Text which is indented at least four spaces or one tab
will be rendered as a code block.
`````
TBD: make type of created indent element configurable?
TBD: is default-to-code enough when we can map elements in a context-sensitive way?
A line which is indented one to three spaces starts a new paragraph.
example:
`````
Normal Text within one paragraph.
Text which is indented one to three spaces against the base indent
will start a new block (paragraph or element context).
* list item in a new block
* second list item in the same new block
`````
Structure from headers
----------------------
Tree structure can also be specified by providing headers on different levels.
example:
``````
element: level 1
================
content on level 1
element: level 2
----------------
content on level 1
``````
When defining sections, the "section:" part can also be omitted.
example:
``````
section: new section
--------------------
text paragraph.
``````
is parsed the same as:
``````
new section
-----------
text paragraph.
``````
Each indentation level has it's own set of header markers.
example:
`````
section: level1
+++++++++++++++
section: level2
section: level3
----------------
section: level4
+++++++++++++++
# Q: do we actually allow to mix both header styles within one level?
# A: Yes we do, because we want to support other indented elements here, too.
section: level2
---------------
`````
Shortcuts
---------
Some commonly used elements have shortcuts so that they can be created easier.
Lists can be introduced with the characters `*`, `+`, and `-`:
example:
`````
TODO:
* first item
* and another
- subitem 1
- subitem 2
* last item
`````
Multiple levels can be created by indentation.
If the list immediately follows a line of normal text,
than it has to be indented by one to three spaces to be
recognized.
We recommend to consistently indent the first level by one space.
Numbered lists can be created like this:
example:
``````
1. first item
2. and another
a) subitem 1
b) subitem 2
3. last item
``````
Each numbered item can be introduced by an optional open brace,
a number and an closing brace or symbol.
E.g. `(1)`, `b.`, `iii`, `[IV]`, and `<5>` are all valid number
schemes.
Element content can be enclosed by marker lines.
example:
`````
Verbatim code block:
```
int main(int argc, char **argv) {
printf("Hello, world.");
return 0;
}
```
`````
Indentation can also be used to define an implicit code section.
Any block indented with at least four spaces or one tab is taken as a "Code" element.
Additional indentation is taken verbatim as indentation within the code block.
example:
`````
Hello world program:
int main(int argc, char **argv) {
printf("Hello world.");
return 0;
}
`````
This is parsed identical to the previous example.
Lines starting with `>` form block quotes.
example:
`````
> Just like quoted lines in email,
> the text after the `>` quote characters
> is concatenated from following lines.
>> This is a blockquote within another.
`````
Lines starting with `//` are comments which will not be part of the document
example:
`````
// comment, no markup will be parsed here
`````
Text markup
~~~~~~~~~~~
A span of text can be attributed:
example:
`````
Text with [em:emphasis] or [strong:strong emphasis].
[style color=red: [em: red emphasis]]
`````
The markup is always enclosed in a matching pair of brackets (`[]`),
the text content comes after a colon (`:`), everything before the colon is used to attribute this text.
Links
-----
example:
`````
Please visit our [link http://example.com/: Homepage].
A link to another part of the document [link #id] or to another document [link doc.gain].
Adding a link to some text: [link doc.gain: some text].
Link to a website (containing a colon in the URL): [link "http://www.example.com/"].
TBD: require colon + white-space to separate URL + Title?
`````
Images and figures
------------------
example:
`````
inline image:
[image a.png]
[image a.png title="title": alternative text]
[image a.png: alternative text {title="title"}]
`````
example:
`````
figure #fig1:
[image fig1.png]
Description of the figure
# TBD: find better syntax?
`````
Mathematics
-----------
example:
`````
Inline equation ([math: E = m c^2]) using TeX syntax or block mode:
math:
a^2 + b^2 = c^2
`````
Shortcuts
---------
There are several abbreviations:
example:
`````
[[Name of section]] instead of [link #id-of-section: Name of section]
{{template-paramter}} instead of [param: template-parameter]
{{dom-selector}} instead of [select: dom-selector]
http://example.org/ instead of [link "http://exaple.org/"]
info@example.org instead of [mailto:info@example.org]
`pre-formatted code` instead of [code: pre-formatted code]
~raw text, no markup~ instead of [raw: raw text, no markup]
*emphasize* instead of [em: emphasize]
**strong empasize** instead of [strong: strong emphasize]
$a^2 = b^2 + c^2$ instead of [math: a^2 = b^2 + c^2]
`````
example:
`````
```
pre-formatted code
```
instead of
code:
pre-formatted code
`````
These additional special characters are only interpreted when the
opening and closing part are on the same line and must start at the
beginning of a word but must not end at the beginning of a word.
That means that white-space is required in front of the opening part
(the opening part can of course also be at the beginning of the line or
some other element)
but no white-space is allowed directly after it or before the closing part.
example:
`The costs are $5 and $10.` will not trigger math mode
(white-space before the second `$`).
`The balance is between -$10 and -$5.` will also not trigger math mode
(no white-space before the first `$`).
Neither does `The costs are ~10$.` trigger raw or math mode
(only one `~`/`$` on the line).
Such elements can be nested.
example:
`*~**foo**~*` to get emphasis on a word with raw asterisks (*~**foo**~*).
Literate brackets can be inserted by escaping them with [code:~] or `\\`.
example:
`~[~` or `\[` to get a ~[~.
`~]~` or `\]` to get a ~]~.
`[raw:~]` or `\~` to get a single [raw:~].
Escaping with `~` does not work inside a word
(needs whitespace before the leading `~`).
Either escape the whole word or use `\\`.
example:
```
~[not an element]~
\[not an element]
```
Inline HTML
~~~~~~~~~~~
An XML subtree can be embedded verbatim into the document.
It has to start on a line of its own and has to end at the end of a line.
Alternatively, `<span>`, `<b>` and `<em>` elements may be inserted directly into the text.
Inline RDFa
~~~~~~~~~~~
TBD: base on JSON-LD?
example:
`````
@context person:
name:
@id: http://schema.org/name
image:
@id: http://schema.org/image
@type: @id
homepage:
@id: http://schema.org/url
@type: @id
person:
name: Anton
image: http://example.com/anton.jpg
homepage: http://example.com/anton.html
`````
Tables
~~~~~~
TBD
Maybe support different styles for different use cases:
- "visual style" which resembles a rendered table
- "adjacency matrix" style for one data item per line
Visual style is difficult to parse when we want to support all blocks within the cells.
Other styles may be difficult to remember/use for beginners.
example:
A visual style, relying on layout alone.
Looks nice even in source but does not work with proportional fonts.
May be difficult to use in some text editors.
Can be parsed quite easily in a two-stage approach when the first stage just cuts out the cells at fixed positions.
`````
table:
first second
----- ------
a1 b1
a2 b2
`````
A visual style, relying on separator characters.
Can be layouted to look nice in source form, but can also be edited using proportional fonts.
Difficult to parse as the grammar has to understand both the cell separator as well as the contents of the cell at the same time.
(The separator character might be used and escaped by the cell content itself)
`````
table:
heading: first [] second
a1 [] b1
a2 [] b2
`````
A list style, each line as one list.
With row headings represented as element.
`````
table:
- first: a1
second: b1
- first: a2
second: b2
`````
Similar list style, but with shortcut elements for headings.
`````
table:
heading a: first
heading b: second
+ a: a1
b: b1
+ a: a2
b: b2
`````
`````
table:
- [first: a1 ][second: b1 ]
- [first: a2 ][second: b2 ]
`````
`````
table:
heading: first
heading: second
cell first 1: a1
cell B 1: b1
first: a2
second: b2
`````
`````
table:
row:
- a1
- b1
row:
- a2
- b2
`````
`````
table:
column: first
- a1
- a2
column: second
- b1
- b2
`````
Web Component integration
~~~~~~~~~~~~~~~~~~~~~~~~~
Web components should be easy to use in GainText documents.
example:
`````
import: http://example.org/elements/ex-warning.html
ex-warning: severity=low
Don't do *this* at home!
`````
Just like normal GainText elements, only previously registered elements
are recognized.
This means that all HTML imports have to be checked for Web Components.
Macros
~~~~~~
Many template tasks can be solved by using web components.
For simple tasks, a template can also be specified inside GainText.
Use a templating mechanism to generate content.
Select nodes in the AST using XPath or similar.
Have some special elements which can be used to import or process these nodes
Allow to define shortcuts which can be used to generate new content based on a template.
example:
`````
person:
name: Anton
image: http://example.com/anton.jpg
homepage: http://example.com/anton.html
define avatar:
parameter name:
<a href="{{person[name={{name}}].homepage}}">
<img src="{{person[name={{name}}].image}}" alt="{{name}}"/>
{{name}}
</a>
[avatar: name=Anton]
`````