コード例 #1
0
 def test_dont_highlight_highlightings(self):
     self.assertEquals(
         highlight(HTML_CONTENT.replace('world', 'highlight'),
                   ['hello', 'highlight']),
         '<html><body><p><span class="highlight term-1">Hello</span> '
         '<span class="highlight term-2">highlight</span> !</p>'
         '</body></html>')
コード例 #2
0
ファイル: tests.py プロジェクト: Fantomas42/django-sekh
 def test_dont_highlight_highlightings(self):
     self.assertEquals(
         highlight(HTML_CONTENT.replace('world', 'highlight'),
                   ['hello', 'highlight']),
         '<html><body><p><span class="highlight term-1">Hello</span> '
         '<span class="highlight term-2">highlight</span> !</p>'
         '</body></html>')
コード例 #3
0
ファイル: sekh_tags.py プロジェクト: movermeyer/django-sekh
    def render(self, context):
        output = self.nodelist.render(context)

        terms = self.terms
        if terms[0] == terms[-1] and terms[0] in ("'", '"'):
            terms = terms[1:-1]
        else:
            terms = self.terms_var.resolve(context)

        return highlight(output, remove_duplicates(RE_ARG_SPLIT.split(terms)))
コード例 #4
0
ファイル: sekh_tags.py プロジェクト: Fantomas42/django-sekh
    def render(self, context):
        output = self.nodelist.render(context)

        terms = self.terms
        if terms[0] == terms[-1] and terms[0] in ("'", '"'):
            terms = terms[1:-1]
        else:
            terms = self.terms_var.resolve(context)

        return highlight(output,
                         remove_duplicates(RE_ARG_SPLIT.split(terms)))
コード例 #5
0
    def process_response(self, request, response):
        """
        Transform the HTML if keywords are present.
        """
        if (response.status_code != 200
                or not 'text/html' in response['Content-Type']):
            return response

        referrer = request.META.get('HTTP_REFERER')
        engine, domain, terms = self.parse_search(referrer)

        for GET_varname in GET_VARNAMES:
            if request.GET.get(GET_varname):
                terms.extend(request.GET[GET_varname].split())

        if not terms:
            return response

        response.content = highlight(response.content,
                                     remove_duplicates(terms))
        return response
コード例 #6
0
ファイル: middleware.py プロジェクト: Fantomas42/django-sekh
    def process_response(self, request, response):
        """
        Transform the HTML if keywords are present.
        """
        if (response.status_code != 200 or
                not 'text/html' in response['Content-Type']):
            return response

        referrer = request.META.get('HTTP_REFERER')
        engine, domain, terms = self.parse_search(referrer)

        for GET_varname in GET_VARNAMES:
            if request.GET.get(GET_varname):
                terms.extend(request.GET[GET_varname].split())

        if not terms:
            return response

        response.content = highlight(response.content,
                                     remove_duplicates(terms))
        return response
コード例 #7
0
 def test_highlight_multiple_in_one_markup(self):
     self.assertEquals(
         highlight(HTML_CONTENT.replace('!', 'hello'), ['hello']),
         '<html><body><p><span class="highlight term-1">Hello</span> '
         'world <span class="highlight term-1">hello</span></p>'
         '</body></html>')
コード例 #8
0
 def test_highlight_none(self):
     self.assertEquals(highlight(HTML_CONTENT, []), HTML_CONTENT)
コード例 #9
0
 def test_highlight_case(self):
     self.assertEquals(
         highlight(HTML_CONTENT, ['HELLO', 'World']),
         '<html><body><p><span class="highlight term-1">Hello</span> '
         '<span class="highlight term-2">world</span> !</p></body></html>')
コード例 #10
0
 def test_dont_highlight_protected_markups(self):
     self.assertEquals(
         highlight(HTML_CONTENT.replace('world', '<pre>world</pre>'),
                   ['world']),
         '<html><body><p>Hello <pre>world</pre> !</p></body></html>')
コード例 #11
0
ファイル: sekh_tags.py プロジェクト: movermeyer/django-sekh
def highlight_filter(value, terms, autoescape=None):
    esc = autoescape and conditional_escape or (lambda x: x)
    return mark_safe(
        highlight(esc(value), remove_duplicates(RE_ARG_SPLIT.split(terms))))
コード例 #12
0
ファイル: tests.py プロジェクト: Fantomas42/django-sekh
 def test_highlight(self):
     self.assertEquals(
         highlight(HTML_CONTENT, ['Hello', 'world']),
         '<html><body><p><span class="highlight term-1">Hello</span> '
         '<span class="highlight term-2">world</span> !</p></body></html>')
コード例 #13
0
ファイル: tests.py プロジェクト: Fantomas42/django-sekh
 def test_dont_highlight_protected_markups(self):
     self.assertEquals(
         highlight(HTML_CONTENT.replace('world', '<pre>world</pre>'),
                   ['world']),
         '<html><body><p>Hello <pre>world</pre> !</p></body></html>')
コード例 #14
0
ファイル: tests.py プロジェクト: Fantomas42/django-sekh
 def test_highlight_multiple_in_one_markup(self):
     self.assertEquals(
         highlight(HTML_CONTENT.replace('!', 'hello'), ['hello']),
         '<html><body><p><span class="highlight term-1">Hello</span> '
         'world <span class="highlight term-1">hello</span></p>'
         '</body></html>')
コード例 #15
0
ファイル: tests.py プロジェクト: Fantomas42/django-sekh
 def test_highlight_none(self):
     self.assertEquals(
         highlight(HTML_CONTENT, []), HTML_CONTENT)
コード例 #16
0
ファイル: sekh_tags.py プロジェクト: Fantomas42/django-sekh
def highlight_filter(value, terms, autoescape=None):
    esc = autoescape and conditional_escape or (lambda x: x)
    return mark_safe(highlight(esc(value),
                               remove_duplicates(RE_ARG_SPLIT.split(terms))))