mirror of
https://github.com/rkd77/elinks.git
synced 2024-12-04 14:46:47 -05:00
Introduce sgml_parser_type for specifying tree and streaming parsers
Mostly added for the future, since currently only one parser type is supported.
This commit is contained in:
parent
05a61cd16a
commit
4c8d871404
@ -700,7 +700,7 @@ render_dom_document(struct cache_entry *cached, struct document *document,
|
|||||||
|
|
||||||
assert(document->options.plain);
|
assert(document->options.plain);
|
||||||
|
|
||||||
parser = init_sgml_parser(cached, document);
|
parser = init_sgml_parser(SGML_PARSER_STREAM, cached, document);
|
||||||
if (!parser) return;
|
if (!parser) return;
|
||||||
|
|
||||||
root = parse_sgml(parser, buffer);
|
root = parse_sgml(parser, buffer);
|
||||||
|
@ -297,7 +297,8 @@ parse_sgml_document(struct dom_stack *stack, struct scanner *scanner)
|
|||||||
|
|
||||||
|
|
||||||
struct sgml_parser *
|
struct sgml_parser *
|
||||||
init_sgml_parser(struct cache_entry *cached, struct document *document)
|
init_sgml_parser(enum sgml_parser_type type, struct cache_entry *cached,
|
||||||
|
struct document *document)
|
||||||
{
|
{
|
||||||
size_t obj_size = sizeof(struct sgml_parser_state);
|
size_t obj_size = sizeof(struct sgml_parser_state);
|
||||||
struct sgml_parser *parser;
|
struct sgml_parser *parser;
|
||||||
@ -305,6 +306,7 @@ init_sgml_parser(struct cache_entry *cached, struct document *document)
|
|||||||
parser = mem_calloc(1, sizeof(*parser));
|
parser = mem_calloc(1, sizeof(*parser));
|
||||||
if (!parser) return NULL;
|
if (!parser) return NULL;
|
||||||
|
|
||||||
|
parser->type = type;
|
||||||
parser->document = document;
|
parser->document = document;
|
||||||
parser->cache_entry = cached;
|
parser->cache_entry = cached;
|
||||||
parser->info = &sgml_html_info;
|
parser->info = &sgml_html_info;
|
||||||
|
@ -11,11 +11,24 @@ struct cache_entry;
|
|||||||
struct document;
|
struct document;
|
||||||
struct string;
|
struct string;
|
||||||
|
|
||||||
|
enum sgml_parser_type {
|
||||||
|
/* The first one is a DOM tree builder. */
|
||||||
|
SGML_PARSER_TREE,
|
||||||
|
/* The second one will simply push nodes on the stack, not building a
|
||||||
|
* DOM tree. This interface is similar to that of SAX (Simple API for
|
||||||
|
* XML) where events are fired when nodes are entered and exited. It is
|
||||||
|
* useful when you are not actually interested in the DOM tree, but can
|
||||||
|
* do all processing in a stream-like manner, such as when highlighting
|
||||||
|
* HTML code. */
|
||||||
|
SGML_PARSER_STREAM,
|
||||||
|
};
|
||||||
|
|
||||||
enum sgml_parser_flags {
|
enum sgml_parser_flags {
|
||||||
SGML_PARSER_ADD_ELEMENT_ENDS = 1,
|
SGML_PARSER_ADD_ELEMENT_ENDS = 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct sgml_parser {
|
struct sgml_parser {
|
||||||
|
enum sgml_parser_type type;
|
||||||
/* The parser flags controls what gets added to the DOM tree */
|
/* The parser flags controls what gets added to the DOM tree */
|
||||||
enum sgml_parser_flags flags;
|
enum sgml_parser_flags flags;
|
||||||
struct sgml_info *info;
|
struct sgml_info *info;
|
||||||
@ -33,7 +46,8 @@ struct sgml_parser_state {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct sgml_parser *
|
struct sgml_parser *
|
||||||
init_sgml_parser(struct cache_entry *cached, struct document *document);
|
init_sgml_parser(enum sgml_parser_type type,
|
||||||
|
struct cache_entry *cached, struct document *document);
|
||||||
|
|
||||||
void done_sgml_parser(struct sgml_parser *parser);
|
void done_sgml_parser(struct sgml_parser *parser);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user