Debian Codegraph @

include/libxml/HTMLparser.h

raw
1 /**
2 * @file
3 *
4 * @brief HTML parser, doesn't support HTML5
5 *
6 * This module orginally implemented an HTML parser based on the
7 * (underspecified) HTML 4.0 spec. As of 2.14, the tokenizer
8 * conforms to HTML5. Tree construction still follows a custom,
9 * unspecified algorithm with many differences to HTML5.
10 *
11 * The parser defaults to ISO-8859-1, the default encoding of
12 * HTTP/1.0.
13 *
14 * @copyright See Copyright for the status of this software.
15 *
16 * @author Daniel Veillard
17 */
18
19 #ifndef __HTML_PARSER_H__
20 #define __HTML_PARSER_H__
21 #include <libxml/xmlversion.h>
22 #include <libxml/parser.h>
23
24 #ifdef LIBXML_HTML_ENABLED
25
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29
30 /*
31 * Backward compatibility
32 */
33 #define UTF8ToHtml htmlUTF8ToHtml
34 #define htmlDefaultSubelement(elt) elt->defaultsubelt
35 #define htmlElementAllowedHereDesc(parent,elt) \
36 htmlElementAllowedHere((parent), (elt)->name)
37 #define htmlRequiredAttrs(elt) (elt)->attrs_req
38
39 /*
40 * Most of the back-end structures from XML and HTML are shared.
41 */
42 /** Same as xmlParserCtxt */
43 typedef xmlParserCtxt htmlParserCtxt;
44 typedef xmlParserCtxtPtr htmlParserCtxtPtr;
45 typedef xmlParserNodeInfo htmlParserNodeInfo;
46 /** Same as xmlSAXHandler */
47 typedef xmlSAXHandler htmlSAXHandler;
48 typedef xmlSAXHandlerPtr htmlSAXHandlerPtr;
49 /** Same as xmlParserInput */
50 typedef xmlParserInput htmlParserInput;
51 typedef xmlParserInputPtr htmlParserInputPtr;
52 typedef xmlDocPtr htmlDocPtr;
53 typedef xmlNodePtr htmlNodePtr;
54
55 /** @cond ignore */
56
57 /*
58 * Internal description of an HTML element, representing HTML 4.01
59 * and XHTML 1.0 (which share the same structure).
60 */
61 typedef struct _htmlElemDesc htmlElemDesc;
62 typedef htmlElemDesc *htmlElemDescPtr;
63 struct _htmlElemDesc {
64 const char *name; /* The tag name */
65 char startTag; /* unused */
66 char endTag; /* Whether the end tag can be implied */
67 char saveEndTag; /* unused */
68 char empty; /* Is this an empty element ? */
69 char depr; /* unused */
70 char dtd; /* unused */
71 char isinline; /* is this a block 0 or inline 1 element */
72 const char *desc; /* the description */
73
74 const char** subelts XML_DEPRECATED_MEMBER;
75 const char* defaultsubelt XML_DEPRECATED_MEMBER;
76 const char** attrs_opt XML_DEPRECATED_MEMBER;
77 const char** attrs_depr XML_DEPRECATED_MEMBER;
78 const char** attrs_req XML_DEPRECATED_MEMBER;
79
80 int dataMode;
81 };
82
83 /*
84 * Internal description of an HTML entity.
85 */
86 typedef struct _htmlEntityDesc htmlEntityDesc;
87 typedef htmlEntityDesc *htmlEntityDescPtr;
88 struct _htmlEntityDesc {
89 unsigned int value; /* the UNICODE value for the character */
90 const char *name; /* The entity name */
91 const char *desc; /* the description */
92 };
93
94 #ifdef LIBXML_SAX1_ENABLED
95 /**
96 * @deprecated Use #xmlSAX2InitHtmlDefaultSAXHandler
97 */
98 XML_DEPRECATED
99 XMLPUBVAR const xmlSAXHandlerV1 htmlDefaultSAXHandler;
100 #endif /* LIBXML_SAX1_ENABLED */
101
102 /** @endcond */
103
104 /*
105 * There is only few public functions.
106 */
107 XML_DEPRECATED
108 XMLPUBFUN void
109 htmlInitAutoClose (void);
110 XML_DEPRECATED
111 XMLPUBFUN const htmlElemDesc *
112 htmlTagLookup (const xmlChar *tag);
113 XML_DEPRECATED
114 XMLPUBFUN const htmlEntityDesc *
115 htmlEntityLookup(const xmlChar *name);
116 XML_DEPRECATED
117 XMLPUBFUN const htmlEntityDesc *
118 htmlEntityValueLookup(unsigned int value);
119
120 XML_DEPRECATED
121 XMLPUBFUN int
122 htmlIsAutoClosed(xmlDoc *doc,
123 xmlNode *elem);
124 XML_DEPRECATED
125 XMLPUBFUN int
126 htmlAutoCloseTag(xmlDoc *doc,
127 const xmlChar *name,
128 xmlNode *elem);
129 XML_DEPRECATED
130 XMLPUBFUN const htmlEntityDesc *
131 htmlParseEntityRef(htmlParserCtxt *ctxt,
132 const xmlChar **str);
133 XML_DEPRECATED
134 XMLPUBFUN int
135 htmlParseCharRef(htmlParserCtxt *ctxt);
136 XML_DEPRECATED
137 XMLPUBFUN void
138 htmlParseElement(htmlParserCtxt *ctxt);
139
140 XMLPUBFUN htmlParserCtxt *
141 htmlNewParserCtxt(void);
142 XMLPUBFUN htmlParserCtxt *
143 htmlNewSAXParserCtxt(const htmlSAXHandler *sax,
144 void *userData);
145
146 XMLPUBFUN htmlParserCtxt *
147 htmlCreateMemoryParserCtxt(const char *buffer,
148 int size);
149
150 XMLPUBFUN int
151 htmlParseDocument(htmlParserCtxt *ctxt);
152 XML_DEPRECATED
153 XMLPUBFUN xmlDoc *
154 htmlSAXParseDoc (const xmlChar *cur,
155 const char *encoding,
156 htmlSAXHandler *sax,
157 void *userData);
158 XMLPUBFUN xmlDoc *
159 htmlParseDoc (const xmlChar *cur,
160 const char *encoding);
161 XMLPUBFUN htmlParserCtxt *
162 htmlCreateFileParserCtxt(const char *filename,
163 const char *encoding);
164 XML_DEPRECATED
165 XMLPUBFUN xmlDoc *
166 htmlSAXParseFile(const char *filename,
167 const char *encoding,
168 htmlSAXHandler *sax,
169 void *userData);
170 XMLPUBFUN xmlDoc *
171 htmlParseFile (const char *filename,
172 const char *encoding);
173 XML_DEPRECATED
174 XMLPUBFUN int
175 htmlUTF8ToHtml (unsigned char *out,
176 int *outlen,
177 const unsigned char *in,
178 int *inlen);
179 XML_DEPRECATED
180 XMLPUBFUN int
181 htmlEncodeEntities(unsigned char *out,
182 int *outlen,
183 const unsigned char *in,
184 int *inlen, int quoteChar);
185 XML_DEPRECATED
186 XMLPUBFUN int
187 htmlIsScriptAttribute(const xmlChar *name);
188 XML_DEPRECATED
189 XMLPUBFUN int
190 htmlHandleOmittedElem(int val);
191
192 #ifdef LIBXML_PUSH_ENABLED
193 /*
194 * Interfaces for the Push mode.
195 */
196 XMLPUBFUN htmlParserCtxt *
197 htmlCreatePushParserCtxt(htmlSAXHandler *sax,
198 void *user_data,
199 const char *chunk,
200 int size,
201 const char *filename,
202 xmlCharEncoding enc);
203 XMLPUBFUN int
204 htmlParseChunk (htmlParserCtxt *ctxt,
205 const char *chunk,
206 int size,
207 int terminate);
208 #endif /* LIBXML_PUSH_ENABLED */
209
210 XMLPUBFUN void
211 htmlFreeParserCtxt (htmlParserCtxt *ctxt);
212
213 /*
214 * New set of simpler/more flexible APIs
215 */
216
217 /**
218 * This is the set of HTML parser options that can be passed to
219 * #htmlReadDoc, #htmlCtxtSetOptions and other functions.
220 */
221 typedef enum {
222 /**
223 * No effect as of 2.14.0.
224 */
225 HTML_PARSE_RECOVER = 1<<0,
226 /**
227 * Do not default to a doctype if none was found.
228 */
229 HTML_PARSE_NODEFDTD = 1<<2,
230 /**
231 * Disable error and warning reports to the error handlers.
232 * Errors are still accessible with xmlCtxtGetLastError().
233 */
234 HTML_PARSE_NOERROR = 1<<5,
235 /**
236 * Disable warning reports.
237 */
238 HTML_PARSE_NOWARNING = 1<<6,
239 /**
240 * No effect.
241 */
242 HTML_PARSE_PEDANTIC = 1<<7,
243 /**
244 * Remove some text nodes containing only whitespace from the
245 * result document. Which nodes are removed depends on a conservative
246 * heuristic. The reindenting feature of the serialization code relies
247 * on this option to be set when parsing. Use of this option is
248 * DISCOURAGED.
249 */
250 HTML_PARSE_NOBLANKS = 1<<8,
251 /**
252 * No effect.
253 */
254 HTML_PARSE_NONET = 1<<11,
255 /**
256 * Do not add implied html, head or body elements.
257 */
258 HTML_PARSE_NOIMPLIED = 1<<13,
259 /**
260 * Store small strings directly in the node struct to save
261 * memory.
262 */
263 HTML_PARSE_COMPACT = 1<<16,
264 /**
265 * Relax some internal limits. See XML_PARSE_HUGE in xmlParserOption.
266 *
267 * @since 2.14.0
268 *
269 * Use XML_PARSE_HUGE with older versions.
270 */
271 HTML_PARSE_HUGE = 1<<19,
272 /**
273 * Ignore the encoding in the HTML declaration. This option is
274 * mostly unneeded these days. The only effect is to enforce
275 * ISO-8859-1 decoding of ASCII-like data.
276 */
277 HTML_PARSE_IGNORE_ENC =1<<21,
278 /**
279 * Enable reporting of line numbers larger than 65535.
280 *
281 * @since 2.14.0
282 *
283 * Use XML_PARSE_BIG_LINES with older versions.
284 */
285 HTML_PARSE_BIG_LINES = 1<<22,
286 /**
287 * Make the tokenizer emit a SAX callback for each token. This results
288 * in unbalanced invocations of startElement and endElement.
289 *
290 * For now, this is only usable to tokenize HTML5 with custom SAX
291 * callbacks. A tree builder isn't implemented yet.
292 *
293 * @since 2.14.0
294 */
295 HTML_PARSE_HTML5 = 1<<26
296 } htmlParserOption;
297
298 XMLPUBFUN void
299 htmlCtxtReset (htmlParserCtxt *ctxt);
300 XMLPUBFUN int
301 htmlCtxtSetOptions (htmlParserCtxt *ctxt,
302 int options);
303 XMLPUBFUN int
304 htmlCtxtUseOptions (htmlParserCtxt *ctxt,
305 int options);
306 XMLPUBFUN xmlDoc *
307 htmlReadDoc (const xmlChar *cur,
308 const char *URL,
309 const char *encoding,
310 int options);
311 XMLPUBFUN xmlDoc *
312 htmlReadFile (const char *URL,
313 const char *encoding,
314 int options);
315 XMLPUBFUN xmlDoc *
316 htmlReadMemory (const char *buffer,
317 int size,
318 const char *URL,
319 const char *encoding,
320 int options);
321 XMLPUBFUN xmlDoc *
322 htmlReadFd (int fd,
323 const char *URL,
324 const char *encoding,
325 int options);
326 XMLPUBFUN xmlDoc *
327 htmlReadIO (xmlInputReadCallback ioread,
328 xmlInputCloseCallback ioclose,
329 void *ioctx,
330 const char *URL,
331 const char *encoding,
332 int options);
333 XMLPUBFUN xmlDoc *
334 htmlCtxtParseDocument (htmlParserCtxt *ctxt,
335 xmlParserInput *input);
336 XMLPUBFUN xmlDoc *
337 htmlCtxtReadDoc (xmlParserCtxt *ctxt,
338 const xmlChar *cur,
339 const char *URL,
340 const char *encoding,
341 int options);
342 XMLPUBFUN xmlDoc *
343 htmlCtxtReadFile (xmlParserCtxt *ctxt,
344 const char *filename,
345 const char *encoding,
346 int options);
347 XMLPUBFUN xmlDoc *
348 htmlCtxtReadMemory (xmlParserCtxt *ctxt,
349 const char *buffer,
350 int size,
351 const char *URL,
352 const char *encoding,
353 int options);
354 XMLPUBFUN xmlDoc *
355 htmlCtxtReadFd (xmlParserCtxt *ctxt,
356 int fd,
357 const char *URL,
358 const char *encoding,
359 int options);
360 XMLPUBFUN xmlDoc *
361 htmlCtxtReadIO (xmlParserCtxt *ctxt,
362 xmlInputReadCallback ioread,
363 xmlInputCloseCallback ioclose,
364 void *ioctx,
365 const char *URL,
366 const char *encoding,
367 int options);
368
369 /**
370 * deprecated content model
371 */
372 typedef enum {
373 HTML_NA = 0 , /* something we don't check at all */
374 HTML_INVALID = 0x1 ,
375 HTML_DEPRECATED = 0x2 ,
376 HTML_VALID = 0x4 ,
377 HTML_REQUIRED = 0xc /* VALID bit set so ( & HTML_VALID ) is TRUE */
378 } htmlStatus ;
379
380 /* Using htmlElemDesc rather than name here, to emphasise the fact
381 that otherwise there's a lookup overhead
382 */
383 XML_DEPRECATED
384 XMLPUBFUN htmlStatus htmlAttrAllowed(const htmlElemDesc*, const xmlChar*, int) ;
385 XML_DEPRECATED
386 XMLPUBFUN int htmlElementAllowedHere(const htmlElemDesc*, const xmlChar*) ;
387 XML_DEPRECATED
388 XMLPUBFUN htmlStatus htmlElementStatusHere(const htmlElemDesc*, const htmlElemDesc*) ;
389 XML_DEPRECATED
390 XMLPUBFUN htmlStatus htmlNodeStatus(xmlNode *, int) ;
391
392 #ifdef __cplusplus
393 }
394 #endif
395
396 #endif /* LIBXML_HTML_ENABLED */
397 #endif /* __HTML_PARSER_H__ */