From fe13bdbb9ea1f8221739958bedd6e9742b743916 Mon Sep 17 00:00:00 2001 From: Felix Schumacher Date: Sat, 4 Oct 2008 12:52:00 +0200 Subject: [PATCH] =?utf8?q?Richtige=20W=C3=B6rter=20werden=20jetzt=20durch?= =?utf8?q?=20spans=20und=20hidden=20input=20ersetzt.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- lueckentext.py | 10 +++++++--- text1.txt | 3 ++- 2 files changed, 9 insertions(+), 4 deletions(-) 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. -- 2.11.0