Skip to content

Commit

Permalink
feat: make the markdown rendered configurable in VoilaExporter
Browse files Browse the repository at this point in the history
Example configuration (e.g. in voila.json) could be:

'VoilaExporter': {
    'markdown_renderer_class': 'my.package.MyMarkdownRenderer'
}

Closes #234
  • Loading branch information
maartenbreddels committed Jul 22, 2019
1 parent 0a8deb7 commit 8246c87
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions voila/exporter.py
Expand Up @@ -33,16 +33,18 @@ def image(self, src, title, text):
class VoilaExporter(HTMLExporter):
"""Custom HTMLExporter that inlines the images using VoilaMarkdownRenderer"""

markdown_renderer_class = traitlets.Type('mistune.Renderer').tag(config=True)

# The voila exporter overrides the markdown renderer from the HTMLExporter
# to inline images.

@contextfilter
def markdown2html(self, context, source):
cell = context['cell']
attachments = cell.get('attachments', {})
renderer = VoilaMarkdownRenderer(escape=False, attachments=attachments,
contents_manager=self.contents_manager,
anchor_link_text=self.anchor_link_text)
cls = self.markdown_renderer_class
renderer = cls(escape=False, attachments=attachments,
contents_manager=self.contents_manager,
anchor_link_text=self.anchor_link_text)
return MarkdownWithMath(renderer=renderer).render(source)

# The voila exporter disables the CSSHTMLHeaderPreprocessor from the HTMLExporter.
Expand All @@ -53,6 +55,9 @@ def default_config(self):
'CSSHTMLHeaderPreprocessor': {
'enabled': False
},
'VoilaExporter': {
'markdown_renderer_class': 'voila.exporter.VoilaMarkdownRenderer'
}
})
c.merge(super(VoilaExporter, self).default_config)
return c
Expand Down

0 comments on commit 8246c87

Please sign in to comment.