Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes16kdownloads
HTMLparser.h321 linesDownload Raw Back to libxml
1/*2 * Summary: interface for an HTML 4.0 non-verifying parser3 * Description: this module implements an HTML 4.0 non-verifying parser4 *              with API compatible with the XML parser ones. It should5 *              be able to parse "real world" HTML, even if severely6 *              broken from a specification point of view.7 *8 * Copy: See Copyright for the status of this software.9 *10 * Author: Daniel Veillard11 */12 13#ifndef __HTML_PARSER_H__14#define __HTML_PARSER_H__15#include <libxml/xmlversion.h>16#include <libxml/parser.h>17 18#ifdef LIBXML_HTML_ENABLED19 20#ifdef __cplusplus21extern "C" {22#endif23 24/*25 * Most of the back-end structures from XML and HTML are shared.26 */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/*38 * Internal description of an HTML element, representing HTML 4.0139 * and XHTML 1.0 (which share the same structure).40 */41typedef struct _htmlElemDesc htmlElemDesc;42typedef htmlElemDesc *htmlElemDescPtr;43struct _htmlElemDesc {44    const char *name;	/* The tag name */45    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 */52    const char *desc;   /* the description */53 54/* NRK Jan.200355 * New fields encapsulating HTML structure56 *57 * Bugs:58 *	This is a very limited representation.  It fails to tell us when59 *	an element *requires* subelements (we only have whether they're60 *	allowed or not), and it doesn't tell us where CDATA and PCDATA61 *	are allowed.  Some element relationships are not fully represented:62 *	these are flagged with the word MODIFIER63 */64    const char** subelts;		/* allowed sub-elements of this element */65    const char* defaultsubelt;	/* subelement for suggested auto-repair66					   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 */70};71 72/*73 * Internal description of an HTML entity.74 */75typedef struct _htmlEntityDesc htmlEntityDesc;76typedef htmlEntityDesc *htmlEntityDescPtr;77struct _htmlEntityDesc {78    unsigned int value;	/* the UNICODE value for the character */79    const char *name;	/* The entity name */80    const char *desc;   /* the description */81};82 83/*84 * There is only few public functions.85 */86XML_DEPRECATED87XMLPUBFUN void88			htmlInitAutoClose	(void);89XMLPUBFUN const htmlElemDesc *90			htmlTagLookup	(const xmlChar *tag);91XMLPUBFUN const htmlEntityDesc *92			htmlEntityLookup(const xmlChar *name);93XMLPUBFUN const htmlEntityDesc *94			htmlEntityValueLookup(unsigned int value);95 96XMLPUBFUN int97			htmlIsAutoClosed(htmlDocPtr doc,98					 htmlNodePtr elem);99XMLPUBFUN int100			htmlAutoCloseTag(htmlDocPtr doc,101					 const xmlChar *name,102					 htmlNodePtr elem);103XML_DEPRECATED104XMLPUBFUN const htmlEntityDesc *105			htmlParseEntityRef(htmlParserCtxtPtr ctxt,106					 const xmlChar **str);107XML_DEPRECATED108XMLPUBFUN int109			htmlParseCharRef(htmlParserCtxtPtr ctxt);110XML_DEPRECATED111XMLPUBFUN void112			htmlParseElement(htmlParserCtxtPtr ctxt);113 114XMLPUBFUN htmlParserCtxtPtr115			htmlNewParserCtxt(void);116XMLPUBFUN htmlParserCtxtPtr117			htmlNewSAXParserCtxt(const htmlSAXHandler *sax,118					     void *userData);119 120XMLPUBFUN htmlParserCtxtPtr121			htmlCreateMemoryParserCtxt(const char *buffer,122						   int size);123 124XMLPUBFUN int125			htmlParseDocument(htmlParserCtxtPtr ctxt);126XML_DEPRECATED127XMLPUBFUN htmlDocPtr128			htmlSAXParseDoc	(const xmlChar *cur,129					 const char *encoding,130					 htmlSAXHandlerPtr sax,131					 void *userData);132XMLPUBFUN htmlDocPtr133			htmlParseDoc	(const xmlChar *cur,134					 const char *encoding);135XMLPUBFUN htmlParserCtxtPtr136			htmlCreateFileParserCtxt(const char *filename,137	                                         const char *encoding);138XML_DEPRECATED139XMLPUBFUN htmlDocPtr140			htmlSAXParseFile(const char *filename,141					 const char *encoding,142					 htmlSAXHandlerPtr sax,143					 void *userData);144XMLPUBFUN htmlDocPtr145			htmlParseFile	(const char *filename,146					 const char *encoding);147XMLPUBFUN int148			UTF8ToHtml	(unsigned char *out,149					 int *outlen,150					 const unsigned char *in,151					 int *inlen);152XMLPUBFUN int153			htmlEncodeEntities(unsigned char *out,154					 int *outlen,155					 const unsigned char *in,156					 int *inlen, int quoteChar);157XMLPUBFUN int158			htmlIsScriptAttribute(const xmlChar *name);159XMLPUBFUN int160			htmlHandleOmittedElem(int val);161 162#ifdef LIBXML_PUSH_ENABLED163/**164 * Interfaces for the Push mode.165 */166XMLPUBFUN htmlParserCtxtPtr167			htmlCreatePushParserCtxt(htmlSAXHandlerPtr sax,168						 void *user_data,169						 const char *chunk,170						 int size,171						 const char *filename,172						 xmlCharEncoding enc);173XMLPUBFUN int174			htmlParseChunk		(htmlParserCtxtPtr ctxt,175						 const char *chunk,176						 int size,177						 int terminate);178#endif /* LIBXML_PUSH_ENABLED */179 180XMLPUBFUN void181			htmlFreeParserCtxt	(htmlParserCtxtPtr ctxt);182 183/*184 * New set of simpler/more flexible APIs185 */186/**187 * xmlParserOption:188 *189 * This is the set of XML parser options that can be passed down190 * to the xmlReadDoc() and similar calls.191 */192typedef enum {193    HTML_PARSE_RECOVER  = 1<<0, /* Relaxed parsing */194    HTML_PARSE_NODEFDTD = 1<<2, /* do not default a doctype if not found */195    HTML_PARSE_NOERROR	= 1<<5,	/* suppress error reports */196    HTML_PARSE_NOWARNING= 1<<6,	/* suppress warning reports */197    HTML_PARSE_PEDANTIC	= 1<<7,	/* pedantic error reporting */198    HTML_PARSE_NOBLANKS	= 1<<8,	/* remove blank nodes */199    HTML_PARSE_NONET	= 1<<11,/* Forbid network access */200    HTML_PARSE_NOIMPLIED= 1<<13,/* Do not add implied html/body... elements */201    HTML_PARSE_COMPACT  = 1<<16,/* compact small text nodes */202    HTML_PARSE_IGNORE_ENC=1<<21 /* ignore internal document encoding hint */203} htmlParserOption;204 205XMLPUBFUN void206		htmlCtxtReset		(htmlParserCtxtPtr ctxt);207XMLPUBFUN int208		htmlCtxtUseOptions	(htmlParserCtxtPtr ctxt,209					 int options);210XMLPUBFUN htmlDocPtr211		htmlReadDoc		(const xmlChar *cur,212					 const char *URL,213					 const char *encoding,214					 int options);215XMLPUBFUN htmlDocPtr216		htmlReadFile		(const char *URL,217					 const char *encoding,218					 int options);219XMLPUBFUN htmlDocPtr220		htmlReadMemory		(const char *buffer,221					 int size,222					 const char *URL,223					 const char *encoding,224					 int options);225XMLPUBFUN htmlDocPtr226		htmlReadFd		(int fd,227					 const char *URL,228					 const char *encoding,229					 int options);230XMLPUBFUN htmlDocPtr231		htmlReadIO		(xmlInputReadCallback ioread,232					 xmlInputCloseCallback ioclose,233					 void *ioctx,234					 const char *URL,235					 const char *encoding,236					 int options);237XMLPUBFUN htmlDocPtr238		htmlCtxtReadDoc		(xmlParserCtxtPtr ctxt,239					 const xmlChar *cur,240					 const char *URL,241					 const char *encoding,242					 int options);243XMLPUBFUN htmlDocPtr244		htmlCtxtReadFile		(xmlParserCtxtPtr ctxt,245					 const char *filename,246					 const char *encoding,247					 int options);248XMLPUBFUN htmlDocPtr249		htmlCtxtReadMemory		(xmlParserCtxtPtr ctxt,250					 const char *buffer,251					 int size,252					 const char *URL,253					 const char *encoding,254					 int options);255XMLPUBFUN htmlDocPtr256		htmlCtxtReadFd		(xmlParserCtxtPtr ctxt,257					 int fd,258					 const char *URL,259					 const char *encoding,260					 int options);261XMLPUBFUN htmlDocPtr262		htmlCtxtReadIO		(xmlParserCtxtPtr ctxt,263					 xmlInputReadCallback ioread,264					 xmlInputCloseCallback ioclose,265					 void *ioctx,266					 const char *URL,267					 const char *encoding,268					 int options);269 270/* NRK/Jan2003: further knowledge of HTML structure271 */272typedef enum {273  HTML_NA = 0 ,		/* something we don't check at all */274  HTML_INVALID = 0x1 ,275  HTML_DEPRECATED = 0x2 ,276  HTML_VALID = 0x4 ,277  HTML_REQUIRED = 0xc /* VALID bit set so ( & HTML_VALID ) is TRUE */278} htmlStatus ;279 280/* Using htmlElemDesc rather than name here, to emphasise the fact281   that otherwise there's a lookup overhead282*/283XMLPUBFUN htmlStatus htmlAttrAllowed(const htmlElemDesc*, const xmlChar*, int) ;284XMLPUBFUN int htmlElementAllowedHere(const htmlElemDesc*, const xmlChar*) ;285XMLPUBFUN htmlStatus htmlElementStatusHere(const htmlElemDesc*, const htmlElemDesc*) ;286XMLPUBFUN htmlStatus htmlNodeStatus(const htmlNodePtr, int) ;287/**288 * htmlDefaultSubelement:289 * @elt: HTML element290 *291 * Returns the default subelement for this element292 */293#define htmlDefaultSubelement(elt) elt->defaultsubelt294/**295 * htmlElementAllowedHereDesc:296 * @parent: HTML parent element297 * @elt: HTML element298 *299 * Checks whether an HTML element description may be a300 * direct child of the specified element.301 *302 * Returns 1 if allowed; 0 otherwise.303 */304#define htmlElementAllowedHereDesc(parent,elt) \305	htmlElementAllowedHere((parent), (elt)->name)306/**307 * htmlRequiredAttrs:308 * @elt: HTML element309 *310 * Returns the attributes required for the specified element.311 */312#define htmlRequiredAttrs(elt) (elt)->attrs_req313 314 315#ifdef __cplusplus316}317#endif318 319#endif /* LIBXML_HTML_ENABLED */320#endif /* __HTML_PARSER_H__ */321 
codekingpro/portable-devtools · Team Ai