Render Markdown in code block and rendered output in result code block.
(src="", language="", class_name=None, options=None, md="", **kwargs)
| 65 | |
| 66 | |
| 67 | def md_render(src="", language="", class_name=None, options=None, md="", **kwargs): |
| 68 | """ Render Markdown in code block and rendered output in result code block. """ |
| 69 | try: |
| 70 | fm, text = get_frontmatter(src) |
| 71 | html = markdown.markdown( |
| 72 | text, |
| 73 | extensions=fm.get('extensions', []), |
| 74 | extension_configs=fm.get('extension_configs', {}) |
| 75 | ) |
| 76 | except Exception: |
| 77 | import traceback |
| 78 | print(traceback.format_exc()) |
| 79 | raise |
| 80 | |
| 81 | options = options or {} |
| 82 | if 'title' not in options: |
| 83 | options['title'] = 'Markdown Source' |
| 84 | result_options = options.copy() |
| 85 | result_options['title'] = 'HTML Output' |
| 86 | |
| 87 | source = md.preprocessors['fenced_code_block'].highlight(text, 'markdown', options, md, **kwargs) |
| 88 | output = md.preprocessors['fenced_code_block'].highlight(html, 'html', result_options, md, **kwargs) |
| 89 | return f'{source}\n<div class="result">{output}</div>' |
| 90 | |
| 91 | |
| 92 | class PyExecNamespace(): |
nothing calls this directly
no test coverage detected