Show More
@@ -714,9 +714,9 b' class ConverterHTML(Converter):' | |||
|
714 | 714 | extension = 'html' |
|
715 | 715 | |
|
716 | 716 | def in_tag(self, tag, src, attrs=None): |
|
717 | attrs = {} if attrs is None else attrs | |
|
718 | 717 | """Return a list of elements bracketed by the given tag""" |
|
719 |
attr_s = ' |
|
|
718 | attr_s = '' if attrs is None else \ | |
|
719 | ' '.join( "%s=%s" % (attr, value) | |
|
720 | 720 | for attr, value in attrs.iteritems() ) |
|
721 | 721 | return ['<%s %s>' % (tag, attr_s), src, '</%s>' % tag] |
|
722 | 722 | |
@@ -726,7 +726,7 b' class ConverterHTML(Converter):' | |||
|
726 | 726 | def _stylesheet(self, fname): |
|
727 | 727 | with io.open(fname, encoding='utf-8') as f: |
|
728 | 728 | s = f.read() |
|
729 | return self.in_tag('style', s, dict(type='text/css')) | |
|
729 | return self.in_tag('style', s, dict(type='"text/css"')) | |
|
730 | 730 | |
|
731 | 731 | def _out_prompt(self, output): |
|
732 | 732 | if output.output_type == 'pyout': |
@@ -736,11 +736,12 b' class ConverterHTML(Converter):' | |||
|
736 | 736 | content = '' |
|
737 | 737 | return ['<div class="prompt output_prompt">%s</div>' % content] |
|
738 | 738 | |
|
739 |
def |
|
|
740 | from pygments.formatters import HtmlFormatter | |
|
741 | ||
|
742 | header = ['<html>', '<head>'] | |
|
739 | def header_body(self): | |
|
740 | """Return the body of the header as a list of strings.""" | |
|
743 | 741 | |
|
742 | from pygments.formatters import HtmlFormatter | |
|
743 | ||
|
744 | header = [] | |
|
744 | 745 | static = os.path.join(path.get_ipython_package_dir(), |
|
745 | 746 | 'frontend', 'html', 'notebook', 'static', |
|
746 | 747 | ) |
@@ -762,27 +763,24 b' class ConverterHTML(Converter):' | |||
|
762 | 763 | # pygments css |
|
763 | 764 | pygments_css = HtmlFormatter().get_style_defs('.highlight') |
|
764 | 765 | header.extend(['<meta charset="UTF-8">']) |
|
765 | header.extend(self.in_tag('style', pygments_css, dict(type='text/css'))) | |
|
766 | header.extend(self.in_tag('style', pygments_css, dict(type='"text/css"'))) | |
|
766 | 767 | |
|
767 | 768 | # TODO: this should be allowed to use local mathjax: |
|
768 | header.extend(self.in_tag('script', '', {'type':'text/javascript', | |
|
769 | header.extend(self.in_tag('script', '', {'type':'"text/javascript"', | |
|
769 | 770 | 'src': '"https://c328740.ssl.cf1.rackcdn.com/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"', |
|
770 | 771 | })) |
|
771 |
with io.open(os.path.join(here, 'js', 'initmathjax.js'), |
|
|
772 | with io.open(os.path.join(here, 'js', 'initmathjax.js'), | |
|
773 | encoding='utf-8') as f: | |
|
772 | 774 | header.extend(self.in_tag('script', f.read(), |
|
773 | 775 | {'type': '"text/javascript"'})) |
|
774 | ||
|
775 | header.extend(['</head>', '<body>']) | |
|
776 | ||
|
777 | 776 | return header |
|
778 | 777 | |
|
778 | def optional_header(self): | |
|
779 | return ['<html>', '<head>'] + self.header_body() + \ | |
|
780 | ['</head>', '<body>'] | |
|
781 | ||
|
779 | 782 | def optional_footer(self): |
|
780 | lines = [] | |
|
781 | lines.extend([ | |
|
782 | '</body>', | |
|
783 | '</html>', | |
|
784 | ]) | |
|
785 | return lines | |
|
783 | return ['</body>', '</html>'] | |
|
786 | 784 | |
|
787 | 785 | @DocInherit |
|
788 | 786 | @text_cell |
@@ -902,6 +900,25 b' class ConverterHTML(Converter):' | |||
|
902 | 900 | return [output.javascript] |
|
903 | 901 | |
|
904 | 902 | |
|
903 | class ConverterBloggerHTML(ConverterHTML): | |
|
904 | """Convert a notebook to html suitable for easy pasting into Blogger. | |
|
905 | ||
|
906 | It generates an html file that has *only* the pure HTML contents, and a | |
|
907 | separate file with `_header` appended to the name with all header contents. | |
|
908 | Typically, the header file only needs to be used once when setting up a | |
|
909 | blog, as the CSS for all posts is stored in a single location in Blogger. | |
|
910 | """ | |
|
911 | ||
|
912 | def optional_header(self): | |
|
913 | with io.open(self.outbase + '_header.html', 'w', | |
|
914 | encoding=self.default_encoding) as f: | |
|
915 | f.write('\n'.join(self.header_body())) | |
|
916 | return [] | |
|
917 | ||
|
918 | def optional_footer(self): | |
|
919 | return [] | |
|
920 | ||
|
921 | ||
|
905 | 922 | class ConverterLaTeX(Converter): |
|
906 | 923 | """Converts a notebook to a .tex file suitable for pdflatex. |
|
907 | 924 | |
@@ -1395,7 +1412,7 b' def cell_to_lines(cell):' | |||
|
1395 | 1412 | return s.split('\n') |
|
1396 | 1413 | |
|
1397 | 1414 | |
|
1398 |
known_formats = "rst (default), html, |
|
|
1415 | known_formats = "rst (default), html, blogger-html, latex, markdown, py" | |
|
1399 | 1416 | |
|
1400 | 1417 | def main(infile, format='rst'): |
|
1401 | 1418 | """Convert a notebook to html in one step""" |
@@ -1411,6 +1428,9 b" def main(infile, format='rst'):" | |||
|
1411 | 1428 | elif format == 'html': |
|
1412 | 1429 | converter = ConverterHTML(infile) |
|
1413 | 1430 | htmlfname = converter.render() |
|
1431 | elif format == 'blogger-html': | |
|
1432 | converter = ConverterBloggerHTML(infile) | |
|
1433 | htmlfname = converter.render() | |
|
1414 | 1434 | elif format == 'latex': |
|
1415 | 1435 | converter = ConverterLaTeX(infile) |
|
1416 | 1436 | latexfname = converter.render() |
General Comments 0
You need to be logged in to leave comments.
Login now