Exemplo n.º 1
0
    def check_single(self, source, target, unit):

        # Strip MarkDown links
        if "md-text" in unit.all_flags:
            target = MD_LINK.sub("", target)

        return bleach.clean(target, **extract_bleach(source)) != target
Exemplo n.º 2
0
 def test_noclose(self):
     self.assertEqual(extract_bleach("<br>"), {
         "tags": {"br"},
         "attributes": {
             "br": set()
         }
     })
Exemplo n.º 3
0
 def test_noattr(self):
     self.assertEqual(extract_bleach("<b>text</b>"), {
         "tags": {"b"},
         "attributes": {
             "b": set()
         }
     })
Exemplo n.º 4
0
    def fix_single_target(self, target, source, unit):
        flags = unit.all_flags
        if "safe-html" not in flags:
            return target, False

        old_target = target

        # Strip MarkDown links
        replacements = {}
        current = 0

        def handle_replace(match):
            nonlocal current, replacements
            current += 1
            replacement = f"@@@@@weblate:{current}@@@@@"
            replacements[replacement] = match.group(0)
            return replacement

        if "md-text" in flags:
            target = MD_LINK.sub(handle_replace, target)

        new_target = bleach.clean(target, **extract_bleach(source))
        for text, replace in replacements.items():
            new_target = new_target.replace(text, replace)
        return new_target, new_target != old_target
Exemplo n.º 5
0
 def test_attrs(self):
     self.assertEqual(
         extract_bleach('<a href="#">t</a>'),
         {
             "tags": {"a"},
             "attributes": {
                 "a": {"href"}
             }
         },
     )
Exemplo n.º 6
0
 def check_single(self, source, target, unit):
     return bleach.clean(target, **extract_bleach(source)) != target
Exemplo n.º 7
0
    def fix_single_target(self, target, source, unit):
        if "safe-html" not in unit.all_flags:
            return target, False

        newtarget = bleach.clean(target, **extract_bleach(source))
        return newtarget, newtarget != target