Method Parser.HTML()->add_entities()


Method add_tag
Method add_container
Method add_entity
Method add_quote_tag
Method add_tags
Method add_containers
Method add_entities

Parser.HTML add_tag(string name, mixed to_do)
Parser.HTML add_container(string name, mixed to_do)
Parser.HTML add_entity(string entity, mixed to_do)
Parser.HTML add_quote_tag(string name, mixed to_do, string end)
Parser.HTML add_tags(mapping(string:mixed) tags)
Parser.HTML add_containers(mapping(string:mixed) containers)
Parser.HTML add_entities(mapping(string:mixed) entities)

Description

Registers the actions to take when parsing various things. Tags, containers, entities are as usual. add_quote_tag() adds a special kind of tag that reads any data until the next occurrence of the end string immediately before a tag end.

Parameter to_do

This argument can be any of the following.

function(:void)

The function will be called as a callback function. It will get the following arguments, depending on the type of callback.

 mixed tag_callback(Parser.HTML parser,mapping args,mixed ... extra)
 mixed container_callback(Parser.HTML parser,mapping args,string content,mixed ... extra)
 mixed entity_callback(Parser.HTML parser,mixed ... extra)
 mixed quote_tag_callback(Parser.HTML parser,string content,mixed ... extra)
	

string

This tag/container/entity is then replaced by the string. The string is normally not reparsed, i.e. it's equivalent to writing a function that returns the string in an array (but a lot faster). If reparse_strings is set the string will be reparsed, though.

array

The first element is a function as above. It will receive the rest of the array as extra arguments. If extra arguments are given by set_extra(), they will appear after the ones in this array.

int(0..)

If there is a tag/container/entity with the given name in the parser, it's removed.

The callback function can return:

string

This string will be pushed on the parser stack and be parsed. Be careful not to return anything in this way that could lead to a infinite recursion.

array

The element(s) of the array is the result of the function. This will not be parsed. This is useful for avoiding infinite recursion. The array can be of any size, this means the empty array is the most effective to return if you don't care about the result. If the parser is operating in mixed_mode, the array can contain anything. Otherwise only strings are allowed.

int(0)

This means "don't do anything", ie the item that generated the callback is left as it is, and the parser continues.

int(1)

Reparse the last item again. This is useful to parse a tag as a container, or vice versa: just add or remove callbacks for the tag and return this to jump to the right callback.

Returns

Returns the object being called.

See also

tags, containers, entities