Skip to content
Browse files

Launch version for OGN7

  • Loading branch information...
1 parent 6751904 commit b3a9c5acbdf13c5cfd37b76dd5d2c26fae6849cd Tom Dyson committed
Showing with 26 additions and 5 deletions.
  1. +4 −1 urls.py
  2. +12 −1 views.py
  3. +10 −3 wordoff.py
View
5 urls.py
@@ -4,5 +4,8 @@
urlpatterns = patterns('',
(r'^static/(.+)$', 'django.views.static.serve', {'document_root': MEDIA_ROOT}),
(r'^$', 'views.index'),
- (r'^clean$', 'views.clean')
+ (r'^clean$', 'views.clean'),
+ (r'^api/clean$', 'views.clean_api'),
+ (r'^about$', 'views.about'),
+ (r'^api$', 'views.about_api'),
)
View
13 views.py
@@ -9,4 +9,15 @@ def index(request):
def clean(request):
input = request.POST["html"]
cleaned = superClean(input)
- return render_to_response('cleaned.html', locals())
+ return render_to_response('cleaned.html', locals())
+
+def clean_api(request):
+ input = request.POST["html"]
+ cleaned = superClean(input)
+ return render_to_response('api.html', locals())
+
+def about(request):
+ return render_to_response('about.html')
+
+def about_api(request):
+ return render_to_response('about-api.html')
View
13 wordoff.py
@@ -4,15 +4,22 @@
import re
import unicodedata
-match_attributes = re.compile(r'<([a-zA-Z]+[0-9]?) [^>]+>')
+match_tags_with_attributes = re.compile(r'<([a-zA-Z]+[0-9]?) [^>]+>')
match_spans = re.compile(r'</?span[^>]*>')
match_divs = re.compile(r'</?div[^>]*>')
match_empty_elements = re.compile(r'<([a-zA-Z]+)>\s*</\1>')
match_multiple_linebreaks = re.compile(r'(\n\s*){3,}')
+def ignore_some_tags(matchobj):
+ # don't strip attributes for <a>s
+ if matchobj.group(1) == 'a':
+ return matchobj.group(0)
+ else:
+ return '<%s>' % matchobj.group(1)
+
def stripAttributes(str):
# remove attributes from all tags
- return match_attributes.sub(r'<\1>',str)
+ return match_tags_with_attributes.sub(ignore_some_tags,str)
def stripSpans(str):
# remove spans
@@ -33,7 +40,7 @@ def stripEmptyElements(str):
def xenophobia(str):
# convert everything to ascii
utf8_string = str.decode('utf-8')
- return unicodedata.normalize('NFKD', utf8_string).encode('iso-8859-1', 'ignore')
+ return unicodedata.normalize('NFKD', utf8_string).encode('ascii', 'ignore')
def superClean(str):
clean = stripAttributes(str)

0 comments on commit b3a9c5a

Please sign in to comment.
Something went wrong with that request. Please try again.