blob: 10a3d654f389e77d22572ff68a5efcbf0a9e13df [file] [log] [blame]
Owen Taylor3473f882001-02-23 17:55:21 +00001/*
Daniel Veillardbe586972003-11-18 20:56:51 +00002 * Summary: interface for an HTML 4.0 non-verifying parser
3 * Description: this module implements an HTML 4.0 non-verifying parser
4 * with API compatible with the XML parser ones. It should
5 * be able to parse "real world" HTML, even if severely
6 * broken from a specification point of view.
Owen Taylor3473f882001-02-23 17:55:21 +00007 *
Daniel Veillardbe586972003-11-18 20:56:51 +00008 * Copy: See Copyright for the status of this software.
Owen Taylor3473f882001-02-23 17:55:21 +00009 *
Daniel Veillardbe586972003-11-18 20:56:51 +000010 * Author: Daniel Veillard
Owen Taylor3473f882001-02-23 17:55:21 +000011 */
12
13#ifndef __HTML_PARSER_H__
14#define __HTML_PARSER_H__
Igor Zlatkovic76874e42003-08-25 09:05:12 +000015#include <libxml/xmlversion.h>
Owen Taylor3473f882001-02-23 17:55:21 +000016#include <libxml/parser.h>
17
Daniel Veillarda2351322004-06-27 12:08:10 +000018#ifdef LIBXML_HTML_ENABLED
19
Owen Taylor3473f882001-02-23 17:55:21 +000020#ifdef __cplusplus
21extern "C" {
22#endif
23
24/*
Daniel Veillard61f26172002-03-12 18:46:39 +000025 * Most of the back-end structures from XML and HTML are shared.
Owen Taylor3473f882001-02-23 17:55:21 +000026 */
27typedef xmlParserCtxt htmlParserCtxt;
28typedef xmlParserCtxtPtr htmlParserCtxtPtr;
29typedef xmlParserNodeInfo htmlParserNodeInfo;
30typedef xmlSAXHandler htmlSAXHandler;
31typedef xmlSAXHandlerPtr htmlSAXHandlerPtr;
32typedef xmlParserInput htmlParserInput;
33typedef xmlParserInputPtr htmlParserInputPtr;
34typedef xmlDocPtr htmlDocPtr;
35typedef xmlNodePtr htmlNodePtr;
36
37/*
Daniel Veillard930dfb62003-02-05 10:17:38 +000038 * Internal description of an HTML element, representing HTML 4.01
39 * and XHTML 1.0 (which share the same structure).
Owen Taylor3473f882001-02-23 17:55:21 +000040 */
41typedef struct _htmlElemDesc htmlElemDesc;
42typedef htmlElemDesc *htmlElemDescPtr;
43struct _htmlElemDesc {
44 const char *name; /* The tag name */
Daniel Veillard02bb1702001-06-13 21:11:59 +000045 char startTag; /* Whether the start tag can be implied */
46 char endTag; /* Whether the end tag can be implied */
47 char saveEndTag; /* Whether the end tag should be saved */
48 char empty; /* Is this an empty element ? */
49 char depr; /* Is this a deprecated element ? */
50 char dtd; /* 1: only in Loose DTD, 2: only Frameset one */
51 char isinline; /* is this a block 0 or inline 1 element */
Owen Taylor3473f882001-02-23 17:55:21 +000052 const char *desc; /* the description */
Daniel Veillard930dfb62003-02-05 10:17:38 +000053
54/* NRK Jan.2003
55 * New fields encapsulating HTML structure
56 *
57 * Bugs:
58 * This is a very limited representation. It fails to tell us when
59 * an element *requires* subelements (we only have whether they're
60 * allowed or not), and it doesn't tell us where CDATA and PCDATA
61 * are allowed. Some element relationships are not fully represented:
62 * these are flagged with the word MODIFIER
63 */
64 const char** subelts; /* allowed sub-elements of this element */
65 const char* defaultsubelt; /* subelement for suggested auto-repair
66 if necessary or NULL */
67 const char** attrs_opt; /* Optional Attributes */
68 const char** attrs_depr; /* Additional deprecated attributes */
69 const char** attrs_req; /* Required attributes */
Owen Taylor3473f882001-02-23 17:55:21 +000070};
71
72/*
Daniel Veillard61f26172002-03-12 18:46:39 +000073 * Internal description of an HTML entity.
Owen Taylor3473f882001-02-23 17:55:21 +000074 */
75typedef struct _htmlEntityDesc htmlEntityDesc;
76typedef htmlEntityDesc *htmlEntityDescPtr;
77struct _htmlEntityDesc {
Daniel Veillard56a4cb82001-03-24 17:00:36 +000078 unsigned int value; /* the UNICODE value for the character */
Owen Taylor3473f882001-02-23 17:55:21 +000079 const char *name; /* The entity name */
80 const char *desc; /* the description */
81};
82
83/*
84 * There is only few public functions.
85 */
Igor Zlatkovic76874e42003-08-25 09:05:12 +000086XMLPUBFUN const htmlElemDesc * XMLCALL
87 htmlTagLookup (const xmlChar *tag);
88XMLPUBFUN const htmlEntityDesc * XMLCALL
89 htmlEntityLookup(const xmlChar *name);
90XMLPUBFUN const htmlEntityDesc * XMLCALL
91 htmlEntityValueLookup(unsigned int value);
Owen Taylor3473f882001-02-23 17:55:21 +000092
Igor Zlatkovic76874e42003-08-25 09:05:12 +000093XMLPUBFUN int XMLCALL
94 htmlIsAutoClosed(htmlDocPtr doc,
Owen Taylor3473f882001-02-23 17:55:21 +000095 htmlNodePtr elem);
Igor Zlatkovic76874e42003-08-25 09:05:12 +000096XMLPUBFUN int XMLCALL
97 htmlAutoCloseTag(htmlDocPtr doc,
Owen Taylor3473f882001-02-23 17:55:21 +000098 const xmlChar *name,
99 htmlNodePtr elem);
Igor Zlatkovic76874e42003-08-25 09:05:12 +0000100XMLPUBFUN const htmlEntityDesc * XMLCALL
101 htmlParseEntityRef(htmlParserCtxtPtr ctxt,
Daniel Veillard2fdbd322003-08-18 12:15:38 +0000102 const xmlChar **str);
Igor Zlatkovic76874e42003-08-25 09:05:12 +0000103XMLPUBFUN int XMLCALL
104 htmlParseCharRef(htmlParserCtxtPtr ctxt);
105XMLPUBFUN void XMLCALL
106 htmlParseElement(htmlParserCtxtPtr ctxt);
Owen Taylor3473f882001-02-23 17:55:21 +0000107
Igor Zlatkovic76874e42003-08-25 09:05:12 +0000108XMLPUBFUN htmlParserCtxtPtr XMLCALL
Daniel Veillard34c647c2006-09-21 06:53:59 +0000109 htmlNewParserCtxt(void);
110
111XMLPUBFUN htmlParserCtxtPtr XMLCALL
Igor Zlatkovic76874e42003-08-25 09:05:12 +0000112 htmlCreateMemoryParserCtxt(const char *buffer,
Daniel Veillard02ea1412003-04-09 12:08:47 +0000113 int size);
114
Igor Zlatkovic76874e42003-08-25 09:05:12 +0000115XMLPUBFUN int XMLCALL
116 htmlParseDocument(htmlParserCtxtPtr ctxt);
117XMLPUBFUN htmlDocPtr XMLCALL
118 htmlSAXParseDoc (xmlChar *cur,
Owen Taylor3473f882001-02-23 17:55:21 +0000119 const char *encoding,
120 htmlSAXHandlerPtr sax,
121 void *userData);
Igor Zlatkovic76874e42003-08-25 09:05:12 +0000122XMLPUBFUN htmlDocPtr XMLCALL
123 htmlParseDoc (xmlChar *cur,
Owen Taylor3473f882001-02-23 17:55:21 +0000124 const char *encoding);
Igor Zlatkovic76874e42003-08-25 09:05:12 +0000125XMLPUBFUN htmlDocPtr XMLCALL
126 htmlSAXParseFile(const char *filename,
Owen Taylor3473f882001-02-23 17:55:21 +0000127 const char *encoding,
128 htmlSAXHandlerPtr sax,
129 void *userData);
Igor Zlatkovic76874e42003-08-25 09:05:12 +0000130XMLPUBFUN htmlDocPtr XMLCALL
131 htmlParseFile (const char *filename,
Owen Taylor3473f882001-02-23 17:55:21 +0000132 const char *encoding);
Igor Zlatkovic76874e42003-08-25 09:05:12 +0000133XMLPUBFUN int XMLCALL
134 UTF8ToHtml (unsigned char *out,
Owen Taylor3473f882001-02-23 17:55:21 +0000135 int *outlen,
Daniel Veillard963d2ae2002-01-20 22:08:18 +0000136 const unsigned char *in,
Owen Taylor3473f882001-02-23 17:55:21 +0000137 int *inlen);
Igor Zlatkovic76874e42003-08-25 09:05:12 +0000138XMLPUBFUN int XMLCALL
139 htmlEncodeEntities(unsigned char *out,
Owen Taylor3473f882001-02-23 17:55:21 +0000140 int *outlen,
Daniel Veillard963d2ae2002-01-20 22:08:18 +0000141 const unsigned char *in,
Owen Taylor3473f882001-02-23 17:55:21 +0000142 int *inlen, int quoteChar);
Igor Zlatkovic76874e42003-08-25 09:05:12 +0000143XMLPUBFUN int XMLCALL
144 htmlIsScriptAttribute(const xmlChar *name);
145XMLPUBFUN int XMLCALL
146 htmlHandleOmittedElem(int val);
Owen Taylor3473f882001-02-23 17:55:21 +0000147
Daniel Veillard73b013f2003-09-30 12:36:01 +0000148#ifdef LIBXML_PUSH_ENABLED
Owen Taylor3473f882001-02-23 17:55:21 +0000149/**
Daniel Veillard61f26172002-03-12 18:46:39 +0000150 * Interfaces for the Push mode.
Owen Taylor3473f882001-02-23 17:55:21 +0000151 */
Igor Zlatkovic76874e42003-08-25 09:05:12 +0000152XMLPUBFUN htmlParserCtxtPtr XMLCALL
153 htmlCreatePushParserCtxt(htmlSAXHandlerPtr sax,
Owen Taylor3473f882001-02-23 17:55:21 +0000154 void *user_data,
155 const char *chunk,
156 int size,
157 const char *filename,
158 xmlCharEncoding enc);
Igor Zlatkovic76874e42003-08-25 09:05:12 +0000159XMLPUBFUN int XMLCALL
160 htmlParseChunk (htmlParserCtxtPtr ctxt,
Owen Taylor3473f882001-02-23 17:55:21 +0000161 const char *chunk,
162 int size,
163 int terminate);
Daniel Veillard73b013f2003-09-30 12:36:01 +0000164#endif /* LIBXML_PUSH_ENABLED */
165
166XMLPUBFUN void XMLCALL
167 htmlFreeParserCtxt (htmlParserCtxtPtr ctxt);
Daniel Veillard930dfb62003-02-05 10:17:38 +0000168
Daniel Veillard9475a352003-09-26 12:47:50 +0000169/*
170 * New set of simpler/more flexible APIs
171 */
172/**
173 * xmlParserOption:
174 *
175 * This is the set of XML parser options that can be passed down
176 * to the xmlReadDoc() and similar calls.
177 */
178typedef enum {
Daniel Veillardea4b0ba2005-08-23 16:06:08 +0000179 HTML_PARSE_RECOVER = 1<<0, /* Relaxed parsing */
Daniel Veillardf1121c42010-07-26 14:02:42 +0200180 HTML_PARSE_NODEFDTD = 1<<2, /* do not default a doctype if not found */
Daniel Veillard9475a352003-09-26 12:47:50 +0000181 HTML_PARSE_NOERROR = 1<<5, /* suppress error reports */
182 HTML_PARSE_NOWARNING= 1<<6, /* suppress warning reports */
183 HTML_PARSE_PEDANTIC = 1<<7, /* pedantic error reporting */
184 HTML_PARSE_NOBLANKS = 1<<8, /* remove blank nodes */
Daniel Veillard8874b942005-08-25 13:19:21 +0000185 HTML_PARSE_NONET = 1<<11,/* Forbid network access */
Daniel Veillarde20fb5a2010-01-29 20:47:08 +0100186 HTML_PARSE_NOIMPLIED= 1<<13,/* Do not add implied html/body... elements */
Daniel Veillardc62efc82011-05-16 16:03:50 +0800187 HTML_PARSE_COMPACT = 1<<16,/* compact small text nodes */
188 HTML_PARSE_IGNORE_ENC=1<<21 /* ignore internal document encoding hint */
Daniel Veillard9475a352003-09-26 12:47:50 +0000189} htmlParserOption;
190
191XMLPUBFUN void XMLCALL
192 htmlCtxtReset (htmlParserCtxtPtr ctxt);
193XMLPUBFUN int XMLCALL
194 htmlCtxtUseOptions (htmlParserCtxtPtr ctxt,
195 int options);
196XMLPUBFUN htmlDocPtr XMLCALL
197 htmlReadDoc (const xmlChar *cur,
198 const char *URL,
199 const char *encoding,
200 int options);
201XMLPUBFUN htmlDocPtr XMLCALL
202 htmlReadFile (const char *URL,
203 const char *encoding,
204 int options);
205XMLPUBFUN htmlDocPtr XMLCALL
206 htmlReadMemory (const char *buffer,
207 int size,
208 const char *URL,
209 const char *encoding,
210 int options);
211XMLPUBFUN htmlDocPtr XMLCALL
212 htmlReadFd (int fd,
213 const char *URL,
214 const char *encoding,
215 int options);
216XMLPUBFUN htmlDocPtr XMLCALL
217 htmlReadIO (xmlInputReadCallback ioread,
218 xmlInputCloseCallback ioclose,
219 void *ioctx,
220 const char *URL,
221 const char *encoding,
222 int options);
223XMLPUBFUN htmlDocPtr XMLCALL
224 htmlCtxtReadDoc (xmlParserCtxtPtr ctxt,
225 const xmlChar *cur,
226 const char *URL,
227 const char *encoding,
228 int options);
229XMLPUBFUN htmlDocPtr XMLCALL
230 htmlCtxtReadFile (xmlParserCtxtPtr ctxt,
231 const char *filename,
232 const char *encoding,
233 int options);
234XMLPUBFUN htmlDocPtr XMLCALL
235 htmlCtxtReadMemory (xmlParserCtxtPtr ctxt,
236 const char *buffer,
237 int size,
238 const char *URL,
239 const char *encoding,
240 int options);
241XMLPUBFUN htmlDocPtr XMLCALL
242 htmlCtxtReadFd (xmlParserCtxtPtr ctxt,
243 int fd,
244 const char *URL,
245 const char *encoding,
246 int options);
247XMLPUBFUN htmlDocPtr XMLCALL
248 htmlCtxtReadIO (xmlParserCtxtPtr ctxt,
249 xmlInputReadCallback ioread,
250 xmlInputCloseCallback ioclose,
251 void *ioctx,
252 const char *URL,
253 const char *encoding,
254 int options);
255
Daniel Veillard930dfb62003-02-05 10:17:38 +0000256/* NRK/Jan2003: further knowledge of HTML structure
257 */
258typedef enum {
259 HTML_NA = 0 , /* something we don't check at all */
260 HTML_INVALID = 0x1 ,
261 HTML_DEPRECATED = 0x2 ,
262 HTML_VALID = 0x4 ,
263 HTML_REQUIRED = 0xc /* VALID bit set so ( & HTML_VALID ) is TRUE */
264} htmlStatus ;
265
266/* Using htmlElemDesc rather than name here, to emphasise the fact
267 that otherwise there's a lookup overhead
268*/
Igor Zlatkovic76874e42003-08-25 09:05:12 +0000269XMLPUBFUN htmlStatus XMLCALL htmlAttrAllowed(const htmlElemDesc*, const xmlChar*, int) ;
270XMLPUBFUN int XMLCALL htmlElementAllowedHere(const htmlElemDesc*, const xmlChar*) ;
271XMLPUBFUN htmlStatus XMLCALL htmlElementStatusHere(const htmlElemDesc*, const htmlElemDesc*) ;
272XMLPUBFUN htmlStatus XMLCALL htmlNodeStatus(const htmlNodePtr, int) ;
William M. Brack7a821652003-08-15 07:27:40 +0000273/**
274 * htmlDefaultSubelement:
275 * @elt: HTML element
276 *
277 * Returns the default subelement for this element
278 */
Daniel Veillard930dfb62003-02-05 10:17:38 +0000279#define htmlDefaultSubelement(elt) elt->defaultsubelt
William M. Brack7a821652003-08-15 07:27:40 +0000280/**
281 * htmlElementAllowedHereDesc:
282 * @parent: HTML parent element
283 * @elt: HTML element
284 *
285 * Checks whether an HTML element description may be a
286 * direct child of the specified element.
287 *
288 * Returns 1 if allowed; 0 otherwise.
289 */
Daniel Veillard930dfb62003-02-05 10:17:38 +0000290#define htmlElementAllowedHereDesc(parent,elt) \
291 htmlElementAllowedHere((parent), (elt)->name)
William M. Brack7a821652003-08-15 07:27:40 +0000292/**
293 * htmlRequiredAttrs:
294 * @elt: HTML element
295 *
296 * Returns the attributes required for the specified element.
297 */
Daniel Veillard930dfb62003-02-05 10:17:38 +0000298#define htmlRequiredAttrs(elt) (elt)->attrs_req
299
300
Owen Taylor3473f882001-02-23 17:55:21 +0000301#ifdef __cplusplus
302}
303#endif
304
Daniel Veillarda2351322004-06-27 12:08:10 +0000305#endif /* LIBXML_HTML_ENABLED */
Owen Taylor3473f882001-02-23 17:55:21 +0000306#endif /* __HTML_PARSER_H__ */