Example #1
0
    def test_presenter_notes(self):
        g = Generator(os.path.join(DATA_DIR, 'test.md'))
        svars = g.get_slide_vars("<h1>heading</h1>\n<p>foo</p>\n"
                                 "<h1>Presenter Notes</h1>\n<p>bar</p>\n")
        self.assertEqual(svars['presenter_notes'], "<p>bar</p>")

        # Check that presenter notes work even if the slide has no heading.
        # For example, if it is only an image:

        g = Generator(os.path.join(DATA_DIR, 'test.md'))
        svars = g.get_slide_vars("<p>foo</p>\n"
                                 "<h1>Presenter Notes</h1>\n<p>bar</p>\n")
Example #2
0
 def test_add_user_assets(self):
     base_dir = os.path.join(DATA_DIR, 'test.md')
     g = Generator(base_dir, logger=self.logtest)
     g.add_user_css(os.path.join(DATA_DIR, 'test.css'))
     g.add_user_js(os.path.join(DATA_DIR, 'test.js'))
     self.assertEqual(g.user_css[0]['contents'], '* {color: red;}')
     self.assertEqual(g.user_js[0]['contents'], "alert('foo');")
Example #3
0
 def test_get_template_vars(self):
     g = Generator(os.path.join(DATA_DIR, 'test.md'))
     svars = g.get_template_vars([{'title': "slide1", 'level': 1},
                                  {'title': "slide2", 'level': 1},
                                  {'title': None, 'level': 1},
     ])
     self.assertEqual(svars['head_title'], 'slide1')
Example #4
0
 def test_get_slide_vars(self):
     g = Generator(os.path.join(DATA_DIR, 'test.md'))
     svars = g.get_slide_vars("<h1>heading</h1>\n<p>foo</p>\n<p>bar</p>\n")
     self.assertEqual(svars['title'], 'heading')
     self.assertEqual(svars['level'], 1)
     self.assertEqual(svars['header'], '<h1>heading</h1>')
     self.assertEqual(svars['content'], '<p>foo</p>\n<p>bar</p>')
     self.assertEqual(svars['source'], {})
     self.assertEqual(svars['classes'], [])
Example #5
0
def run(input_file, options):
    generator = Generator(input_file,
                          options.destination_file,
                          options.theme,
                          direct=options.direct,
                          debug=options.debug,
                          verbose=options.verbose,
                          embed=options.embed,
                          encoding=options.encoding,
                          logger=log)
    generator.execute()
Example #6
0
def open_slides():
    slides_path = file_in_dir('slides.md')
    output_path = 'pipped-slides.html'
    Generator(
        slides_path, **{
            'embed': True,
            'relative': True,
            'destination_file': output_path,
            'theme': file_in_dir('avalanche'),
        }).execute()
    call(['open', output_path])
Example #7
0
 def test_process_macros(self):
     g = Generator(os.path.join(DATA_DIR, 'test.md'))
     # Notes
     r = g.process_macros('<p>foo</p>\n<p>.notes: bar</p>\n<p>baz</p>')
     self.assertEqual(r[0].find('<p class="notes">bar</p>'), 11)
     self.assertEqual(r[1], [u'has_notes'])
     # FXs
     content = '<p>foo</p>\n<p>.fx: blah blob</p>\n<p>baz</p>'
     r = g.process_macros(content)
     self.assertEqual(r[0], '<p>foo</p>\n<p>baz</p>')
     self.assertEqual(r[1][0], 'blah')
     self.assertEqual(r[1][1], 'blob')
Example #8
0
    def test_macro_alert(self):
        g = Generator(os.path.join(DATA_DIR, 'test.md'))
        # .info
        r = g.process_macros('<p>foo</p>\n<p>.info: bar</p>\n<p>baz</p>')
        self.assertEqual(r[0].find('<p class="alert alert-info">bar</p>'), 11)
        self.assertEqual(r[1], [u'has_alert'])

        # .danger
        r = g.process_macros('<p>foo</p>\n<p>.danger: bar</p>\n<p>baz</p>')
        self.assertEqual(r[0].find('<p class="alert alert-danger">bar</p>'),
                         11)
        self.assertEqual(r[1], [u'has_alert'])
Example #9
0
    def test_inputencoding(self):
        path = os.path.join(DATA_DIR, 'encoding.rst')
        g = Generator(path, encoding='koi8_r')
        content = g.render()

        # check that the string is utf_8
        self.assertTrue(re.findall(u'русский', content, flags=re.UNICODE))
        g.execute()
        with codecs.open(g.destination_file, encoding='utf_8') as file_object:
            file_contents = file_object.read()
        # check that the file was properly encoded in utf_8
        self.assertTrue(re.findall(u'русский', file_contents,
                                   flags=re.UNICODE))
Example #10
0
    def test_register_macro(self):
        g = Generator(os.path.join(DATA_DIR, 'test.md'))

        class SampleMacro(macro.Macro):
            pass

        g.register_macro(SampleMacro)
        self.assertTrue(SampleMacro in g.macros)

        def plop(foo):
            pass

        self.assertRaises(TypeError, g.register_macro, plop)
Example #11
0
    def test_process_animation_macros(self):
        g = Generator(os.path.join(DATA_DIR, 'test.md'))

        r = g.process_macros('''<ul class="xx">
<li>Markdown .fx:rollIn</li>
<li>ReStructured Text</li>
<li>Textile</li>
</ul>''')
        self.assertEqual(r[0], '''<ul class="rollIn xx">
<li class="building">Markdown </li>
<li class="tobuild">ReStructured Text</li>
<li class="tobuild">Textile</li>
</ul>''')
Example #12
0
 def test_get_toc(self):
     base_dir = os.path.join(DATA_DIR, 'test.md')
     g = Generator(base_dir, logger=self.logtest)
     g.add_toc_entry('Section 1', 1, 1)
     g.add_toc_entry('Section 1.1', 2, 2)
     g.add_toc_entry('Section 1.2', 2, 3)
     g.add_toc_entry('Section 2', 1, 4)
     g.add_toc_entry('Section 2.1', 2, 5)
     g.add_toc_entry('Section 3', 1, 6)
     toc = g.toc
     self.assertEqual(len(toc), 3)
     self.assertEqual(toc[0]['title'], 'Section 1')
     self.assertEqual(len(toc[0]['sub']), 2)
     self.assertEqual(toc[0]['sub'][1]['title'], 'Section 1.2')
     self.assertEqual(toc[1]['title'], 'Section 2')
     self.assertEqual(len(toc[1]['sub']), 1)
     self.assertEqual(toc[2]['title'], 'Section 3')
     self.assertEqual(len(toc[2]['sub']), 0)
Example #13
0
 def test_unicode(self):
     g = Generator(os.path.join(DATA_DIR, 'test.md'))
     g.execute()
     s = g.render()
     self.assertTrue(s.find('<pre>') != -1)
     self.assertEqual(len(re.findall('<pre><span', s)), 3)
Example #14
0
 def test_skip_presenter_notes(self):
     g = Generator(os.path.join(DATA_DIR, 'test.md'), presenter_notes=False)
     svars = g.get_slide_vars("<h1>heading</h1>\n<p>foo</p>\n"
                              "<h1>Presenter Notes</h1>\n<p>bar</p>\n")
     self.assertEqual(svars['presenter_notes'], None)
Example #15
0
def run(input_file, options):
    """ Runs the Generator using parsed options.
    """
    options.logger = log
    generator = Generator(input_file, **options.__dict__)
    generator.execute()