Skip to content

Commit

Permalink
Works when there's nothing but a string to parse (not HTML tags).
Browse files Browse the repository at this point in the history
  • Loading branch information
BertrandBordage committed Jun 30, 2013
1 parent 1887230 commit 96078ae
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 8 deletions.
11 changes: 8 additions & 3 deletions terms/html.py
Expand Up @@ -58,9 +58,14 @@ def is_navigable_string(navigable_string):
def html_content_iterator(parent_tag, replace_regexp):
if not parent_tag.find(text=replace_regexp):
return
for tag in parent_tag.find_all(
name=TAGS_REGEXP, class_=valid_class, id=valid_id,
recursive=False):
valid_tags = parent_tag.find_all(
name=TAGS_REGEXP, class_=valid_class, id=valid_id,
recursive=False)

if not valid_tags:
yield parent_tag

for tag in valid_tags:
if not tag.find(text=replace_regexp):
continue
if tag.find(text=replace_regexp, recursive=False):
Expand Down
10 changes: 5 additions & 5 deletions terms/tests/terms/2_after.html
@@ -1,7 +1,7 @@
<html>
<body>
Ow… Look at this cute
<a onclick="window.open('{{ term.get_absolute_url }}', '', 'height=450px, width=700px');"
style="cursor: help;">indricothere</a>!
</body>
<body>
Ow… Look at this cute
<a onclick="window.open('{{ term.get_absolute_url }}', '', 'height=450px, width=700px');"
style="cursor: help;">indricothere</a>!
</body>
</html>
5 changes: 5 additions & 0 deletions terms/tests/terms/3_after.html
@@ -0,0 +1,5 @@
<p>
I would like <strong>a better world</strong>.
But that won't be cool.
In french we say the word <q><a href="{{ term.url }}">optimisé</a></q>.
</p>
5 changes: 5 additions & 0 deletions terms/tests/terms/3_before.html
@@ -0,0 +1,5 @@
<p>
I would like <strong>a better world</strong>.
But that won't be cool.
In french we say the word <q>optimisé</q>.
</p>
1 change: 1 addition & 0 deletions terms/tests/terms/4_after.html
@@ -0,0 +1 @@
<a href="{{ term.url }}">optimized</a>
1 change: 1 addition & 0 deletions terms/tests/terms/4_before.html
@@ -0,0 +1 @@
optimized
16 changes: 16 additions & 0 deletions terms/tests/terms/__init__.py
@@ -1,3 +1,6 @@
# coding: utf-8

from __future__ import unicode_literals
import os
from django.core.urlresolvers import reverse
from django.template import Template, Context
Expand Down Expand Up @@ -30,6 +33,9 @@ def setUp(self):
self.term2 = Term.objects.create(
name='indricothere',
definition='A nice mix between a rhino and a giraffe.')
self.term3 = Term.objects.create(
name='optimiser|optimize|optimise|optimisé|optimized|optimised',
url='/optimisation')

def assertDetailView(self, term, status_code=200):
self.assertURL(term.get_absolute_url(), status_code=status_code)
Expand Down Expand Up @@ -67,6 +73,16 @@ def test2(self):

self.assertCachedRegex()

def test3(self):
self.assertHTMLEqual(
replace_terms(read_file('3_before.html')),
read_file('3_after.html', {'term': self.term3}))
self.assertDetailView(self.term3, status_code=404)

self.assertHTMLEqual(
replace_terms(read_file('4_before.html')),
read_file('4_after.html', {'term': self.term3}))

def testAdminRendering(self):
for term in Term.objects.all():
self.assertURL(
Expand Down

0 comments on commit 96078ae

Please sign in to comment.