-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathlowdown.3
1165 lines (1165 loc) · 25.6 KB
/
lowdown.3
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
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
.\" Copyright (c) Kristaps Dzonsons <kristaps@bsd.lv>
.\"
.\" Permission to use, copy, modify, and distribute this software for any
.\" purpose with or without fee is hereby granted, provided that the above
.\" copyright notice and this permission notice appear in all copies.
.\"
.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
.Dd $Mdocdate$
.Dt LOWDOWN 3
.Os
.Sh NAME
.Nm lowdown
.Nd simple markdown translator library
.Sh LIBRARY
.Lb liblowdown
.Sh SYNOPSIS
.In sys/queue.h
.In stdio.h
.In lowdown.h
.Vt "struct lowdown_meta"
.Vt "struct lowdown_node"
.Vt "struct lowdown_opts"
.Sh DESCRIPTION
This library parses
.Xr lowdown 5
into various output formats.
.Pp
The library consists first of a high-level interface consisting of
.Xr lowdown_buf 3 ,
.Xr lowdown_buf_diff 3 ,
.Xr lowdown_file 3 ,
and
.Xr lowdown_file_diff 3 .
.Pp
The high-level functions interface with low-level functions that perform
parsing and formatting.
These consist of
.Xr lowdown_doc_new 3 ,
.Xr lowdown_doc_parse 3 ,
and
.Xr lowdown_doc_free 3
for parsing
.Xr lowdown 5
documents into an abstract syntax tree.
.Pp
The front-end functions for freeing, allocation, and rendering are as
follows.
.Bl -bullet
.It
HTML5:
.Bl -item -compact
.It
.Xr lowdown_html_free 3
.It
.Xr lowdown_html_new 3
.It
.Xr lowdown_html_rndr 3
.El
.It
gemini:
.Bl -item -compact
.It
.Xr lowdown_gemini_free 3
.It
.Xr lowdown_gemini_new 3
.It
.Xr lowdown_gemini_rndr 3
.El
.It
LaTeX:
.Bl -item -compact
.It
.Xr lowdown_latex_free 3
.It
.Xr lowdown_latex_new 3
.It
.Xr lowdown_latex_rndr 3
.El
.It
OpenDocument:
.Bl -item -compact
.It
.Xr lowdown_odt_free 3
.It
.Xr lowdown_odt_new 3
.It
.Xr lowdown_odt_rndr 3
.El
.It
roff:
.Bl -item -compact
.It
.Xr lowdown_nroff_free 3
.It
.Xr lowdown_nroff_new 3
.It
.Xr lowdown_nroff_rndr 3
.El
.It
UTF-8 ANSI terminal:
.Bl -item -compact
.It
.Xr lowdown_term_free 3
.It
.Xr lowdown_term_new 3
.It
.Xr lowdown_term_rndr 3
.El
.It
debugging:
.Bl -item -compact
.It
.Xr lowdown_tree_rndr 3
.El
.El
.Pp
To compile and link, use
.Xr pkg-config 1 :
.Bd -literal
% cc `pkg-config --cflags lowdown` -c -o sample.o sample.c
% cc -o sample sample.o `pkg-config --libs lowdown`
.Ed
.Ss Pledge Promises
The
.Nm lowdown
library is built to operate in security-sensitive environments, such as
those using
.Xr pledge 2
on
.Ox .
The only promise required is
.Va stdio
for
.Xr lowdown_file_diff 3
and
.Xr lowdown_file 3 :
both require access to the stream for reading input.
.Sh TYPES
All
.Nm lowdown
functions use one or more of the following structures.
.Pp
The main structure for configuring parsing and output is
.Vt struct lowdown_opts .
It has the following fields:
.Bl -tag -width Ds
.It Va enum lowdown_type type
The output medium:
.Pp
.Bl -tag -width Ds -compact
.It Dv LOWDOWN_HTML
HTML5
.It Dv LOWDOWN_LATEX
LaTeX
.It Dv LOWDOWN_MAN
roff
.Fl m Ns Ar an
macros
.It Dv LOWDOWN_FODT
.Dq flat
OpenDocument
.It Dv LOWDOWN_TERM
ANSI-compatible UTF-8 terminal output
.It Dv LOWDOWN_GEMINI
Gemini format
.It Dv LOWDOWN_NROFF
roff
.Fl m Ns Ar s
macros
.It Dv LOWDOWN_TREE
syntax tree (debugging)
.El
.It Va unsigned int feat
Parse-time features.
This bit-field may have the following bits OR'd:
.Pp
.Bl -tag -width Ds -compact
.It Dv LOWDOWN_ATTRS
Parse PHP extra link, header, and image attributes.
.It Dv LOWDOWN_AUTOLINK
Parse
.Li http ,
.Li https ,
.Li ftp ,
.Li mailto ,
and relative links or link fragments.
.It Dv LOWDOWN_CALLOUTS
Parse MDN/GFM callouts
.Pq Dq admonitions .
.It Dv LOWDOWN_COMMONMARK
Tighten input parsing to the CommonMark specification.
This also uses the first ordered list value instead of starting all
lists at one.
This feature is
.Em experimental
and
.Em incomplete .
.It Dv LOWDOWN_DEFLIST
Parse PHP extra definition lists.
This is currently constrained to single-key lists.
.It Dv LOWDOWN_FENCED
Parse GFM fenced (language-specific) code blocks.
.It Dv LOWDOWN_FOOTNOTES
Parse MMD style footnotes.
This only supports the referenced footnote style, not the
.Dq inline
style.
.It Dv LOWDOWN_HILITE
Parse highlit sequences.
This are disabled by default because it may be erroneously interpreted
as section headers.
.It Dv LOWDOWN_IMG_EXT
Deprecated.
Use
.Dv LOWDOWN_ATTRS
instead.
.It Dv LOWDOWN_MANTITLE
Recognise manpage titles in Pandoc metadata title lines.
Only applicable if
.Dv LOWDOWN_METADATA
is also provided.
Manpages titles must begin with a non-empty title followed by an open
parenthesis, digit or
.Dq n ,
optional letters after, then a closing parenthesis.
This may be optionally followed by a source and, if a vertical bar is
detected, the content after as the volume.
These are passed to the renderers as the
.Li title ,
.Li volume ,
and optionally
.Li source
and
.Li volume
metadata key-value pairs.
The original title is not recoverable.
.It Dv LOWDOWN_MATH
Parse mathematics equations.
.It Dv LOWDOWN_METADATA
Parse in-document metadata.
.It Dv LOWDOWN_NOCODEIND
Do not parse indented content as code blocks.
.It Dv LOWDOWN_NOINTEM
Do not parse emphasis within words.
.It Dv LOWDOWN_STRIKE
Parse strikethrough sequences.
.It Dv LOWDOWN_SUPER
Parse super-scripts.
This accepts foo^bar^ GFM super-scripts.
.It Dv LOWDOWN_SUPER_SHORT
If
.Dv LOWDOWN_SUPER
is enabled, instead of the GFM style, accept the
.Dq short
form of superscript.
This accepts foo^bar, which puts the parts following the caret until
whitespace in superscripts; or foo^(bar), which puts only the parts in
parenthesis.
.It Dv LOWDOWN_TABLES
Parse GFM tables.
.It Dv LOWDOWN_TASKLIST
Parse GFM task list items.
.El
.It Va unsigned int oflags
Output-time features.
Bit values are specific to the
.Va type
and are not guaranteed to be globally unique.
.Pp
For all types:
.Pp
.Bl -tag -width Ds -compact
.It Dv LOWDOWN_SMARTY
Don't use smart typography formatting.
.It Dv LOWDOWN_STANDALONE
Emit a full document instead of a document fragment.
This envelope is largely populated from metadata if
.Dv LOWDOWN_METADATA
was provided as an option or as given in
.Va meta
or
.Va metaovr .
.El
.Pp
For
.Dv LOWDOWN_HTML :
.Pp
.Bl -tag -width Ds -compact
.It Dv LOWDOWN_HTML_CALLOUT_MDN , LOWDOWN_HTML_CALLOUT_GFM
Output MDN and/or GFM-style callout syntax.
.It Dv LOWDOWN_HTML_ESCAPE
If
.Dv LOWDOWN_HTML_SKIP_HTML
has not been set, escapes in-document HTML so that it is rendered as
opaque text.
.It Dv LOWDOWN_HTML_HARD_WRAP
Retain line-breaks within paragraphs.
.It Dv LOWDOWN_HTML_HEAD_IDS
Have an identifier written with each header element consisting of an
HTML-escaped version of the header contents.
.It Dv LOWDOWN_HTML_NUM_ENT
Convert, when possible, HTML entities to their numeric form.
If not set, the entities are used as given in the input.
.It Dv LOWDOWN_HTML_OWASP
When escaping text, be extra paranoid in following the OWASP suggestions
for which characters to escape.
.It Dv LOWDOWN_HTML_SKIP_HTML
Do not render in-document HTML at all.
.It Dv LOWDOWN_HTML_TITLEBLOCK
If used with
.Dv LOWDOWN_STANDALONE ,
output a Pandoc-style title block.
This is a
.Li <header id="title-block-header">
element right after the opening
.Li <body>
containing elements for specified title, author(s), and date.
These are
.Li <h1>
and
.Li <p>
elements, respectively, with classes set to what's being output (title,
etc.).
At least one of these must be specified for the title block to be
output.
.El
.Pp
For
.Dv LOWDOWN_GEMINI ,
there are several flags for controlling link placement.
By default, links (images, autolinks, and links) are queued when
specified in-line then emitted in a block sequence after the nearest
block node.
(See
.Sx ABSTRACT SYNTAX TREE . )
.Pp
.Bl -tag -width Ds -compact
.It Dv LOWDOWN_GEMINI_LINK_END
Emit the queue of links at the end of the document instead of after the
nearest block node.
.It Dv LOWDOWN_GEMINI_LINK_IN
Render all links within the flow of text.
This will cause breakage when nested links, such as images within links,
links in blockquotes, etc.
It should not be used unless in carefully crafted documents.
.It Dv LOWDOWN_GEMINI_LINK_NOREF
Do not format link labels.
Takes precedence over
.Dv LOWDOWN_GEMINI_LINK_ROMAN .
.It Dv LOWDOWN_GEMINI_LINK_ROMAN
When formatting link labels, use lower-case Roman numerals instead of
the default lowercase hexavigesimal (i.e.,
.Dq a ,
.Dq b ,
\&...,
.Dq aa ,
.Dq ab ,
\&...).
.It Dv LOWDOWN_GEMINI_METADATA
Print metadata as the canonicalised key followed by a colon then the
value, each on one line (newlines replaced by spaces).
The metadata block is terminated by a double newline.
If there is no metadata, this does nothing.
.El
.Pp
There may only be one of
.Dv LOWDOWN_GEMINI_LINK_END
or
.Dv LOWDOWN_GEMINI_LINK_IN .
If both are specified, the latter is unset.
.Pp
For
.Dv LOWDOWN_FODT :
.Pp
.Bl -tag -width Ds -compact
.It Dv LOWDOWN_ODT_SKIP_HTML
Do not render in-document HTML at all.
Text within HTML elements remains.
.El
.Pp
For
.Dv LOWDOWN_LATEX :
.Pp
.Bl -tag -width Ds -compact
.It Dv LOWDOWN_LATEX_NUMBERED
Use the default numbering scheme for sections, subsections, etc.
If not specified, these are inhibited.
.It Dv LOWDOWN_LATEX_SKIP_HTML
Do not render in-document HTML at all.
Text within HTML elements remains.
.El
.Pp
For
.Dv LOWDOWN_MAN
and
.Dv LOWDOWN_NROFF :
.Pp
.Bl -tag -width Ds -compact
.It Dv LOWDOWN_NROFF_GROFF
Use GNU extensions (i.e., for
.Xr groff 1 )
when rendering output.
The groff arguments must include
.Fl m Ns Ar pdfmark
for formatting links with
.Dv LOWDOWN_MAN
or
.Fl m Ns Ar spdf
instead of
.Fl m Ns Ar s
for
.Dv LOWDOWN_NROFF .
Applies to the
.Dv LOWDOWN_MAN
and
.Dv LOWDOWN_NROFF
output types.
.It Dv LOWDOWN_NROFF_NOLINK
Don't show links at all if they have embedded text.
Applies to images and regular links.
Only in
.Dv LOWDOWN_MAN
or when
.Dv LOWDOWN_NROFF_GROFF
is not specified.
.It Dv LOWDOWN_NROFF_NUMBERED
Use numbered sections if
.Dv LOWDOWON_NROFF_GROFF
is not specified.
Only applies to the
.Dv LOWDOWN_NROFF
output type.
.It Dv LOWDOWN_NROFF_SHORTLINK
Render link URLs in short form.
Applies to images, autolinks, and regular links.
Only in
.Dv LOWDOWN_MAN
or when
.Dv LOWDOWN_NROFF_GROFF
is not specified.
.It Dv LOWDOWN_NROFF_SKIP_HTML
Do not render in-document HTML at all.
Text within HTML elements remains.
.El
.Pp
For
.Dv LOWDOWN_TERM :
.Pp
.Bl -tag -width Ds -compact
.It Dv LOWDOWN_TERM_ALL_META
If
.Dv LOWDOWN_STANDALONE
is specified, output all metadata instead of just the title, author, and
date.
.It Dv LOWDOWN_TERM_NOANSI
Don't apply ANSI style codes at all.
This implies
.Dv LOWDOWN_TERM_NOCOLOUR .
.It Dv LOWDOWN_TERM_NOCOLOUR
Don't apply ANSI colour codes.
This will still show underline, bold, etc.
This should not be used in difference mode, as the output will make no
sense.
.It Dv LOWDOWN_TERM_NOLINK
Don't show links at all.
Applies to images and regular links: autolinks are still shown.
This may be combined with
.Dv LOWDOWN_TERM_SHORTLINK
to also shorten autolinks.
.It Dv LOWDOWN_TERM_SHORTLINK
Render link URLs in short form.
Applies to images, autolinks, and regular links.
This may be combined with
.Dv LOWDOWN_TERM_NOLINK
to only show shortened autolinks.
.El
.It Va size_t maxdepth
The maximum parse depth before the parser exits.
Most documents will have a parse depth in the single digits.
.It Va size_t cols
For
.Dv LOWDOWN_TERM ,
the
.Dq soft limit
for width of terminal output not including margins.
If zero, 80 shall be used.
.It Va size_t hmargin
For
.Dv LOWDOWN_TERM ,
the left margin (space characters).
.It Va size_t vmargin
For
.Dv LOWDOWN_TERM ,
the top/bottom margin (newlines).
.It Va struct lowdown_opts_nroff nroff
If
.Va type
is
.Dv LOWDOWN_MAN
or
.Dv LOWDOWN_NROFF ,
this contains constant-width font variants:
.Vt "const char *cr"
for roman constant-width,
.Vt "const char *cb"
for bold,
.Vt "const char *ci"
for italic, and
.Vt "const char *cbi"
for bold-italic.
If any of these are
.Dv NULL ,
they default to their constant-width variants.
.It Va struct lowdown_opts_odt odt
If
.Va type
is
.Dv LOWDOWN_FODT ,
this contains
.Vt "const char *sty" ,
which is either
.Dv NULL
or the OpenDocument styles used when creating standalone documents.
If
.Dv NULL ,
the default styles are used.
.It Va char **meta
An array of metadata key-value pairs or
.Dv NULL .
Each pair must appear as if provided on one line (or multiple lines) of
the input, including the terminating newline character.
If not consisting of a valid pair (e.g., no newline, no colon), then it is
ignored.
When processed, these values are overridden by those in the document (if
.Dv LOWDOWN_METADATA
is specified) or by those in
.Va metaovr .
.It Va size_t metasz
Number of pairs in
.Va metaovr .
.It Va char **metaovr
See
.Va meta .
The difference is that
.Va metaovr
is applied after
.Va meta
and in-document metadata, so it overrides prior values.
.It Va size_t metaovrsz
Number of pairs in
.Va metaovr .
.El
.Pp
Parsed metadata is held in key-value
.Vt "struct lowdown_meta"
pairs, or collectively as
.Va "struct lowdown_metaq" ,
if
.Dv LOWDOWN_METADATA
is set in
.Va feat .
The former structure consists of the following fields:
.Bl -tag -width Ds
.It Va char *key
The metadata key in its canonical form: lowercase alphanumerics, hyphen, and
underscore.
Whitespace is removed and other characters replaced by a question mark.
.It Va char *value
The metadata value.
This may be an empty string.
.El
.Pp
The abstract syntax tree is encoded in
.Vt struct lowdown_node ,
which consists of the following.
.Bl -tag -width Ds
.It Va enum lowdown_rndrt type
The node type, using HTML5 output as an illustration:
.Pp
.Bl -tag -width Ds -compact
.It Dv LOWDOWN_BLOCKCODE
A block-level snippet of code described by
.Li <pre><code> .
.It Dv LOWDOWN_BLOCKHTML
A block-level snippet of HTML.
This is simply opaque HTML content.
.It Dv LOWDOWN_BLOCKQUOTE
A block-level quotation described by
.Li <blockquote> .
.It Dv LOWDOWN_CODESPAN
An inline-level snippet of code described by
.Li <code> .
.It Dv LOWDOWN_DEFINITION
A definition list described by
.Li <dl> .
.It Dv LOWDOWN_DEFINITION_DATA
Definition data described by
.Li <dd> .
.It Dv LOWDOWN_DEFINITION_TITLE
Definition title described by
.Li <dt> .
.It Dv LOWDOWN_DOC_HEADER
Container for metadata described by
.Li <head> .
.It Dv LOWDOWN_DOUBLE_EMPHASIS
Bold (or otherwise notable) content described by
.Li <strong> .
.It Dv LOWDOWN_EMPHASIS
Italic (or otherwise notable) content described by
.Li <em> .
.It Dv LOWDOWN_ENTITY
Named or numeric HTML entity.
.It Dv LOWDOWN_FOOTNOTE
Footnote content.
.It Dv LOWDOWN_HEADER
A block-level header described by one of
.Li <h1>
through
.Li <h6> .
.It Dv LOWDOWN_HIGHLIGHT
Marked test described by
.Li <mark> .
.It Dv LOWDOWN_HRULE
A horizontal line described by
.Li <hr> .
.It Dv LOWDOWN_IMAGE
An image described by
.Li <img> .
.It Dv LOWDOWN_LINEBREAK
A hard line-break within a block context described by
.Li <br> .
.It Dv LOWDOWN_LINK
A link to external media described by
.Li <a> .
.It Dv LOWDOWN_LINK_AUTO
Like
.Dv LOWDOWN_LINK ,
except inferred from text content.
.It Dv LOWDOWN_LIST
A list enclosure described by
.Li <ul>
or
.Li <ol> .
.It Dv LOWDOWN_LISTITEM
A list item described by
.Li <li> .
.It Dv LOWDOWN_MATH_BLOCK
A snippet of mathematical text in LaTeX format described within
.Li \e[xx\e]
or
.Li \e(xx\e) .
This is usually (in HTML) externally handled by a JavaScript renderer.
.It Dv LOWDOWN_META
Meta-data keys and values.
These are described by elements in
.Li <head> .
.It Dv LOWDOWN_NORMAL_TEXT
Normal text content.
.It Dv LOWDOWN_PARAGRAPH
A block-level paragraph described by
.Li <p> .
.It Dv LOWDOWN_RAW_HTML
An inline of raw HTML.
(Only if configured during parse.)
.It Dv LOWDOWN_ROOT
The root of the document.
This is always the topmost node, and the only node where the
.Va parent
field is
.Dv NULL .
.It Dv LOWDOWN_STRIKETHROUGH
Content struck through.
Described by
.Li <del> .
.It Dv LOWDOWN_SUBSCRIPT , Dv LOWDOWN_SUPERSCRIPT
A subscript or superscript described by
.Li <sub>
or
.Li <sup> ,
respectively.
.It Dv LOWDOWN_TABLE_BLOCK
A table block described by
.Li <table> .
.It Dv LOWDOWN_TABLE_BODY
A table body section described by
.Li <tbody> .
.It Dv LOWDOWN_TABLE_CELL
A table cell described by
.Li <td> ,
or
.Li <th>
if in the header.
.It Dv LOWDOWN_TABLE_HEADER
A table header section described by
.Li <thead> .
.It Dv LOWDOWN_TABLE_ROW
A table row described by
.Li <tr> .
.It Dv LOWDOWN_TRIPLE_EMPHASIS
Combination of
.Dv LOWDOWN_EMPHASIS
and
.Dv LOWDOWN_DOUBLE_EMPHASIS .
.El
.It Va size_t id
An identifier unique within the document.
This can be used as a table index since the number is assigned from a
monotonically increasing point during the parse.
.It Va struct lowdown_node *parent
The parent of the node, or
.Dv NULL
at the root.
.It Va enum lowdown_chng chng
Change tracking: whether this node was inserted
.Pq Dv LOWDOWN_CHNG_INSERT ,
deleted
.Pq Dv LOWDOWN_CHNG_DELETE ,
or neither
.Pq Dv LOWDOWN_CHNG_NONE .
.It Va struct lowdown_nodeq children
A possibly-empty list of child nodes.
.It Va <anon union>
An anonymous union of type-specific structures.
.Pp
.Bl -tag -width Ds -compact
.It Va rndr_autolink
For
.Dv LOWDOWN_LINK_AUTO ,
the link address as
.Va link
and the link type
.Va type ,
which may be one of
.Dv HALINK_EMAIL
for e-mail links and
.Dv HALINK_NORMAL
otherwise.
Any buffer may be empty-sized.
.It Va rndr_blockcode
For
.Dv LOWDOWN_BLOCKCODE ,
the opaque
.Va text
of the block and the optional
.Va lang
of the code language.
.It Va rndr_blockhtml
For
.Dv LOWDOWN_BLOCKHTML ,
the opaque HTML
.Va text .
.It Va rndr_codespan
The opaque
.Va text
of the contents.
.It Va rndr_definition
For
.Dv LOWDOWN_DEFINITION ,
containing
.Va flags
that may be
.Dv HLIST_FL_BLOCK
if the definition list should be interpreted as containing block
nodes.
.It Va rndr_entity
For
.Dv LOWDOWN_ENTITY ,
the entity
.Va text .
.It Va rndr_header
For
.Dv LOWDOWN_HEADER ,
the
.Va level
of the header starting at zero (this value is relative to the metadata
base header level, defaulting to one), optional space-separated class
list
.Va attr_cls ,
and optional single identifier
.Va attr_id .
.It Va rndr_image
For
.Dv LOWDOWN_IMAGE ,
the image address
.Va link ,
the image title
.Va title ,
dimensions NxN (width by height) in
.Va dims ,
and alternate text
.Va alt .
CSS in-line style for width and height may be given in
.Va attr_width
and/or
.Va attr_height ,
and a space-separated list of classes may be in
.Va attr_cls
and a single identifier may be in
.Va attr_id .
.It Va rndr_link
Like
.Va rndr_autolink ,
but without a type and further defining an optional link title
.Va title ,
optional space-separated class list
.Va attr_cls ,
and optional single identifier
.Va attr_id .
.It Va rndr_list
For
.Dv LOWDOWN_LIST ,
consists of a bitfield
.Va flags
that may be set to
.Dv HLIST_FL_ORDERED
for an ordered list and
.Dv HLIST_FL_UNORDERED
for an unordered one.
If
.Dv HLIST_FL_BLOCK
is set, the list should be output as if items were separate blocks.
The
.Va start
value for
.Dv HLIST_FL_ORDERED
is the starting list item position, which is one by default and never
zero.
The
.Va items
is the number of list items.
.It Va rndr_listitem
For
.Dv LOWDOWN_LISTITEM ,
consists of a bitfield
.Va flags
that may be set to
.Dv HLIST_FL_ORDERED
for an ordered list,
.Dv HLIST_FL_UNORDERED
for an unordered list,
.Dv HLIST_FL_DEF
for definition list data,
.Dv HLIST_FL_CHECKED
or
.Dv HLIST_FL_UNCHECKED
for an unordered
.Dq task
list, and/or
.Dv HLIST_FL_BLOCK
for list item output as if containing block nodes.
The
.Dv HLIST_FL_BLOCK
should not be used: use the parent list (or definition list) flags for
this.
The
.Va num
is the index in a
.Dv HLIST_FL_ORDERED
list.
It is monotonically increasing with each item in the list, starting at
the
.Va start
variable given in
.Vt struct rndr_list .
.It Va rndr_math
For
.Dv LOWDOWN_MATH ,
the mode of display in
.Va blockmode :
if 1, in-line math; if 2, multi-line.
The opaque equation, which is assumed to be in LaTeX format, is in the
opaque
.Va text .
.It Va rndr_meta
Each
.Dv LOWDOWN_META
key-value pair is represented.
The keys are lower-case without spaces or non-ASCII characters.
If provided, enclosed nodes may consist only of
.Dv LOWDOWN_NORMAL_TEXT
and
.Dv LOWDOWN_ENTITY .
.It Va rndr_normal_text
The basic
.Va text
content for
.Dv LOWDOWN_NORMAL_TEXT .
If
.Va flags
is set to
.Dv HTEXT_ESCAPED ,
the text may be escaped for output, but may not be altered by any smart
typography or similar (it should be passed as-is).
.It Va rndr_paragraph
For
.Dv LOWDOWN_PARAGRAPH ,
species how many
.Va lines
the paragraph has in the input file and
.Va beoln ,
set to non-zero if the paragraph ends with an empty line instead of a
breaking block node.
.It Va rndr_raw_html
For
.Dv LOWDOWN_RAW_HTML ,
the opaque HTML
.Va text .
.It Va rndr_table
For
.Dv LOWDOWN_TABLE_BLOCK ,
the number of
.Va columns
in each row or header row.
The number of columns in
.Va rndr_table ,
.Va rndr_table_header ,
and
.Va rndr_table_cell
are the same.
.It Va rndr_table_cell
For
.Dv LOWDOWN_TABLE_CELL ,
the current
.Va col
column number out of
.Va columns .
See
.Va rndr_table_header
for a description of the bits in
.Va flags .
The number of columns in
.Va rndr_table ,
.Va rndr_table_header ,
and
.Va rndr_table_cell
are the same.
.It Va rndr_table_header
For
.Dv LOWDOWN_TABLE_HEADER ,
the number of
.Va columns
in each row and the per-column
.Va flags ,
which may tested for equality against
.Dv HTBL_FL_ALIGN_LEFT ,
.Dv HTBL_FL_ALIGN_RIGHT ,
or
.Dv HTBL_FL_ALIGN_CENTER
after being masked with
.Dv HTBL_FL_ALIGNMASK ;
or
.Dv HTBL_FL_HEADER .
If no alignment is specified after the mask, the default should be
left-aligned.
The number of columns in
.Va rndr_table ,
.Va rndr_table_header ,
and
.Va rndr_table_cell
are the same.
.El
.El
.Sh ABSTRACT SYNTAX TREE
A parsed document is a tree of
.Vt struct lowdown_node
nodes.
If a node is
.Dq block ,
it may contain other block or inline nodes.
If
.Dq inline,
it may only contain other inline nodes.
.Dq Special
nodes are documented below.
An additional mark of
.Dq void
means that the node will never contain children.
.Pp
.Bl -column "LOWDOWN_DEFINITION_TITLE" "special, void" -offset indent -compact
.It Node Ta Scope
.It Dv LOWDOWN_BLOCKCODE Ta block, void
.It Dv LOWDOWN_BLOCKHTML Ta block, void
.It Dv LOWDOWN_BLOCKQUOTE Ta block
.It Dv LOWDOWN_CODESPAN Ta inline, void
.It Dv LOWDOWN_DEFINITION Ta block
.It Dv LOWDOWN_DEFINITION_DATA Ta special
.It Dv LOWDOWN_DEFINITION_TITLE Ta special
.It Dv LOWDOWN_DOC_HEADER Ta special
.It Dv LOWDOWN_DOUBLE_EMPHASIS Ta inline
.It Dv LOWDOWN_EMPHASIS Ta inline
.It Dv LOWDOWN_ENTITY Ta inline, void
.It Dv LOWDOWN_FOOTNOTE Ta block, special
.It Dv LOWDOWN_HEADER Ta block