Example #1
0
def htmleqn(formula, hr=True):
    """Format a formula to appear as if it would have been outsourced into an
    external file."""
    return '%s\n<p id="%s"><pre>%s</pre></span></p>\n' % (
        ("<hr/>" if hr else ""),
        htmlhandling.gen_id(formula),
        formula,
    )
Example #2
0
 def test_that_link_to_external_image_points_to_file_basepath_and_formula(self):
     os.mkdir("basepath")
     with htmlhandling.HtmlImageFormatter("basepath") as img:
         formatted_img = img.format_excluded(self.pos, "\\tau\\tau", "foo.png")
         expected_id = htmlhandling.gen_id("\\tau\\tau")
     # find linked formula path
     href = re.search('href="(.*?)"', formatted_img)
     self.assertTrue(href != None)
     # extract path and id from it
     self.assertTrue("#" in href.groups()[0])
     path, id = href.groups()[0].split("#")
     self.assertEqual(path, "basepath/" + excl_filename)
     self.assertEqual(id, expected_id)
Example #3
0
 def test_that_link_to_external_image_points_to_file_basepath_and_formula(self):
     os.mkdir('basepath')
     with htmlhandling.HtmlImageFormatter('basepath') as img:
         formatted_img = img.format_excluded(self.pos, '\\tau\\tau', 'foo.png')
         expected_id = htmlhandling.gen_id('\\tau\\tau')
     external_file = read(os.path.join('basepath', excl_filename), 'r')
     # find linked formula path
     href = re.search('href="(.*?)"', formatted_img)
     self.assertTrue(href != None)
     # extract path and id from it
     self.assertTrue('#' in href.groups()[0])
     path, id = href.groups()[0].split('#')
     self.assertEqual(path, 'basepath/' + excl_filename)
     self.assertEqual(id, expected_id)
Example #4
0
    def test_that_link_to_external_image_points_to_file_and_formula(self):
        with htmlhandling.HtmlImageFormatter() as img:
            formatted_img = img.format_excluded(self.pos, "\\tau\\tau", "foo.png")
            expected_id = htmlhandling.gen_id("\\tau\\tau")
        external_file = read(excl_filename, "r", encoding="utf-8")
        # find linked formula path
        href = re.search('href="(.*?)"', formatted_img)
        self.assertTrue(href != None)
        # extract path and id from it
        self.assertTrue("#" in href.groups()[0])
        path, id = href.groups()[0].split("#")
        self.assertEqual(path, excl_filename)
        self.assertEqual(id, expected_id)

        # check external file
        self.assertTrue("<p id" in external_file)
        self.assertTrue('="' + expected_id in external_file)
Example #5
0
    def test_that_link_to_external_image_points_to_file_and_formula(self):
        with htmlhandling.HtmlImageFormatter() as img:
            formatted_img = img.format_excluded(self.pos, '\\tau\\tau', 'foo.png')
            expected_id = htmlhandling.gen_id('\\tau\\tau')
        external_file = read(excl_filename, 'r', encoding='utf-8')
        # find linked formula path
        href = re.search('href="(.*?)"', formatted_img)
        self.assertTrue(href != None)
        # extract path and id from it
        self.assertTrue('#' in href.groups()[0])
        path, id = href.groups()[0].split('#')
        self.assertEqual(path, excl_filename)
        self.assertEqual(id, expected_id)

        # check external file
        self.assertTrue('<p id' in external_file)
        self.assertTrue('="'+expected_id in external_file)
Example #6
0
 def test_id_contains_no_special_characters(self):
     data = htmlhandling.gen_id('\\tau!\'{}][~^')
     for character in {'!', "'", '\\', '{', '}'}:
         self.assertFalse(character in data)
Example #7
0
 def test_that_ids_start_with_letter(self):
     id = htmlhandling.gen_id("{}\\[]ÖÖÖö9343...·tau")
     self.assertTrue(id[0].isalpha())
Example #8
0
 def test_that_ids_are_max_150_characters_wide(self):
     id = htmlhandling.gen_id("\\alpha\\cdot\\gamma + " * 999)
     self.assertTrue(len(id) == 150)
Example #9
0
 def test_that_same_characters_are_not_repeated(self):
     id = htmlhandling.gen_id("jo{{{{{{{{ha")
     self.assertEqual(id, "jo_ha")
Example #10
0
 def test_formula_can_consist_only_of_numbers_and_id_is_generated(self):
     data = htmlhandling.gen_id("9*8*7=504")
     self.assertTrue(data.startswith("form"))
     self.assertTrue(data.endswith("504"))
Example #11
0
 def test_id_contains_no_special_characters(self):
     data = htmlhandling.gen_id("\\tau!'{}][~^")
     for character in {"!", "'", "\\", "{", "}"}:
         self.assertFalse(character in data)
Example #12
0
 def test_id_contains_no_special_characters(self):
     data = htmlhandling.gen_id('\\tau!\'{}][~^')
     for character in {'!', "'", '\\', '{', '}'}:
         self.assertFalse(character in data)
Example #13
0
 def test_that_same_characters_are_not_repeated(self):
     id = htmlhandling.gen_id("jo{{{{{{{{ha")
     self.assertEqual(id, "jo_ha")
Example #14
0
 def test_formula_can_consist_only_of_numbers_and_id_is_generated(self):
     data = htmlhandling.gen_id('9*8*7=504')
     self.assertTrue(data.startswith('form'))
     self.assertTrue(data.endswith('504'))
Example #15
0
def htmleqn(formula, hr=True):
    """Format a formula to appear as if it would have been outsourced into an
    external file."""
    return '%s\n<p id="%s"><pre>%s</pre></span></p>\n' % (\
            ('<hr/>' if hr else ''), htmlhandling.gen_id(formula), formula)
Example #16
0
 def test_that_ids_are_max_150_characters_wide(self):
     id = htmlhandling.gen_id('\\alpha\\cdot\\gamma + ' * 999)
     self.assertTrue(len(id) == 150)
Example #17
0
 def test_that_ids_start_with_letter(self):
     id = htmlhandling.gen_id('{}\\[]ÖÖÖö9343...·tau')
     self.assertTrue(id[0].isalpha())