예제 #1
0
 def test_rescales_an_image(self):
     input = ('<div><img src="a.png" style="max-height:300px;"/></div>')
     expected_output = (
         '<div><img src="a.png" style="max-height:200px;"/></div>')
     self.assertEqual(
         main.scale_images_with_css(input, stub_height_provider(200)),
         expected_output)
예제 #2
0
 def test_scales_through_cloze(self):
     input = '<div>{{c1::<img src="dune.jpg"/>}}</div>'
     expected_output = (
         '<div>{{c1::<img src="dune.jpg" style="max-height:200px;"/>}}' +
         '</div>')
     self.assertEqual(
         main.scale_images_with_css(input, stub_height_provider(200)),
         expected_output)
예제 #3
0
    def test_scales_multiple_images_differently(self):
        # 2 different sizes and also an image that is ignored.
        def height_generator(img: str) -> Optional[int]:
            if img == 'context.jpg':
                return 100
            elif img == 'img.jpg':
                return 200
            else:
                return None

        input = ('<div><img src="context.jpg"/><img src="ignore.jpg"/>' +
                 '<img src="img.jpg"/></div>')
        expected_output = (
            '<div><img src="context.jpg" style="max-height:100px;"/>' +
            '<img src="ignore.jpg"/>' +
            '<img src="img.jpg" style="max-height:200px;"/></div>')
        self.assertEqual(main.scale_images_with_css(input, height_generator),
                         expected_output)
예제 #4
0
 def test_scale_correctly_formats_html(self):
     input = '<div>&lt;img&gt;</div>'
     expected_output = '<div>&lt;img&gt;</div>'
     self.assertEqual(
         main.scale_images_with_css(input, stub_height_provider(200)),
         expected_output)