aboutsummaryrefslogtreecommitdiff
path: root/man/man3/html.3
blob: 8de7b121230cf57a0c4ef88a5801ea57c1bd1f42 (plain)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
.TH HTML 3
.SH NAME
parsehtml,
printitems,
validitems,
freeitems,
freedocinfo,
dimenkind,
dimenspec,
targetid,
targetname,
fromStr,
toStr
\- HTML parser
.SH SYNOPSIS
.nf
.PP
.ft L
#include <u.h>
#include <libc.h>
#include <html.h>
.ft P
.PP
.ta \w'\fLToken* 'u
.B
Item*	parsehtml(uchar* data, int datalen, Rune* src, int mtype,
.B
	int chset, Docinfo** pdi)
.PP
.B
void	printitems(Item* items, char* msg)
.PP
.B
int	validitems(Item* items)
.PP
.B
void	freeitems(Item* items)
.PP
.B
void	freedocinfo(Docinfo* d)
.PP
.B
int	dimenkind(Dimen d)
.PP
.B
int	dimenspec(Dimen d)
.PP
.B
int	targetid(Rune* s)
.PP
.B
Rune*	targetname(int targid)
.PP
.B
uchar*	fromStr(Rune* buf, int n, int chset)
.PP
.B
Rune*	toStr(uchar* buf, int n, int chset)
.SH DESCRIPTION
.PP
This library implements a parser for HTML 4.0 documents.
The parsed HTML is converted into an intermediate representation that
describes how the formatted HTML should be laid out.
.PP
.I Parsehtml
parses an entire HTML document contained in the buffer
.I data
and having length
.IR datalen .
The URL of the document should be passed in as
.IR src .
.I Mtype
is the media type of the document, which should be either
.B TextHtml
or
.BR TextPlain .
The character set of the document is described in
.IR chset ,
which can be one of
.BR US_Ascii ,
.BR ISO_8859_1 ,
.B UTF_8
or
.BR Unicode .
The return value is a linked list of
.B Item
structures, described in detail below.
As a side effect, 
.BI * pdi
is set to point to a newly created
.B Docinfo
structure, containing information pertaining to the entire document.
.PP
The library expects two allocation routines to be provided by the
caller,
.B emalloc
and
.BR erealloc .
These routines are analogous to the standard malloc and realloc routines,
except that they should not return if the memory allocation fails.
In addition,
.B emalloc
is required to zero the memory.
.PP
For debugging purposes,
.I printitems
may be called to display the contents of an item list; individual items may
be printed using the
.B %I
print verb, installed on the first call to
.IR parsehtml .
.I validitems
traverses the item list, checking that all of the pointers are valid.
It returns
.B 1
is everything is ok, and
.B 0
if an error was found.
Normally, one would not call these routines directly.
Instead, one sets the global variable
.I dbgbuild
and the library calls them automatically.
One can also set
.IR warn ,
to cause the library to print a warning whenever it finds a problem with the
input document, and
.IR dbglex ,
to print debugging information in the lexer.
.PP
When an item list is finished with, it should be freed with
.IR freeitems .
Then,
.I freedocinfo
should be called on the pointer returned in
.BI * pdi\f1.
.PP
.I Dimenkind
and
.I dimenspec
are provided to interpret the
.B Dimen
type, as described in the section
.IR "Dimension Specifications" .
.PP
Frame target names are mapped to integer ids via a global, permanent mapping.
To find the value for a given name, call
.IR targetid ,
which allocates a new id if the name hasn't been seen before.
The name of a given, known id may be retrieved using
.IR targetname .
The library predefines
.BR FTtop ,
.BR FTself ,
.B FTparent
and
.BR FTblank .
.PP
The library handles all text as Unicode strings (type
.BR Rune* ).
Character set conversion is provided by
.I fromStr
and
.IR toStr .
.I FromStr
takes
.I n
Unicode characters from
.I buf
and converts them to the character set described by
.IR chset .
.I ToStr
takes
.I n
bytes from
.IR buf ,
interpretted as belonging to character set
.IR chset ,
and converts them to a Unicode string.
Both routines null-terminate the result, and use
.B emalloc
to allocate space for it.
.SS Items
The return value of
.I parsehtml
is a linked list of variant structures,
with the generic portion described by the following definition:
.PP
.EX
.ta 6n +\w'Genattr* 'u
typedef struct Item Item;
struct Item
{
	Item*	next;
	int	width;
	int	height;
	int	ascent;
	int	anchorid;
	int	state;
	Genattr*	genattr;
	int	tag;
};
.EE
.PP
The field
.B next
points to the successor in the linked list of items, while
.BR width ,
.BR height ,
and
.B ascent
are intended for use by the caller as part of the layout process.
.BR Anchorid ,
if non-zero, gives the integer id assigned by the parser to the anchor that
this item is in (see section
.IR Anchors ).
.B State
is a collection of flags and values described as follows:
.PP
.EX
.ta 6n +\w'IFindentshift = 'u
enum
{
	IFbrk =	0x80000000,
	IFbrksp =	0x40000000,
	IFnobrk =	0x20000000,
	IFcleft =	0x10000000,
	IFcright =	0x08000000,
	IFwrap =	0x04000000,
	IFhang =	0x02000000,
	IFrjust =	0x01000000,
	IFcjust =	0x00800000,
	IFsmap =	0x00400000,
	IFindentshift =	8,
	IFindentmask =	(255<<IFindentshift),
	IFhangmask =	255
};
.EE
.PP
.B IFbrk
is set if a break is to be forced before placing this item.
.B IFbrksp
is set if a 1 line space should be added to the break (in which case
.B IFbrk
is also set).
.B IFnobrk
is set if a break is not permitted before the item.
.B IFcleft
is set if left floats should be cleared (that is, if the list of pending left floats should be placed)
before this item is placed, and
.B IFcright
is set for right floats.
In both cases, IFbrk is also set.
.B IFwrap
is set if the line containing this item is allowed to wrap.
.B IFhang
is set if this item hangs into the left indent.
.B IFrjust
is set if the line containing this item should be right justified,
and
.B IFcjust
is set for center justified lines.
.B IFsmap
is used to indicate that an image is a server-side map.
The low 8 bits, represented by
.BR IFhangmask ,
indicate the current hang into left indent, in tenths of a tabstop.
The next 8 bits, represented by
.B IFindentmask
and
.BR IFindentshift ,
indicate the current indent in tab stops.
.PP
The field
.B genattr
is an optional pointer to an auxiliary structure, described in the section
.IR "Generic Attributes" .
.PP
Finally,
.B tag
describes which variant type this item has.
It can have one of the values
.BR Itexttag ,
.BR Iruletag ,
.BR Iimagetag ,
.BR Iformfieldtag ,
.BR Itabletag ,
.B Ifloattag
or
.BR Ispacertag .
For each of these values, there is an additional structure defined, which
includes Item as an unnamed initial substructure, and then defines additional
fields.
.PP
Items of type
.B Itexttag
represent a piece of text, using the following structure:
.PP
.EX
.ta 6n +\w'Rune* 'u
struct Itext
{
	Item;
	Rune*	s;
	int	fnt;
	int	fg;
	uchar	voff;
	uchar	ul;
};
.EE
.PP
Here
.B s
is a null-terminated Unicode string of the actual characters making up this text item,
.B fnt
is the font number (described in the section
.IR "Font Numbers" ),
and
.B fg
is the RGB encoded color for the text.
.B Voff
measures the vertical offset from the baseline; subtract
.B Voffbias
to get the actual value (negative values represent a displacement down the page).
The field
.B ul
is the underline style:
.B ULnone
if no underline,
.B ULunder
for conventional underline, and
.B ULmid
for strike-through.
.PP
Items of type
.B Iruletag
represent a horizontal rule, as follows:
.PP
.EX
.ta 6n +\w'Dimen 'u
struct Irule
{
	Item;
	uchar	align;
	uchar	noshade;
	int	size;
	Dimen	wspec;
};
.EE
.PP
Here
.B align
is the alignment specification (described in the corresponding section),
.B noshade
is set if the rule should not be shaded,
.B size
is the height of the rule (as set by the size attribute),
and
.B wspec
is the desired width (see section
.IR "Dimension Specifications" ).
.PP
Items of type
.B Iimagetag
describe embedded images, for which the following structure is defined:
.PP
.EX
.ta 6n +\w'Iimage* 'u
struct Iimage
{
	Item;
	Rune*	imsrc;
	int	imwidth;
	int	imheight;
	Rune*	altrep;
	Map*	map;
	int	ctlid;
	uchar	align;
	uchar	hspace;
	uchar	vspace;
	uchar	border;
	Iimage*	nextimage;
};
.EE
.PP
Here
.B imsrc
is the URL of the image source,
.B imwidth
and
.BR imheight ,
if non-zero, contain the specified width and height for the image,
and
.B altrep
is the text to use as an alternative to the image, if the image is not displayed.
.BR Map ,
if set, points to a structure describing an associated client-side image map.
.B Ctlid
is reserved for use by the application, for handling animated images.
.B Align
encodes the alignment specification of the image.
.B Hspace
contains the number of pixels to pad the image with on either side, and
.B Vspace
the padding above and below.
.B Border
is the width of the border to draw around the image.
.B Nextimage
points to the next image in the document (the head of this list is
.BR Docinfo.images ).
.PP
For items of type
.BR Iformfieldtag ,
the following structure is defined:
.PP
.EX
.ta 6n +\w'Formfield* 'u
struct Iformfield
{
	Item;
	Formfield*	formfield;
};
.EE
.PP
This adds a single field,
.BR formfield ,
which points to a structure describing a field in a form, described in section
.IR Forms .
.PP
For items of type
.BR Itabletag ,
the following structure is defined:
.PP
.EX
.ta 6n +\w'Table* 'u
struct Itable
{
	Item;
	Table*	table;
};
.EE
.PP
.B Table
points to a structure describing the table, described in the section
.IR Tables .
.PP
For items of type
.BR Ifloattag ,
the following structure is defined:
.PP
.EX
.ta 6n +\w'Ifloat* 'u
struct Ifloat
{
	Item;
	Item*	item;
	int	x;
	int	y;
	uchar	side;
	uchar	infloats;
	Ifloat*	nextfloat;
};
.EE
.PP
The
.B item
points to a single item (either a table or an image) that floats (the text of the
document flows around it), and
.B side
indicates the margin that this float sticks to; it is either
.B ALleft
or
.BR ALright .
.B X
and
.B y
are reserved for use by the caller; these are typically used for the coordinates
of the top of the float.
.B Infloats
is used by the caller to keep track of whether it has placed the float.
.B Nextfloat
is used by the caller to link together all of the floats that it has placed.
.PP
For items of type
.BR Ispacertag ,
the following structure is defined:
.PP
.EX
.ta 6n +\w'Item; 'u
struct Ispacer
{
	Item;
	int	spkind;
};
.EE
.PP
.B Spkind
encodes the kind of spacer, and may be one of
.B ISPnull
(zero height and width),
.B ISPvline
(takes on height and ascent of the current font),
.B ISPhspace
(has the width of a space in the current font) and
.B ISPgeneral
(for all other purposes, such as between markers and lists).
.SS Generic Attributes
.PP
The genattr field of an item, if non-nil, points to a structure that holds
the values of attributes not specific to any particular
item type, as they occur on a wide variety of underlying HTML tags.
The structure is as follows:
.PP
.EX
.ta 6n +\w'SEvent* 'u
typedef struct Genattr Genattr;
struct Genattr
{
	Rune*	id;
	Rune*	class;
	Rune*	style;
	Rune*	title;
	SEvent*	events;
};
.EE
.PP
Fields
.BR id ,
.BR class ,
.B style
and
.BR title ,
when non-nil, contain values of correspondingly named attributes of the HTML tag
associated with this item.
.B Events
is a linked list of events (with corresponding scripted actions) associated with the item:
.PP
.EX
.ta 6n +\w'SEvent* 'u
typedef struct SEvent SEvent;
struct SEvent
{
	SEvent*	next;
	int	type;
	Rune*	script;
};
.EE
.PP
Here,
.B next
points to the next event in the list,
.B type
is one of
.BR SEonblur ,
.BR SEonchange ,
.BR SEonclick ,
.BR SEondblclick ,
.BR SEonfocus ,
.BR SEonkeypress ,
.BR SEonkeyup ,
.BR SEonload ,
.BR SEonmousedown ,
.BR SEonmousemove ,
.BR SEonmouseout ,
.BR SEonmouseover ,
.BR SEonmouseup ,
.BR SEonreset ,
.BR SEonselect ,
.B SEonsubmit
or
.BR SEonunload ,
and
.B script
is the text of the associated script.
.SS Dimension Specifications
.PP
Some structures include a dimension specification, used where
a number can be followed by a
.B %
or a
.B *
to indicate
percentage of total or relative weight.
This is encoded using the following structure:
.PP
.EX
.ta 6n +\w'int 'u
typedef struct Dimen Dimen;
struct Dimen
{
	int	kindspec;
};
.EE
.PP
Separate kind and spec values are extracted using
.I dimenkind
and
.IR dimenspec .
.I Dimenkind
returns one of
.BR Dnone ,
.BR Dpixels ,
.B Dpercent
or
.BR Drelative .
.B Dnone
means that no dimension was specified.
In all other cases,
.I dimenspec
should be called to find the absolute number of pixels, the percentage of total,
or the relative weight.
.SS Background Specifications
.PP
It is possible to set the background of the entire document, and also
for some parts of the document (such as tables).
This is encoded as follows:
.PP
.EX
.ta 6n +\w'Rune* 'u
typedef struct Background Background;
struct Background
{
	Rune*	image;
	int	color;
};
.EE
.PP
.BR Image ,
if non-nil, is the URL of an image to use as the background.
If this is nil,
.B color
is used instead, as the RGB value for a solid fill color.
.SS Alignment Specifications
.PP
Certain items have alignment specifiers taken from the following
enumerated type:
.PP
.EX
.ta 6n
enum
{
	ALnone = 0, ALleft, ALcenter, ALright, ALjustify,
	ALchar, ALtop, ALmiddle, ALbottom, ALbaseline
};
.EE
.PP
These values correspond to the various alignment types named in the HTML 4.0
standard.
If an item has an alignment of
.B ALleft
or
.BR ALright ,
the library automatically encapsulates it inside a float item.
.PP
Tables, and the various rows, columns and cells within them, have a more
complex alignment specification, composed of separate vertical and
horizontal alignments:
.PP
.EX
.ta 6n +\w'uchar 'u
typedef struct Align Align;
struct Align
{
	uchar	halign;
	uchar	valign;
};
.EE
.PP
.B Halign
can be one of
.BR ALnone ,
.BR ALleft ,
.BR ALcenter ,
.BR ALright ,
.B ALjustify
or
.BR ALchar .
.B Valign
can be one of
.BR ALnone ,
.BR ALmiddle ,
.BR ALbottom ,
.BR ALtop
or
.BR ALbaseline .
.SS Font Numbers
.PP
Text items have an associated font number (the
.B fnt
field), which is encoded as
.BR style*NumSize+size .
Here,
.B style
is one of
.BR FntR ,
.BR FntI ,
.B FntB
or
.BR FntT ,
for roman, italic, bold and typewriter font styles, respectively, and size is
.BR Tiny ,
.BR Small ,
.BR Normal ,
.B Large
or
.BR Verylarge .
The total number of possible font numbers is
.BR NumFnt ,
and the default font number is
.B DefFnt
(which is roman style, normal size).
.SS Document Info
.PP
Global information about an HTML page is stored in the following structure:
.PP
.EX
.ta 6n +\w'DestAnchor* 'u
typedef struct Docinfo Docinfo;
struct Docinfo
{
	// stuff from HTTP headers, doc head, and body tag
	Rune*	src;
	Rune*	base;
	Rune*	doctitle;
	Background	background;
	Iimage*	backgrounditem;
	int	text;
	int	link;
	int	vlink;
	int	alink;
	int	target;
	int	chset;
	int	mediatype;
	int	scripttype;
	int	hasscripts;
	Rune*	refresh;
	Kidinfo*	kidinfo;
	int	frameid;

