1#ifndef __TAGS_H__
2#define __TAGS_H__
3
4/* tags.h -- recognize HTML tags
5
6  (c) 1998-2006 (W3C) MIT, ERCIM, Keio University
7  See tidy.h for the copyright notice.
8
9  CVS Info :
10
11    $Author$
12    $Date$
13    $Revision$
14
15  The HTML tags are stored as 8 bit ASCII strings.
16  Use lookupw() to find a tag given a wide char string.
17
18*/
19
20#include "forward.h"
21#include "attrdict.h"
22
23typedef void (Parser)( TidyDocImpl* doc, Node *node, GetTokenMode mode );
24typedef void (CheckAttribs)( TidyDocImpl* doc, Node *node );
25
26/*
27 Tag dictionary node
28*/
29
30/* types of tags that the user can define */
31typedef enum
32{
33    tagtype_null = 0,
34    tagtype_empty = 1,
35    tagtype_inline = 2,
36    tagtype_block = 4,
37    tagtype_pre = 8
38} UserTagType;
39
40struct _Dict
41{
42    TidyTagId       id;
43    tmbstr          name;
44    uint            versions;
45    AttrVersion const *    attrvers;
46    uint            model;
47    Parser*         parser;
48    CheckAttribs*   chkattrs;
49    Dict*           next;
50};
51
52#if !defined(ELEMENT_HASH_LOOKUP)
53#define ELEMENT_HASH_LOOKUP 1
54#endif
55
56#if ELEMENT_HASH_LOOKUP
57enum
58{
59    ELEMENT_HASH_SIZE=178u
60};
61
62struct _DictHash
63{
64    Dict const*         tag;
65    struct _DictHash*   next;
66};
67
68typedef struct _DictHash DictHash;
69#endif
70
71struct _TidyTagImpl
72{
73    Dict* xml_tags;                /* placeholder for all xml tags */
74    Dict* declared_tag_list;       /* User declared tags */
75#if ELEMENT_HASH_LOOKUP
76    DictHash* hashtab[ELEMENT_HASH_SIZE];
77#endif
78};
79
80typedef struct _TidyTagImpl TidyTagImpl;
81
82/* interface for finding tag by name */
83const Dict* TY_(LookupTagDef)( TidyTagId tid );
84Bool    TY_(FindTag)( TidyDocImpl* doc, Node *node );
85Parser* TY_(FindParser)( TidyDocImpl* doc, Node *node );
86void    TY_(DefineTag)( TidyDocImpl* doc, UserTagType tagType, ctmbstr name );
87void    TY_(FreeDeclaredTags)( TidyDocImpl* doc, UserTagType tagType ); /* tagtype_null to free all */
88
89TidyIterator   TY_(GetDeclaredTagList)( TidyDocImpl* doc );
90ctmbstr        TY_(GetNextDeclaredTag)( TidyDocImpl* doc, UserTagType tagType,
91                                        TidyIterator* iter );
92
93void TY_(InitTags)( TidyDocImpl* doc );
94void TY_(FreeTags)( TidyDocImpl* doc );
95
96
97/* Parser methods for tags */
98
99Parser TY_(ParseHTML);
100Parser TY_(ParseHead);
101Parser TY_(ParseTitle);
102Parser TY_(ParseScript);
103Parser TY_(ParseFrameSet);
104Parser TY_(ParseNoFrames);
105Parser TY_(ParseBody);
106Parser TY_(ParsePre);
107Parser TY_(ParseList);
108Parser TY_(ParseLI);
109Parser TY_(ParseDefList);
110Parser TY_(ParseBlock);
111Parser TY_(ParseInline);
112Parser TY_(ParseEmpty);
113Parser TY_(ParseTableTag);
114Parser TY_(ParseColGroup);
115Parser TY_(ParseRowGroup);
116Parser TY_(ParseRow);
117Parser TY_(ParseSelect);
118Parser TY_(ParseOptGroup);
119Parser TY_(ParseText);
120Parser TY_(ParseObject);
121Parser TY_(ParseMap);
122
123CheckAttribs TY_(CheckAttributes);
124
125/* 0 == TidyTag_UNKNOWN */
126#define TagId(node)        ((node) && (node)->tag ? (node)->tag->id : TidyTag_UNKNOWN)
127#define TagIsId(node, tid) ((node) && (node)->tag && (node)->tag->id == tid)
128
129Bool TY_(nodeIsText)( Node* node );
130Bool TY_(nodeIsElement)( Node* node );
131
132Bool TY_(nodeHasText)( TidyDocImpl* doc, Node* node );
133
134#if 0
135/* Compare & result to operand.  If equal, then all bits
136** requested are set.
137*/
138Bool nodeMatchCM( Node* node, uint contentModel );
139#endif
140
141/* True if any of the bits requested are set.
142*/
143Bool TY_(nodeHasCM)( Node* node, uint contentModel );
144
145Bool TY_(nodeCMIsBlock)( Node* node );
146Bool TY_(nodeCMIsInline)( Node* node );
147Bool TY_(nodeCMIsEmpty)( Node* node );
148
149
150Bool TY_(nodeIsHeader)( Node* node );     /* H1, H2, ..., H6 */
151uint TY_(nodeHeaderLevel)( Node* node );  /* 1, 2, ..., 6 */
152
153#define nodeIsHTML( node )       TagIsId( node, TidyTag_HTML )
154#define nodeIsHEAD( node )       TagIsId( node, TidyTag_HEAD )
155#define nodeIsTITLE( node )      TagIsId( node, TidyTag_TITLE )
156#define nodeIsBASE( node )       TagIsId( node, TidyTag_BASE )
157#define nodeIsMETA( node )       TagIsId( node, TidyTag_META )
158#define nodeIsBODY( node )       TagIsId( node, TidyTag_BODY )
159#define nodeIsFRAMESET( node )   TagIsId( node, TidyTag_FRAMESET )
160#define nodeIsFRAME( node )      TagIsId( node, TidyTag_FRAME )
161#define nodeIsIFRAME( node )     TagIsId( node, TidyTag_IFRAME )
162#define nodeIsNOFRAMES( node )   TagIsId( node, TidyTag_NOFRAMES )
163#define nodeIsHR( node )         TagIsId( node, TidyTag_HR )
164#define nodeIsH1( node )         TagIsId( node, TidyTag_H1 )
165#define nodeIsH2( node )         TagIsId( node, TidyTag_H2 )
166#define nodeIsPRE( node )        TagIsId( node, TidyTag_PRE )
167#define nodeIsLISTING( node )    TagIsId( node, TidyTag_LISTING )
168#define nodeIsP( node )          TagIsId( node, TidyTag_P )
169#define nodeIsUL( node )         TagIsId( node, TidyTag_UL )
170#define nodeIsOL( node )         TagIsId( node, TidyTag_OL )
171#define nodeIsDL( node )         TagIsId( node, TidyTag_DL )
172#define nodeIsDIR( node )        TagIsId( node, TidyTag_DIR )
173#define nodeIsLI( node )         TagIsId( node, TidyTag_LI )
174#define nodeIsDT( node )         TagIsId( node, TidyTag_DT )
175#define nodeIsDD( node )         TagIsId( node, TidyTag_DD )
176#define nodeIsTABLE( node )      TagIsId( node, TidyTag_TABLE )
177#define nodeIsCAPTION( node )    TagIsId( node, TidyTag_CAPTION )
178#define nodeIsTD( node )         TagIsId( node, TidyTag_TD )
179#define nodeIsTH( node )         TagIsId( node, TidyTag_TH )
180#define nodeIsTR( node )         TagIsId( node, TidyTag_TR )
181#define nodeIsCOL( node )        TagIsId( node, TidyTag_COL )
182#define nodeIsCOLGROUP( node )   TagIsId( node, TidyTag_COLGROUP )
183#define nodeIsBR( node )         TagIsId( node, TidyTag_BR )
184#define nodeIsA( node )          TagIsId( node, TidyTag_A )
185#define nodeIsLINK( node )       TagIsId( node, TidyTag_LINK )
186#define nodeIsB( node )          TagIsId( node, TidyTag_B )
187#define nodeIsI( node )          TagIsId( node, TidyTag_I )
188#define nodeIsSTRONG( node )     TagIsId( node, TidyTag_STRONG )
189#define nodeIsEM( node )         TagIsId( node, TidyTag_EM )
190#define nodeIsBIG( node )        TagIsId( node, TidyTag_BIG )
191#define nodeIsSMALL( node )      TagIsId( node, TidyTag_SMALL )
192#define nodeIsPARAM( node )      TagIsId( node, TidyTag_PARAM )
193#define nodeIsOPTION( node )     TagIsId( node, TidyTag_OPTION )
194#define nodeIsOPTGROUP( node )   TagIsId( node, TidyTag_OPTGROUP )
195#define nodeIsIMG( node )        TagIsId( node, TidyTag_IMG )
196#define nodeIsMAP( node )        TagIsId( node, TidyTag_MAP )
197#define nodeIsAREA( node )       TagIsId( node, TidyTag_AREA )
198#define nodeIsNOBR( node )       TagIsId( node, TidyTag_NOBR )
199#define nodeIsWBR( node )        TagIsId( node, TidyTag_WBR )
200#define nodeIsFONT( node )       TagIsId( node, TidyTag_FONT )
201#define nodeIsLAYER( node )      TagIsId( node, TidyTag_LAYER )
202#define nodeIsSPACER( node )     TagIsId( node, TidyTag_SPACER )
203#define nodeIsCENTER( node )     TagIsId( node, TidyTag_CENTER )
204#define nodeIsSTYLE( node )      TagIsId( node, TidyTag_STYLE )
205#define nodeIsSCRIPT( node )     TagIsId( node, TidyTag_SCRIPT )
206#define nodeIsNOSCRIPT( node )   TagIsId( node, TidyTag_NOSCRIPT )
207#define nodeIsFORM( node )       TagIsId( node, TidyTag_FORM )
208#define nodeIsTEXTAREA( node )   TagIsId( node, TidyTag_TEXTAREA )
209#define nodeIsBLOCKQUOTE( node ) TagIsId( node, TidyTag_BLOCKQUOTE )
210#define nodeIsAPPLET( node )     TagIsId( node, TidyTag_APPLET )
211#define nodeIsOBJECT( node )     TagIsId( node, TidyTag_OBJECT )
212#define nodeIsDIV( node )        TagIsId( node, TidyTag_DIV )
213#define nodeIsSPAN( node )       TagIsId( node, TidyTag_SPAN )
214#define nodeIsINPUT( node )      TagIsId( node, TidyTag_INPUT )
215#define nodeIsQ( node )          TagIsId( node, TidyTag_Q )
216#define nodeIsLABEL( node )      TagIsId( node, TidyTag_LABEL )
217#define nodeIsH3( node )         TagIsId( node, TidyTag_H3 )
218#define nodeIsH4( node )         TagIsId( node, TidyTag_H4 )
219#define nodeIsH5( node )         TagIsId( node, TidyTag_H5 )
220#define nodeIsH6( node )         TagIsId( node, TidyTag_H6 )
221#define nodeIsADDRESS( node )    TagIsId( node, TidyTag_ADDRESS )
222#define nodeIsXMP( node )        TagIsId( node, TidyTag_XMP )
223#define nodeIsSELECT( node )     TagIsId( node, TidyTag_SELECT )
224#define nodeIsBLINK( node )      TagIsId( node, TidyTag_BLINK )
225#define nodeIsMARQUEE( node )    TagIsId( node, TidyTag_MARQUEE )
226#define nodeIsEMBED( node )      TagIsId( node, TidyTag_EMBED )
227#define nodeIsBASEFONT( node )   TagIsId( node, TidyTag_BASEFONT )
228#define nodeIsISINDEX( node )    TagIsId( node, TidyTag_ISINDEX )
229#define nodeIsS( node )          TagIsId( node, TidyTag_S )
230#define nodeIsSTRIKE( node )     TagIsId( node, TidyTag_STRIKE )
231#define nodeIsSUB( node )        TagIsId( node, TidyTag_SUB )
232#define nodeIsSUP( node )        TagIsId( node, TidyTag_SUP )
233#define nodeIsU( node )          TagIsId( node, TidyTag_U )
234#define nodeIsMENU( node )       TagIsId( node, TidyTag_MENU )
235#define nodeIsBUTTON( node )     TagIsId( node, TidyTag_BUTTON )
236
237
238#endif /* __TAGS_H__ */
239