nmd-core 1.0.1

Official NMD compiler core
Documentation
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
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
> [!WARNING]
> NMD syntax is working in progress yet, you can contribute following [contribution guidelines]CONTRIBUTING.md!  

- [Structure]#structure
    - [Dossier]#dossier
      - [Dossier configuration]#dossier-configuration
        - [name]#name
        - [toc]#toc
        - [documents]#documents
        - [style]#style
        - [references]#references
        - [bibliography]#bibliography
        - [compilation]#compilation
- [NMD Syntax]#nmd-syntax
  - [Heading (Title of a chapter)]#heading-title-of-a-chapter
    - [Compact heading]#compact-heading
    - [Relative heading]#relative-heading
    - [Annotations]#annotations
  - [Inline modifier]#inline-modifier
    - [Escape]#escape
    - [Metadata \[NOT SUPPORTED YET\]]#metadata-not-supported-yet
    - [Reference]#reference
    - [Bold]#bold
    - [Italic]#italic
    - [Strikethrough]#strikethrough
    - [Underlined]#underlined
    - [Checkbox]#checkbox
    - [Color, Highlight and Font]#color-highlight-and-font
      - [Compatible highlight text]#compatible-highlight-text
    - [Embedded style]#embedded-style
    - [Identifier]#identifier
    - [Emoji]#emoji
    - [Superscript]#superscript
    - [Subscript]#subscript
    - [Link]#link
    - [Inline code]#inline-code
    - [Inline math]#inline-math
    - [Inline comments]#inline-comments
    - [Greek letters]#greek-letters
    - [Bookmark]#bookmark
      - [Abridged bookmark]#abridged-bookmark
      - [Bookmark]#bookmark-1
      - [Todo]#todo
    - [Cite]#cite
  - [Paragraph modifier]#paragraph-modifier
    - [Embedded style]#embedded-style-1
    - [Image]#image
      - [Abridged Image]#abridged-image
      - [Multi Image]#multi-image
    - [Page break]#page-break
    - [Line break]#line-break
    - [List]#list
    - [Code block]#code-block
    - [Multiline comments \[TO BE DEFINE; NOT SUPPORTED YET\]]#multiline-comments-to-be-define-not-supported-yet
    - [Focus block]#focus-block
      - [Focus quote block]#focus-quote-block
    - [Math block (LaTeX)]#math-block-latex
    - [Chapter styles and metadata \[TO BE DEFINE; NOT SUPPORTED YET\]]#chapter-styles-and-metadata-to-be-define-not-supported-yet
    - [Tables \[NOT SUPPORTED YET\]]#tables-not-supported-yet



## Structure

There are several type of ways to write NMD.

The structure hierarchy is the following:

1. **Dossier**: structured project
2. **Document**: single NMD file having `.nmd` extension
3. **Chapter**: actual NMD text, it is identified by the heading and it has some paragraph
4. **Paragraph**: actual NMD text, it is the text block in a chapter. Each paragraph is separated by each other by two new lines (`\n\n`)

![Structure](./docs/assets/images/nmd-strucutre-sets.png)

#### Dossier

A **dossier** is a structured project having one or more *NMD documents*.

It allows to manage a set of related NMD documents and their assets.

> **Asset** is a resource used in a document, e.g. an image, or a custom *style*. 

A dossier allows to write the content in different NMD files and than union them in a single output.

The actual structure of a dossier is the following:

- `assets/`
  - `images/`
  - `documents/`
  - `styles/`
  - ...
- `nmd.yml` or `nmd.json` called **dossier configuration**
- set of NMD document (having `.nmd` extension)

The `images/` directory contains... images! Such as `documents` which contains documents and `styles/` which contains custom style for dossier.

The custom style must be written in **CSS**. The CSS classes are specified in each following *modifier section*.

##### Dossier configuration

The **dossier configuration** is a YAML or JSON file which contains configuration parameters for the dossier.

Considering YAML version, it may have the following content:

