From: Felix Schumacher Date: Sat, 4 Oct 2008 10:52:00 +0000 (+0200) Subject: Richtige Wörter werden jetzt durch spans und hidden input ersetzt. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=refs%2Fheads%2Fmaster;p=lueckentexte.git Richtige Wörter werden jetzt durch spans und hidden input ersetzt. --- diff --git a/lueckentext.py b/lueckentext.py index d476789..82869c7 100644 --- a/lueckentext.py +++ b/lueckentext.py @@ -2,6 +2,11 @@ import re REPLACE_TEXT=re.compile('\[([^\]]+)\]', re.M) +REPLACE_TEMPLATES = { + True: '''%(text)s + ''', + False: '''''', + } def to_html(text="", params={}): result = text @@ -11,9 +16,8 @@ def to_html(text="", params={}): css_class='todo' todo = params.get(key, '') solution = REPLACE_TEXT.search(result).group() - if "[%s]" % todo == solution: - css_class = 'ok' - result = REPLACE_TEXT.sub('' % (css_class, key, params.get(key, '')), result, 1) + is_solution = "[%s]" % todo == solution + result = REPLACE_TEXT.sub(REPLACE_TEMPLATES[is_solution] % { 'text': params.get(key, ''), 'key': key }, result, 1) counter += 1 return '
\n%s\n
' % (result) diff --git a/text1.txt b/text1.txt index 9fff70d..9c3483a 100644 --- a/text1.txt +++ b/text1.txt @@ -28,7 +28,8 @@ deutsche Sprache kennen. ... # doctest: +NORMALIZE_WHITESPACE
Dies ein Lueckentext. -Er mehrere Worte und +Er enthaelt + mehrere Worte und mehrere Zeilen. Damit ausgefuellt werden kann, sollte man deutsche Sprache kennen.