	// info needed to respond to user actions
	Anchor*	anchors;
	DestAnchor*	dests;
	Form*	forms;
	Table*	tables;
	Map*	maps;
	Iimage*	images;
};
.EE
.PP
.B Src
gives the URL of the original source of the document,
and
.B base
is the base URL.
.B Doctitle
is the document's title, as set by a
.B <title>
element.
.B Background
is as described in the section
.IR "Background Specifications" ,
and
.B backgrounditem
is set to be an image item for the document's background image (if given as a URL),
or else nil.
.B Text
gives the default foregound text color of the document,
.B link
the unvisited hyperlink color,
.B vlink
the visited hyperlink color, and
.B alink
the color for highlighting hyperlinks (all in 24-bit RGB format).
.B Target
is the default target frame id.
.B Chset
and
.B mediatype
are as for the
.I chset
and
.I mtype
parameters to
.IR parsehtml .
.B Scripttype
is the type of any scripts contained in the document, and is always
.BR TextJavascript .
.B Hasscripts
is set if the document contains any scripts.
Scripting is currently unsupported.
.B Refresh
is the contents of a
.B "<meta http-equiv=Refresh ...>"
tag, if any.
.B Kidinfo
is set if this document is a frameset (see section
.IR Frames ).
.B Frameid
is this document's frame id.
.PP
.B Anchors
is a list of hyperlinks contained in the document,
and
.B dests
is a list of hyperlink destinations within the page (see the following section for details).
.BR Forms ,
.B tables
and
.B maps
are lists of the various forms, tables and client-side maps contained
in the document, as described in subsequent sections.
.B Images
is a list of all the image items in the document.
.SS Anchors
.PP
The library builds two lists for all of the
.B <a>
elements (anchors) in a document.
Each anchor is assigned a unique anchor id within the document.
For anchors which are hyperlinks (the
.B href
attribute was supplied), the following structure is defined:
.PP
.EX
.ta 6n +\w'Anchor* 'u
typedef struct Anchor Anchor;
struct Anchor
{
	Anchor*	next;
	int	index;
	Rune*	name;
	Rune*	href;
	int	target;
};
.EE
.PP
.B Next
points to the next anchor in the list (the head of this list is
.BR Docinfo.anchors ).
.B Index
is the anchor id; each item within this hyperlink is tagged with this value
in its
.B anchorid
field.
.B Name
and
.B href
are the values of the correspondingly named attributes of the anchor
(in particular, href is the URL to go to).
.B Target
is the value of the target attribute (if provided) converted to a frame id.
.PP
Destinations within the document (anchors with the name attribute set)
are held in the
.B Docinfo.dests
list, using the following structure:
.PP
.EX
.ta 6n +\w'DestAnchor* 'u
typedef struct DestAnchor DestAnchor;
struct DestAnchor
{
	DestAnchor*	next;
	int	index;
	Rune*	name;
	Item*	item;
};
.EE
.PP
.B Next
is the next element of the list,
.B index
is the anchor id,
.B name
is the value of the name attribute, and
.B item
is points to the item within the parsed document that should be considered
to be the destination.
.SS Forms
.PP
Any forms within a document are kept in a list, headed by
.BR Docinfo.forms .
The elements of this list are as follows:
.PP
.EX
.ta 6n +\w'Formfield* 'u
typedef struct Form Form;
struct Form
{
	Form*	next;
	int	formid;
	Rune*	name;
	Rune*	action;
	int	target;
	int	method;
	int	nfields;
	Formfield*	fields;
};
.EE
.PP
.B Next
points to the next form in the list.
.B Formid
is a serial number for the form within the document.
.B Name
is the value of the form's name or id attribute.
.B Action
is the value of any action attribute.
.B Target
is the value of the target attribute (if any) converted to a frame target id.
.B Method
is one of
.B HGet
or
.BR HPost .
.B Nfields
is the number of fields in the form, and
.B fields
is a linked list of the actual fields.
.PP
The individual fields in a form are described by the following structure:
.PP
.EX
.ta 6n +\w'Formfield* 'u
typedef struct Formfield Formfield;
struct Formfield
{
	Formfield*	next;
	int	ftype;
	int	fieldid;
	Form*	form;
	Rune*	name;
	Rune*	value;
	int	size;
	int	maxlength;
	int	rows;
	int	cols;
	uchar	flags;
	Option*	options;
	Item*	image;
	int	ctlid;
	SEvent*	events;
};
.EE
.PP
Here,
.B next
points to the next field in the list.
.B Ftype
is the type of the field, which can be one of
.BR Ftext ,
.BR Fpassword ,
.BR Fcheckbox ,
.BR Fradio ,
.BR Fsubmit ,
.BR Fhidden ,
.BR Fimage ,
.BR Freset ,
.BR Ffile ,
.BR Fbutton ,
.B Fselect
or
.BR Ftextarea .
.B Fieldid
is a serial number for the field within the form.
.B Form
points back to the form containing this field.
.BR Name ,
.BR value ,
.BR size ,
.BR maxlength ,
.B rows
and
.B cols
each contain the values of corresponding attributes of the field, if present.
.B Flags
contains per-field flags, of which
.B FFchecked
and
.B FFmultiple
are defined.
.B Image
is only used for fields of type
.BR Fimage ;
it points to an image item containing the image to be displayed.
.B Ctlid
is reserved for use by the caller, typically to store a unique id
of an associated control used to implement the field.
.B Events
is the same as the corresponding field of the generic attributes
associated with the item containing this field.
.B Options
is only used by fields of type
.BR Fselect ;
it consists of a list of possible options that may be selected for that
field, using the following structure:
.PP
.EX
.ta 6n +\w'Option* 'u
typedef struct Option Option;
struct Option
{
	Option*	next;
	int	selected;
	Rune*	value;
	Rune*	display;
};
.EE
.PP
.B Next
points to the next element of the list.
.B Selected
is set if this option is to be displayed initially.
.B Value
is the value to send when the form is submitted if this option is selected.
.B Display
is the string to display on the screen for this option.
.SS Tables
.PP
The library builds a list of all the tables in the document,
headed by
.BR Docinfo.tables .
Each element of this list has the following format:
.PP
.EX
.ta 6n +\w'Tablecell*** 'u
typedef struct Table Table;
struct Table
{
	Table*	next;
	int	tableid;
	Tablerow*	rows;
	int	nrow;
	Tablecol*	cols;
	int	ncol;
	Tablecell*	cells;
	int	ncell;
	Tablecell***	grid;
	Align	align;
	Dimen	width;
	int	border;
	int	cellspacing;
	int	cellpadding;
	Background	background;
	Item*	caption;
	uchar	caption_place;
	Lay*	caption_lay;
	int	totw;
	int	toth;
	int	caph;
	int	availw;
	Token*	tabletok;
	uchar	flags;
};
.EE
.PP
.B Next
points to the next element in the list of tables.
.B Tableid
is a serial number for the table within the document.
.B Rows
is an array of row specifications (described below) and
.B nrow
is the number of elements in this array.
Similarly,
.B cols
is an array of column specifications, and
.B ncol
the size of this array.
.B Cells
is a list of all cells within the table (structure described below)
and
.B ncell
is the number of elements in this list.
Note that a cell may span multiple rows and/or columns, thus
.B ncell
may be smaller than
.BR nrow*ncol .
.B Grid
is a two-dimensional array of cells within the table; the cell
at row
.B i
and column
.B j
is
.BR Table.grid[i][j] .
A cell that spans multiple rows and/or columns will
be referenced by
.B grid
multiple times, however it will only occur once in
.BR cells .
.B Align
gives the alignment specification for the entire table,
and
.B width
gives the requested width as a dimension specification.
.BR Border ,
.B cellspacing
and
.B cellpadding
give the values of the corresponding attributes for the table,
and
.B background
gives the requested background for the table.
.B Caption
is a linked list of items to be displayed as the caption of the
table, either above or below depending on whether
.B caption_place
is
.B ALtop
or
.BR ALbottom .
Most of the remaining fields are reserved for use by the caller,
except
.BR tabletok ,
which is reserved for internal use.
The type
.B Lay
is not defined by the library; the caller can provide its
own definition.
.PP
The
.B Tablecol
structure is defined for use by the caller.
The library ensures that the correct number of these
is allocated, but leaves them blank.
The fields are as follows:
.PP
.EX
.ta 6n +\w'Point 'u
typedef struct Tablecol Tablecol;
struct Tablecol
{
	int	width;
	Align	align;
	Point		pos;
};
.EE
.PP
The rows in the table are specified as follows:
.PP
.EX
.ta 6n +\w'Background 'u
typedef struct Tablerow Tablerow;
struct Tablerow
{
	Tablerow*	next;
	Tablecell*	cells;
	int	height;
	int	ascent;
	Align	align;
	Background	background;
	Point	pos;
	uchar	flags;
};
.EE
.PP
.B Next
is only used during parsing; it should be ignored by the caller.
.B Cells
provides a list of all the cells in a row, linked through their
.B nextinrow
fields (see below).
.BR Height ,
.B ascent
and
.B pos
are reserved for use by the caller.
.B Align
is the alignment specification for the row, and
.B background
is the background to use, if specified.
.B Flags
is used by the parser; ignore this field.
.PP
The individual cells of the table are described as follows:
.PP
.EX
.ta 6n +\w'Background 'u
typedef struct Tablecell Tablecell;
struct Tablecell
{
	Tablecell*	next;
	Tablecell*	nextinrow;
	int	cellid;
	Item*	content;
	Lay*	lay;
	int	rowspan;
	int	colspan;
	Align	align;
	uchar	flags;
	Dimen	wspec;
	int	hspec;
	Background	background;
	int	minw;
	int	maxw;
	int	ascent;
	int	row;
	int	col;
	Point	pos;
};
.EE
.PP
.B Next
is used to link together the list of all cells within a table
.RB ( Table.cells ),
whereas
.B nextinrow
is used to link together all the cells within a single row
.RB ( Tablerow.cells ).
.B Cellid
provides a serial number for the cell within the table.
.B Content
is a linked list of the items to be laid out within the cell.
.B Lay
is reserved for the user to describe how these items have
been laid out.
.B Rowspan
and
.B colspan
are the number of rows and columns spanned by this cell,
respectively.
.B Align
is the alignment specification for the cell.
.B Flags
is some combination of
.BR TFparsing ,
.B TFnowrap
and
.B TFisth
or'd together.
Here
.B TFparsing
is used internally by the parser, and should be ignored.
.B TFnowrap
means that the contents of the cell should not be
wrapped if they don't fit the available width,
rather, the table should be expanded if need be
(this is set when the nowrap attribute is supplied).
.B TFisth
means that the cell was created by the
.B <th>
element (rather than the
.B <td>
element),
indicating that it is a header cell rather than a data cell.
.B Wspec
provides a suggested width as a dimension specification,
and
.B hspec
provides a suggested height in pixels.
.B Background
gives a background specification for the individual cell.
.BR Minw ,
.BR maxw ,
.B ascent
and
.B pos
are reserved for use by the caller during layout.
.B Row
and
.B col
give the indices of the row and column of the top left-hand
corner of the cell within the table grid.
.SS Client-side Maps
.PP
The library builds a list of client-side maps, headed by
.BR Docinfo.maps ,
and having the following structure:
.PP
.EX
.ta 6n +\w'Rune* 'u
typedef struct Map Map;
struct Map
{
	Map*	next;
	Rune*	name;
	Area*	areas;
};
.EE
.PP
.B Next
points to the next element in the list,
.B name
is the name of the map (use to bind it to an image), and
.B areas
is a list of the areas within the image that comprise the map,
using the following structure:
.PP
.EX
.ta 6n +\w'Dimen* 'u
typedef struct Area Area;
struct Area
{
	Area*	next;
	int	shape;
	Rune*	href;
	int	target;
	Dimen*	coords;
	int	ncoords;
};
.EE
.PP
.B Next
points to the next element in the map's list of areas.
.B Shape
describes the shape of the area, and is one of
.BR SHrect ,
.B SHcircle
or
.BR  SHpoly .
.B Href
is the URL associated with this area in its role as
a hypertext link, and
.B target
is the target frame it should be loaded in.
.B Coords
is an array of coordinates for the shape, and
.B ncoords
is the size of this array (number of elements).
.SS Frames
.PP
If the
.B Docinfo.kidinfo
field is set, the document is a frameset.
In this case, it is typical for
.I parsehtml
to return nil, as a document which is a frameset should have no actual
items that need to be laid out (such will appear only in subsidiary documents).
It is possible that items will be returned by a malformed document; the caller
should check for this and free any such items.
.PP
The
.B Kidinfo
structure itself reflects the fact that framesets can be nested within a document.
If is defined as follows:
.PP
.EX
.ta 6n +\w'Kidinfo* 'u
typedef struct Kidinfo Kidinfo;
struct Kidinfo
{
	Kidinfo*	next;
	int	isframeset;

