Skip to content

Commit 804a3f8

Browse files
committed
added further readme for custom converters
1 parent 7d0bf46 commit 804a3f8

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

README.rst

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,12 @@ Creating Custom Converters
156156

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

161166
.. code:: python
162167
@@ -173,6 +178,21 @@ change:
173178
def md(html, **options):
174179
return ImageBlockConverter(**options).convert(html)
175180
181+
.. code:: python
182+
183+
from markdownify import MarkdownConverter
184+
185+
class IgnoreParagraphsConverter(MarkdownConverter):
186+
"""
187+
Create a custom MarkdownConverter that ignores paragraphs
188+
"""
189+
def convert_p(self, el, text, convert_as_inline):
190+
return ''
191+
192+
# Create shorthand method for conversion
193+
def md(html, **options):
194+
return IgnoreParagraphsConverter(**options).convert(html)
195+
176196
177197
Command Line Interface
178198
======================

0 commit comments

Comments
 (0)