Skip to content

Commit

Permalink
added further readme for custom converters
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexVonB committed Mar 26, 2024
1 parent 7d0bf46 commit 804a3f8
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,12 @@ Creating Custom Converters

If you have a special usecase that calls for a special conversion, you can
always inherit from ``MarkdownConverter`` and override the method you want to
change:
change.
The function that handles a HTML tag named ``abc`` is called
``convert_abc(self, el, text, convert_as_inline)`` and returns a string
containing the converted HTML tag.
The ``MarkdownConverter`` object will handle the conversion based on the
function names:

.. code:: python
Expand All @@ -173,6 +178,21 @@ change:
def md(html, **options):
return ImageBlockConverter(**options).convert(html)
.. code:: python
from markdownify import MarkdownConverter
class IgnoreParagraphsConverter(MarkdownConverter):
"""
Create a custom MarkdownConverter that ignores paragraphs
"""
def convert_p(self, el, text, convert_as_inline):
return ''
# Create shorthand method for conversion
def md(html, **options):
return IgnoreParagraphsConverter(**options).convert(html)
Command Line Interface
======================
Expand Down

0 comments on commit 804a3f8

Please sign in to comment.