mirror of
https://github.com/rkd77/elinks.git
synced 2025-01-03 14:57:44 -05:00
DOM: Added callbacks when adding an element or an attribute.
This commit is contained in:
parent
d6c844288a
commit
9edc009c10
@ -66,6 +66,9 @@ add_sgml_element(struct dom_stack *stack, struct dom_scanner_token *token)
|
|||||||
if (push_dom_node(stack, node) != DOM_CODE_OK)
|
if (push_dom_node(stack, node) != DOM_CODE_OK)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
if (parser->add_element_callback)
|
||||||
|
parser->add_element_callback(parent, node);
|
||||||
|
|
||||||
state = get_dom_stack_top(stack);
|
state = get_dom_stack_top(stack);
|
||||||
assert(node == state->node);
|
assert(node == state->node);
|
||||||
|
|
||||||
@ -97,9 +100,12 @@ add_sgml_attribute(struct dom_stack *stack,
|
|||||||
if (valtoken && valtoken->type == SGML_TOKEN_STRING)
|
if (valtoken && valtoken->type == SGML_TOKEN_STRING)
|
||||||
node->data.attribute.quoted = valtoken->string.string[-1];
|
node->data.attribute.quoted = valtoken->string.string[-1];
|
||||||
|
|
||||||
if (!node || push_dom_node(stack, node) != DOM_CODE_OK)
|
if (push_dom_node(stack, node) != DOM_CODE_OK)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
if (parser->add_attribute_callback)
|
||||||
|
parser->add_attribute_callback(parent, node);
|
||||||
|
|
||||||
pop_dom_node(stack);
|
pop_dom_node(stack);
|
||||||
|
|
||||||
return node;
|
return node;
|
||||||
|
@ -69,6 +69,8 @@ struct sgml_parser_state {
|
|||||||
typedef enum dom_code
|
typedef enum dom_code
|
||||||
(*sgml_error_T)(struct sgml_parser *, struct dom_string *, unsigned int);
|
(*sgml_error_T)(struct sgml_parser *, struct dom_string *, unsigned int);
|
||||||
|
|
||||||
|
typedef void
|
||||||
|
(*sgml_callback_T)(struct dom_node *parent, struct dom_node *current);
|
||||||
|
|
||||||
/** The SGML parser
|
/** The SGML parser
|
||||||
*
|
*
|
||||||
@ -88,6 +90,8 @@ struct sgml_parser {
|
|||||||
|
|
||||||
enum dom_code code; /**< The latest (error) code */
|
enum dom_code code; /**< The latest (error) code */
|
||||||
sgml_error_T error_func; /**< Called for detected errors */
|
sgml_error_T error_func; /**< Called for detected errors */
|
||||||
|
sgml_callback_T add_element_callback; /**< Called for added elements */
|
||||||
|
sgml_callback_T add_attribute_callback; /**< Called for added attributes */
|
||||||
|
|
||||||
struct dom_stack stack; /**< A stack for tracking parsed nodes */
|
struct dom_stack stack; /**< A stack for tracking parsed nodes */
|
||||||
struct dom_stack parsing; /**< Used for tracking parsing states */
|
struct dom_stack parsing; /**< Used for tracking parsing states */
|
||||||
|
Loading…
Reference in New Issue
Block a user