-
-
Notifications
You must be signed in to change notification settings - Fork 65
Unable to call HtmlRenderer's paragraph method #73
Comments
Unfortunately the current design doesn't support overriding parent methods, because I'm planning to address this in the next major version. For now you have to re-implement the paragraph rendering method yourself. See code below for an example.
|
Thanks that would work. |
You can add Here's your code updated with a toc:
|
This code renders the |
There is one problem with this code. Consider the following: # from PIL import Image
# import webp
#
# img = Image.open('/home/x/Downloads/img1.png')
# webp.save_image(img, '/home/x/Downloads/error.webp', quality=80)
import misaka as m
import re
import houdini as h
class CustomHTMLRenderer(m.HtmlRenderer):
def paragraph(self, content):
_prefix_re = re.compile(r'^\s*(!{1,4})\s+')
CLASSES = {
1: 'note',
2: 'info',
3: 'tip',
4: 'warning',
}
match = _prefix_re.match(content)
if match is None:
return '<p>' + content + '</p>\n'
else:
length = len(match.group(1))
value = CLASSES[length]
return '<p class="' + value + '">' + content[length+1:] + '</p>\n'
def render_table_of_contents(text):
rndr = m.HtmlTocRenderer()
md = m.Markdown(rndr)
return md(text)
def render_contents(text, flags):
rndr = CustomHTMLRenderer(nesting_level=6, flags=('escape',))
md = m.Markdown(rndr)
return md(text)
if __name__ == '__main__':
flags = ('escape',)
text = """
# H1
some <b>text</b>
## H2
!!!! some more text
```python
# comment
print("hello")
|
I am creating a customer renderer to adds admonition tags to Markdown.
When
paragraph()
method is called I get this error:The text was updated successfully, but these errors were encountered: