##// END OF EJS Templates
Add blogger-html format option....
Fernando Perez -
Show More
@@ -714,9 +714,9 b' class ConverterHTML(Converter):'
714 extension = 'html'
714 extension = 'html'
715
715
716 def in_tag(self, tag, src, attrs=None):
716 def in_tag(self, tag, src, attrs=None):
717 attrs = {} if attrs is None else attrs
718 """Return a list of elements bracketed by the given tag"""
717 """Return a list of elements bracketed by the given tag"""
719 attr_s = ' '.join( "%s=%s" % (attr, value)
718 attr_s = '' if attrs is None else \
719 ' '.join( "%s=%s" % (attr, value)
720 for attr, value in attrs.iteritems() )
720 for attr, value in attrs.iteritems() )
721 return ['<%s %s>' % (tag, attr_s), src, '</%s>' % tag]
721 return ['<%s %s>' % (tag, attr_s), src, '</%s>' % tag]
722
722
@@ -726,7 +726,7 b' class ConverterHTML(Converter):'
726 def _stylesheet(self, fname):
726 def _stylesheet(self, fname):
727 with io.open(fname, encoding='utf-8') as f:
727 with io.open(fname, encoding='utf-8') as f:
728 s = f.read()
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 def _out_prompt(self, output):
731 def _out_prompt(self, output):
732 if output.output_type == 'pyout':
732 if output.output_type == 'pyout':
@@ -736,11 +736,12 b' class ConverterHTML(Converter):'
736 content = ''
736 content = ''
737 return ['<div class="prompt output_prompt">%s</div>' % content]
737 return ['<div class="prompt output_prompt">%s</div>' % content]
738
738
739 def optional_header(self):
739 def header_body(self):
740 from pygments.formatters import HtmlFormatter
740 """Return the body of the header as a list of strings."""
741
742 header = ['<html>', '<head>']
743
741
742 from pygments.formatters import HtmlFormatter
743
744 header = []
744 static = os.path.join(path.get_ipython_package_dir(),
745 static = os.path.join(path.get_ipython_package_dir(),
745 'frontend', 'html', 'notebook', 'static',
746 'frontend', 'html', 'notebook', 'static',
746 )
747 )
@@ -762,27 +763,24 b' class ConverterHTML(Converter):'
762 # pygments css
763 # pygments css
763 pygments_css = HtmlFormatter().get_style_defs('.highlight')
764 pygments_css = HtmlFormatter().get_style_defs('.highlight')
764 header.extend(['<meta charset="UTF-8">'])
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 # TODO: this should be allowed to use local mathjax:
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 'src': '"https://c328740.ssl.cf1.rackcdn.com/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"',
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'), encoding='utf-8') as f:
772 with io.open(os.path.join(here, 'js', 'initmathjax.js'),
773 encoding='utf-8') as f:
772 header.extend(self.in_tag('script', f.read(),
774 header.extend(self.in_tag('script', f.read(),
773 {'type': '"text/javascript"'}))
775 {'type': '"text/javascript"'}))
774
775 header.extend(['</head>', '<body>'])
776
777 return header
776 return header
778
777
778 def optional_header(self):
779 return ['<html>', '<head>'] + self.header_body() + \
780 ['</head>', '<body>']
781
779 def optional_footer(self):
782 def optional_footer(self):
780 lines = []
783 return ['</body>', '</html>']
781 lines.extend([
782 '</body>',
783 '</html>',
784 ])
785 return lines
786
784
787 @DocInherit
785 @DocInherit
788 @text_cell
786 @text_cell
@@ -902,6 +900,25 b' class ConverterHTML(Converter):'
902 return [output.javascript]
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 class ConverterLaTeX(Converter):
922 class ConverterLaTeX(Converter):
906 """Converts a notebook to a .tex file suitable for pdflatex.
923 """Converts a notebook to a .tex file suitable for pdflatex.
907
924
@@ -1395,7 +1412,7 b' def cell_to_lines(cell):'
1395 return s.split('\n')
1412 return s.split('\n')
1396
1413
1397
1414
1398 known_formats = "rst (default), html, quick-html, latex, markdown, py"
1415 known_formats = "rst (default), html, blogger-html, latex, markdown, py"
1399
1416
1400 def main(infile, format='rst'):
1417 def main(infile, format='rst'):
1401 """Convert a notebook to html in one step"""
1418 """Convert a notebook to html in one step"""
@@ -1411,6 +1428,9 b" def main(infile, format='rst'):"
1411 elif format == 'html':
1428 elif format == 'html':
1412 converter = ConverterHTML(infile)
1429 converter = ConverterHTML(infile)
1413 htmlfname = converter.render()
1430 htmlfname = converter.render()
1431 elif format == 'blogger-html':
1432 converter = ConverterBloggerHTML(infile)
1433 htmlfname = converter.render()
1414 elif format == 'latex':
1434 elif format == 'latex':
1415 converter = ConverterLaTeX(infile)
1435 converter = ConverterLaTeX(infile)
1416 latexfname = converter.render()
1436 latexfname = converter.render()
General Comments 0
You need to be logged in to leave comments. Login now