##// END OF EJS Templates
Add first cut of markdown converter.x
Fernando Perez -
Show More
@@ -459,6 +459,105 b' class ConverterRST(Converter):'
459 return rst_directive('.. raw:: javascript', output.javascript)
459 return rst_directive('.. raw:: javascript', output.javascript)
460
460
461
461
462 class ConverterMarkdown(Converter):
463 extension = 'md'
464
465 @DocInherit
466 def render_heading(self, cell):
467 return ['{0} {1}'.format('#'*cell.level, cell.source), '']
468
469 @DocInherit
470 def render_code(self, cell):
471 if not cell.input:
472 return []
473 lines = []
474 #lines.append('----')
475 lines.extend(['*In[%s]:*' % cell.prompt_number, ''])
476 lines.extend([indent(cell.input), ''])
477 if cell.outputs:
478 lines.extend(['==>', ''])
479 for output in cell.outputs:
480 conv_fn = self.dispatch(output.output_type)
481 lines.extend(conv_fn(output))
482
483 #lines.append('----')
484 lines.append('')
485 return lines
486
487 @DocInherit
488 def render_markdown(self, cell):
489 return [cell.source, '']
490 #return [markdown2rst(cell.source)]
491
492 @DocInherit
493 def render_raw(self, cell):
494 if self.raw_as_verbatim:
495 return [indent(cell.source), '']
496 else:
497 return [cell.source, '']
498
499 @DocInherit
500 def render_pyout(self, output):
501 lines = []
502 #lines.extend(['*Out[%s]:*' % output.prompt_number, ''])
503
504 # output is a dictionary like object with type as a key
505 if 'latex' in output:
506 pass
507
508 if 'text' in output:
509 lines.extend([indent(output.text)])
510
511 lines.append('')
512 return lines
513
514 @DocInherit
515 def render_pyerr(self, output):
516 # Note: a traceback is a *list* of frames.
517 return [indent(remove_ansi('\n'.join(output.traceback))), '']
518
519 @DocInherit
520 def _img_lines(self, img_file):
521 return ['', '![image](%s)' % img_file, '']
522
523 @DocInherit
524 def render_display_format_text(self, output):
525 return [indent(output.text)]
526
527 @DocInherit
528 def _unknown_lines(self, data):
529 return ['Warning: Unknown cell', data]
530
531 def render_display_format_html(self, output):
532 """render the html part of an output
533
534 Returns list.
535 """
536 return [output.html]
537
538 def render_display_format_latex(self, output):
539 """render the latex part of an output
540
541 Returns list.
542 """
543 return ['LaTeX::', indent(output.latex)]
544
545 def render_display_format_json(self, output):
546 """render the json part of an output
547
548 Returns list.
549 """
550 return ['JSON:', indent(output.json)]
551
552
553 def render_display_format_javascript(self, output):
554 """render the javascript part of an output
555
556 Returns list.
557 """
558 return ['JavaScript:', indent(output.javascript)]
559
560
462 class ConverterQuickHTML(Converter):
561 class ConverterQuickHTML(Converter):
463 extension = 'html'
562 extension = 'html'
464
563
@@ -996,7 +1095,7 b' def cell_to_lines(cell):'
996 return s.split('\n')
1095 return s.split('\n')
997
1096
998
1097
999 known_formats = "rst (default), html, quick-html, latex"
1098 known_formats = "rst (default), html, quick-html, latex, markdown"
1000
1099
1001 def main(infile, format='rst'):
1100 def main(infile, format='rst'):
1002 """Convert a notebook to html in one step"""
1101 """Convert a notebook to html in one step"""
@@ -1006,6 +1105,9 b" def main(infile, format='rst'):"
1006 if format == 'rst':
1105 if format == 'rst':
1007 converter = ConverterRST(infile)
1106 converter = ConverterRST(infile)
1008 converter.render()
1107 converter.render()
1108 elif format == 'markdown':
1109 converter = ConverterMarkdown(infile)
1110 converter.render()
1009 elif format == 'html':
1111 elif format == 'html':
1010 #Currently, conversion to html is a 2 step process, nb->rst->html
1112 #Currently, conversion to html is a 2 step process, nb->rst->html
1011 converter = ConverterRST(infile)
1113 converter = ConverterRST(infile)
General Comments 0
You need to be logged in to leave comments. Login now