```yaml
name: New Dossier

toc:
  include_in_output: false
  page_numbers: false
  plain: false
  maximum_heading_level: 4

documents:
- ./welcome.nmd

style:
  theme: Light
  styles: []
  list_bullets_configuration: []

references: {}

bibliography:
  title: Bibliography
  records: {}
  include_in_output: false

compilation:
  embed_local_image: true
  embed_remote_image: true
  compress_embed_image: true
  strict_image_src_check: true
  parallelization: true
  use_remote_addons: false
```

###### name

`name` is the name of dossier.

###### toc

`include_in_output` if it must be printed

`page_numbers`: if it must be had page numbers

`tabulated` if it must contains tabulations

`maximum_heading_level` maximum heading level which must be printed

To customize table of contents there are some classes: `toc`, `toc-title`, `toc-body`, `toc-item`, `toc-item-bullet`, `toc-item-content`, `toc-item-indentation`

###### documents

`documents` is a list where are specified the order of the documents in the final output.

###### style

`style` section has the *style configuration*.

`theme` specified the theme used to create output. It can be:

- `Light` (default)
- `Dark`
- `Vintage` is work in progress now 

`styles` refers to CSS files. They can be URLs or local files (if only file name is used, it is inferred `assets/styles/` as prefix) 

`list_bullets_configuration` is described in [list section](#list)

###### references

`references` allows to specify dossier variables.


###### bibliography

Each bibliography record has:

- `title` (**mandatory**)
- `year`
- `authors`
- `description`
- `url`

Style classes: `bibliography`, `bibliography-title`, `bibliography-body`, `bibliography-item`, `bibliography-item-title`, `bibliography-item-authors`, `bibliography-item-year`, `bibliography-item-url`

For example:

```
bibliography:
  title: Bibliography
  records: 
    bib1:
      title: "bib1"
    bib2:
      title: "bib1"
      authors:
        - A1
        - A2
        - A3
      year: 2024
    bib3:
      title: "bib1"
      description: "bib3 description"
  include_in_output: true
```


###### compilation

In `compilation` section you can specified the default values to use during compilation.

- `embed_local_image` (boolean): local images (specified by local path) are inserted in the output without reference, but embedded 
- `embed_remote_image` (boolean): remote images (specified by remote path, e.g. URL) are inserted in the output without reference, but embedded 
- `compress_embed_image` (boolean): compress embedded images
- `strict_image_src_check` (boolean): apply a strict check to image sources
- `parallelization` (boolean): if `true` parallelize execution of compilation
- `use_remote_addons` (boolean): if `true` use CDN instead of local CSS/Javascript to include third part library








## NMD Syntax

NMD syntax is based on [CommonMark](https://commonmark.org/), but add new concepts and modifiers.

> A **modifier** is a special combination of symbols which allows to modify the text style.

In the next section there are all modifiers of NMD.

### Heading (Title of a chapter)

**Style class**: `heading-#` (where `#` is the heading number, e.g. `heading-3`)

Create headings using `#` (up to 6 levels). `#` must be separated from text using a blank space ` `.

```markdown
# Heading 1

## Heading 2

...

###### Heading 6
```

#### Compact heading

It's possible to use this alternative format:

```
#1 Heading 1

#2 Heading 2

...

#6 Heading 6
```

#### Relative heading

It's possible to use this alternative format to refer previous heading level:

- `#-` $= \text{last heading level} - 1$
- `#+` $= \text{last heading level} + 1$
- `#=` $= \text{last heading level}$

For example:

```
#1 Heading 1

#+ Heading 2

#+ Heading 3

#- Heading 2

#= Heading 2
```

#### Annotations

```
@key value1;value2
```

- `id`
- `author`
- `date` of creation
- `intent`
- `style` (inline style, e.g. `color:red`)
- `styleclass` (style class, e.g. `bold-txt`)




### Inline modifier

TODO

#### Escape

You can prevent text modification using **escape**, i.e. `\`:

```
\*
\_
...
```

#### Metadata [NOT SUPPORTED YET]

**Metadata** are a set of data which gives information about document, project and so on.

The syntax is:

```
TBD
```

#### Reference

**Reference** is a... reference! You can use a fictitious name as a classic variable in the programming languages.

References must be set in dossier configuration (`nmd.json` or `nmd.yml`).

The syntax is below.

```
&reference&
```

#### Bold

**Style class**: `bold`

```markdown
**Bold**

or

__Bold__
```

#### Italic

**Style class**: `italic`

```markdown
_Italic_

or

*Italic*
```

#### Strikethrough

**Style class**: `strikethrough`

```
~~Strikethrough text~~
```

#### Underlined

**Style class**: `underlined`

```
++Underlined text++
```

#### Checkbox

**Style class**: `checkbox`, `checkbox-unchecked`, `checkbox-checked`

```
[x] or [x]
[] or [ ]
```


#### Color, Highlight and Font

**Style class**: `abridged-embedded-style`

Color can be written in hexadecimal if you use `#rrggbb` convention or you can use their names.

You can modify text color, text background and its font using this modifier:

```
[Custom colored text]#id{textColor;backgroundColor;fontName}
```

You can omit `id`.

You can omit font and background color if you want only modify text color.

```
[Only text color]{#rrggbb}
```

You can insert only background color or only text font using this convention:

```
[Only background]{;#rrggbb}
[Only font]{;;fontName}
```

##### Compatible highlight text

**Style class**: `highlight`

You can use also `==Highlight text==` to mark text. This uses the default highlight style.

#### Embedded style

**Style class**: `embedded-style`

```
[Custom text style]{{style}}
```

`style` is literally the css-like style to apply.

#### Identifier

**Style class**: `identifier`

You can mark with an identifier a piece of text using:

```
[Text]#the-id
```

You can combine identifier modifier with embedded style:

```
[Text]#the-id{textColor;backgroundColor;fontName}
[Text]#the-id{{style}}
```

#### Emoji

Two ways to add emoji:

- Copy and paste an emoji
- Using `:emojiCode:`, for example 🐫


#### Superscript

```
1^st^
```

> This modifier can be placed attached on other text.

#### Subscript

For example, if you want to write "water" in a more scientific way:

```
H~2~O
```

Pay attention, those are two single quote

> This modifier can be placed attached on other text.

#### Link

**Style class**: `link`

```markdown
[Link](http://https://github.com/nricciardi/nmd.com)
```

#### Inline code

**Style class**: `inline-code`

```markdown
`inline code`
```

#### Inline math

**Style class**: `inline-math`

```markdown
$inline math$
```

#### Inline comments

```
// this is a comment
```

#### Greek letters

**Style class**: `greek`

```
%a%

%b%

%athb%
...
```

```rust
HashMap::from([
    ("a", r"alpha"),
    ("b", r"beta"),
    ("g", r"gamma"),
    ("d", r"delta"),
    ("e", r"epsilon"),
    ("z", r"zeta"),
    ("n", r"eta"),
    ("th", r"theta"),
    ("i", r"iota"),
    ("k", r"kappa"),
    ("l", r"lambda"),
    ("m", r"mu"),
    ("nu", r"nu"),
    ("x", r"xi"),
    ("o", r"omicron"),
    ("p", r"pi"),
    ("r", r"rho"),
    ("s", r"sigma"),
    ("t", r"tau"),
    ("u", r"upsilon"),
    ("phi", r"phi"),
    ("chi", r"chi"),
    ("psi", r"psi"),
    ("w", r"omega"),

    ("A", r"Alpha"),
    ("B", r"Beta"),
    ("G", r"Gamma"),
    ("D", r"Delta"),
    ("E", r"Epsilon"),
    ("Z", r"Zeta"),
    ("N", r"Eta"),
    ("Th", r"Theta"),
    ("I", r"Iota"),
    ("K", r"Kappa"),
    ("L", r"Lambda"),
    ("M", r"Mu"),
    ("Nu", r"Nu"),
    ("X", r"Xi"),
    ("O", r"Omicron"),
    ("P", r"Pi"),
    ("R", r"Rho"),
    ("S", r"Sigma"),
    ("T", r"Tau"),
    ("U", r"Upsilon"),
    ("Phi", r"Phi"),
    ("Chi", r"Chi"),
    ("Psi", r"Psi"),
    ("W", r"Omega"),
])
```

#### Bookmark

**Bookmarks** are label which can be inserted in text body to mark a paragraph or a piece of paragraph.

##### Abridged bookmark

**Style class**: `abridged-bookmark`, `abridged-bookmark-title`

```
@[bookmark description]
@[bookmark description]#the-id
```

Description can be multi-lines.


##### Bookmark

**Style class**: `bookmark`, `bookmark-title`, `bookmark-description`

```
@[bookmark title](bookmark description)
@[bookmark title]#the-id(bookmark description)
```

##### Todo

**Style class**: `todo`, `todo-title`, `todo-description`, `abridged-todo`, `multiline-todo`

Todo is a special tag to insert... TODOs

```
@[TODO](description)
@[todo](description)
```

...or only as first characters of the line (*abridged todo*):

```
TODO: description
todo: description
```

*Multiline* todo:

```
TODO:
this is a multiline todo
:TODO
```

> **Abridged and multiline todo** are paragraphs.

#### Cite

**Style class**: `cite`

```
some text^[bibliography-key]
```




### Paragraph modifier

#### Embedded style

**Style class**: `embedded-paragraph-style`

```
[[Custom text
style]]{{style}}
```

`style` is literally the css-like style or class (with `.` before) to apply.

#### Image

**Style class**: `figure`, `image`, `image-caption`

```markdown
![Image](http://url/a.png)

![Image]#id(http://url/a.png)

![Image]#id(http://url/a.png){{maring:0;width:50vw}}
```

##### Abridged Image

**Style class**: `figure`, `image`, `abridged-image`

```markdown
![(http://url/a.png)]

![(http://url/a.png)]#id

![(http://url/a.png)]#id{{maring:0;width:50vw}}
```

##### Multi Image

**Style class**: `figure`, `image`, `image-caption`, `abridged-image`, `images-container`, `image-container`

```
!!:space-between:[[
:center:![(wikipedia-logo.png)]#image-7{{width:70%}}
![Wikipedia](./assets/images/wikipedia-logo.png){{width:45%;margin:0;}}
]]
```

#### Page break

**Style class**: `page-break`

```
### or more #
```

#### Line break

**Style class**: `line-break`, `line-break-dash`, `line-break-star`, `line-break-plus`

To apply a line break use `---` (or more than 3 `-`) or `***` (or more than 3 `*`) or `+++` (or more than 3 `+`) in a new blank line.

#### List

**Style class**: `list`, `list-item`, `list-item-indentation`, `list-item-bullet`, `list-item-content` 

> Each list must have 2 or more items.

Different types of list are supported in NMD, below the list with modifier

- `-` default style bullet
- `*` full dot bullet
- `+` empty dot bullet
- `->` arrow bullet
- `--` dash bullet
- `|` to use more than one line in an item content
- `-[] or -[ ] or - [] or - [ ]` todo bullet
- `1. or 1) or a. or a) or I. or I)` ordered bullet (numerical, alphabetical, romans numbers)
- `&unicode;` UNICODE bullet

Using `tabs` or `   ` (3 spaces) you can create different list levels.

Style of first and second bullet types can be managed using the configuration file.

Actually, the behavior of bullets can be modified using [dossier configuration](#dossier-configuration). In particular, using `list_bullets_configuration`.

For each record, you must specified 4 fields:

- `from` (string): NMD bullet
- `to` (string): output bullet (`:checkbox:` or `:checkbox-checked:` to show *checkbox* bullets)
- `indentation_level` (number)
- `strict_indentation` (boolean): if `false` the actual rule use `>=` instead of `==` to check indentation

> The rules are checked in order.

Following an example:

```yaml
  list_bullets_configuration:
  - from: '|'
    to: '‍'
    indentation_level: 0
    strict_indentation: false
  - from: '-'
    to: '•'
    indentation_level: 0
    strict_indentation: true
  - from: '-'
    to: '◦'
    indentation_level: 1
    strict_indentation: true
  - from: '-'
    to: '–'
    indentation_level: 2
    strict_indentation: false
  - from: '*'
    to: '•'
    indentation_level: 0
    strict_indentation: false
  - from: +
    to: '◦'
    indentation_level: 0
    strict_indentation: false
```

#### Code block

**Style class**: `code-block`

Code blocks use ``` as paragraph modifier.

It's possible to specify the language used in code block, as in CommonMark, writing language name after first three quotes.

NMD uses [PrimJS](https://prismjs.com/) to render code blocks. So, the supported languages (tag in parenthesis) are the same of that library:

- Python (python)
- Java (java)
- Javascript (javascript)
- PHP (php)
- HTML (html)
- CSS (css)
- Typescript (typescript)
- Kotlin (kotlin)
- ...

#### Multiline comments [TO BE DEFINE; NOT SUPPORTED YET]

```
/*
multi
line
comment
*/
```

#### Focus block

**Style class**: `focus-block`, `focus-block-<type>`, `focus-block-title`, `focus-block-<type>-title`, `focus-block-description`, `focus-block-<type>-description` (replace `type`)

Focus blocks allow to insert text in particular paragraph in which the text is highlighted.

There are many types of focus block:

- **quote**
- **note**
- **tip**
- **important**
- **warning**
- **caution**

The syntax is below.

```
::: warning
Watch out!!!
:::
```

##### Focus quote block

**Style class**: `focus-quote-block`, `focus-quote-block-type`, `focus-quote-block-title`, `focus-quote-block-type-title`, `focus-quote-block-description`, `focus-quote-block-type-description` (replace `type`)

```
> [!note]
> note...
```

> **Only** for `[!type]` pattern you can write `type` in uppercase (`TYPE`).

#### Math block (LaTeX)

**Style class**: `math-block`

Math block is a particular paragraph used to print mathematical formulas and more.

The paragraph modifier for math block is double $, i.e. `$$` to open and close blocks.

NMD uses [Katex](https://katex.org/) to render math blocks.


#### Chapter styles and metadata [TO BE DEFINE; NOT SUPPORTED YET]

In NMD each paragraph can be decorated with a set of **paragraph decorators**, i.e. **metadata**, **in-line styles** and **style classes**. 

There is a set of standard and custom styles which each indicates a particular style. These are guide lines, each editor could implement a standard style in different ways.

Metadata are introduced using `@`:

```
@ + metadata tag + single space + metadata content
```

Supported metadata:

- `author`
- `content` description of paragraph content
- `createdAt`
- `updatedAt`

A special metadata is the **id** which can be written in two alternatives ways:

```
#the-id
@id the-id
```

> the identifiers should be all in lowercase and each word should be separated using `-`.

Style classes are introduced using `.`, e.g. `.styleClass1`.

In-line styles use CSS (or SCSS/SASS based on editor) key-value modifiers, they haven't a symbol.

To add decorators to a paragraph you must insert `{}` in the line below title, in parenthesis each type of decorator has a particular symbol which introduces it. You can use `;` to separate decorator in the same line or a `\n` to insert decorator in multiple lines.

There is an example below.

```
## Foo title
{
    #the-id
    @author you
    @author yourFriend
    .styleClass1
    background-color: red
}
```

You can add decorators also to a single word using this syntax:

#### Tables [NOT SUPPORTED YET]

**Style class**: `table`, `table-header`, `table-header-row`, `table-body`, `table-footer`, `table-body-row`, `table-cell`, `table-left-cell`, `table-center-cell`, `table-right-cell`, `table-empty-cell`, `table-caption`

Each table has an table head, body and footer (like HTML tables). A table can have only head or only footer, but it must always have body.

**Standard syntax**:

```
| Syntax      | Description | Test Text     |
| :---        |    :----:   |          ---: |
| Header      | Title       | Here's this   |
| Paragraph   | Text        | And more      |
```

`:---` for column left alignment

`---:` for column right alignment

`:---:` for column center alignment


**Extended syntax**

```
| Syntax     :| Description |: Test Text   :|
| :---        |    :----:   |          ---: |
| Header     :| Title       | Here's this   |
| Paragraph   | Text       :| And more      |
|---|
|| Footer     |
[Caption]#table-id{{style}}
```

`:` to specify cell alignment

`:---` for column left alignment

`---:` for column right alignment

`:---:` for column center alignment