	// fields for "frame"
	Rune*	src;
	Rune*	name;
	int	marginw;
	int	marginh;
	int	framebd;
	int	flags;

	// fields for "frameset"
	Dimen*	rows;
	int	nrows;
	Dimen*	cols;
	int	ncols;
	Kidinfo*	kidinfos;
	Kidinfo*	nextframeset;
};
.EE
.PP
.B Next
is only used if this structure is part of a containing frameset; it points to the next
element in the list of children of that frameset.
.B Isframeset
is set when this structure represents a frameset; if clear, it is an individual frame.
.PP
Some fields are used only for framesets.
.B Rows
is an array of dimension specifications for rows in the frameset, and
.B nrows
is the length of this array.
.B Cols
is the corresponding array for columns, of length
.BR ncols .
.B Kidinfos
points to a list of components contained within this frameset, each
of which may be a frameset or a frame.
.B Nextframeset
is only used during parsing, and should be ignored.
.PP
The remaining fields are used if the structure describes a frame, not a frameset.
.B Src
provides the URL for the document that should be initially loaded into this frame.
Note that this may be a relative URL, in which case it should be interpretted
using the containing document's URL as the base.
.B Name
gives the name of the frame, typically supplied via a name attribute in the HTML.
If no name was given, the library allocates one.
.BR Marginw ,
.B marginh
and
.B framebd
are the values of the marginwidth, marginheight and frameborder attributes, respectively.
.B Flags
can contain some combination of the following:
.B FRnoresize
(the frame had the noresize attribute set, and the user should not be allowed to resize it),
.B FRnoscroll
(the frame should not have any scroll bars),
.B FRhscroll
(the frame should have a horizontal scroll bar),
.B FRvscroll
(the frame should have a vertical scroll bar),
.B FRhscrollauto
(the frame should be automatically given a horizontal scroll bar if its contents
would not otherwise fit), and
.B FRvscrollauto
(the frame gets a vertical scrollbar only if required).
.SH SOURCE
.B /sys/src/libhtml
.SH SEE ALSO
.IR fmt (1)
.PP
W3C World Wide Web Consortium,
``HTML 4.01 Specification''.
.SH BUGS
The entire HTML document must be loaded into memory before
any of it can be parsed.