Skip to content

Commit

Permalink
fix: documentation on custom html tag handlers.
Browse files Browse the repository at this point in the history
  • Loading branch information
AlbertWeichselbraun committed Feb 16, 2024
1 parent 0f3280d commit aa1b4cb
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -535,19 +535,22 @@ If the fine-tuning options discussed above are not sufficient, you may even over
.. code-block:: python
from inscriptis.html_engine import Inscriptis
from functools import partial
inscriptis = Inscriptis(html_tree, config)
inscriptis.start_tag_handler_dict['a'] = partial(my_handle_start_a, inscriptis)
inscriptis.end_tag_handler_dict['a'] = partial(my_handle_end_a, inscriptis)
from inscriptis import ParserConfig
my_mapping = CustomHtmlTagHandlerMapping(
start_tag_mapping={'a': my_handle_start_a},
end_tag_mapping={'a': my_handle_end_a}
)
inscriptis = Inscriptis(html_tree,
ParserConfig(custom_html_tag_handler_mapping=my_mapping))
text = inscriptis.get_text()
In the example the standard HTML handlers for the ``a`` tag are overwritten with custom versions (i.e., ``my_handle_start_a`` and ``my_handle_end_a``).
You may define custom handlers for any tag, regardless of whether it already exists in ``start_tag_handler_dict`` or ``end_tag_handler_dict``.
You may define custom handlers for any tag, regardless of whether it already exists in the standard mapping.
Please refer to `custom-html-handling.py <https://github.com/weblyzard/inscriptis/blob/master/examples/custom-html-handling.py>`_ for a working example.
Please refer to `custom-html-handling.py <https://github.com/weblyzard/inscriptis/blob/master/examples/custom-html-handling.py>`_ for a working example.
The standard HTML tag handlers can be found in the `inscriptis.model.tag` <https://github.com/weblyzard/inscriptis/blob/master/src/inscriptis/model/tag> package.
Optimizing memory consumption
-----------------------------
Expand Down

0 comments on commit aa1b4cb

Please sign in to comment.