Merge lp:~franku/widelands-website/smiley-and-codeblock-enhancements into lp:widelands-website

Proposed by kaputtnik
Status: Merged
Merged at revision: 382
Proposed branch: lp:~franku/widelands-website/smiley-and-codeblock-enhancements
Merge into: lp:widelands-website
Diff against target: 202 lines (+45/-23)
5 files modified
mainpage/templatetags/wl_markdown.py (+11/-7)
media/css/base.css (+23/-5)
media/css/wiki.css (+1/-1)
pybb/util.py (+3/-1)
settings.py (+7/-9)
To merge this branch: bzr merge lp:~franku/widelands-website/smiley-and-codeblock-enhancements
Reviewer Review Type Date Requested Status
SirVer Approve
Shevonar Approve
Review via email: mp+245742@code.launchpad.net

Description of the change

This branch has following changes:

TOC: Background some brighter

CODEBLOCKS: Added dark background to pre- and code-tags.

SMILEYS: Correct ordering in settings.py; Text-Smileys are only replaced with images, if they aren't in a codeblock; Text-smileys are only replaced with images, if they're not inside a word (i.e. in "http://...") Please take a look at my code in function _insert_smileys()... maybe there is a better solution

QUOTING: I added a space after the ">". This will prevend a failure with smiley ":-))" which will otherwise become ">:-))" and therefor it will not be replaced with the correct image. This is related to the smiley_preescaping of the smiley ">:-)" (the only thing that needs preescaping and make trouble).

Some minor cleanups and some comments added.

See https://wl.widelands.org/forum/topic/1602/ for screenshots to codeblocks. I will add smiley screenshots also there.

To post a comment you must log in.
Revision history for this message
Shevonar (shevonar) wrote :

Your changes look fine. Just one question and an answer to your question in the code below.

review: Approve
Revision history for this message
kaputtnik (franku) wrote :

Tanks for approve.

> Your changes look fine. Just one question and an answer to your question in
> the code below.

Yes the "#b"'s (appears twice) are unintendet, better: i forgot to remove them. I used them to trigger an error to debug the code. I haven't found a way to debug the code (make halt points and examine variables) in another way, so i used this possibility. Is there a better way? A hint on that is welcome :-)

Thanks for the answer.

Greetings
franku

Revision history for this message
SirVer (sirver) wrote :

> Is there a better way? A hint on that is welcome :-)

printf debugging is what I use most of the times too - pdb is not a great debugger. however I have a snippet in my editor that will format all lines I output like so: print "#sirver: a: %s" % a.

Similarly if i note something that I want to fix in a branch before submitting a merge proposal, I add a comment: NOCOM(#sirver). Before sending stuff for review, I grep for '#sirver' in the code base - if there are none left I know i am done.

review: Needs Fixing
383. By <email address hidden>

smiley-and-codeblock-enhancements-corrected

Revision history for this message
kaputtnik (franku) wrote :

Hoping i've done it the right way...

Thank you for review and pointing on some mistakes.

And for the hints to grep.

Revision history for this message
SirVer (sirver) wrote :

Merged and deployed. Thanks!

review: Approve
Revision history for this message
kaputtnik (franku) wrote :

:-)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'mainpage/templatetags/wl_markdown.py'
2--- mainpage/templatetags/wl_markdown.py 2014-12-23 16:59:05 +0000
3+++ mainpage/templatetags/wl_markdown.py 2015-01-08 21:40:45 +0000
4@@ -55,12 +55,16 @@
5 def _insert_smileys( text ):
6 """
7 This searches for smiley symbols in the current text
8- and replaces them with the correct images
9+ and replaces them with the correct images.
10+ Only replacing if smiley symbols aren't in a word (e.g. http://....)
11 """
12+ words = text.split(" ")
13 for sc,img in SMILEYS:
14- text = text.replace(sc,"<img src='%s%s' alt='%s' />" % ( SMILEY_DIR, img, img ))
15+ if sc in words:
16+ words[words.index(sc)] = "<img src='%s%s' alt='%s' />" % ( SMILEY_DIR, img, img )
17+ text = " ".join(words)
18+ return text
19
20- return text
21 def _insert_smiley_preescaping( text ):
22 """
23 This searches for smiley symbols in the current text
24@@ -140,6 +144,7 @@
25
26 def do_wl_markdown( value, *args, **keyw ):
27 # Do Preescaping for markdown, so that some things stay intact
28+ # This is currently only needed for this smiley ">:-)"
29 value = _insert_smiley_preescaping( value )
30
31 custom = keyw.pop('custom', True)
32@@ -154,8 +159,6 @@
33 # well, empty soup. Return it
34 return unicode(soup)
35
36- ctag = soup.contents[0]
37-
38 for text in soup.findAll(text=True):
39 # Do not replace inside a link
40 if text.parent.name == "a":
41@@ -167,8 +170,9 @@
42 if custom:
43 # Replace bzr revisions
44 rv = _insert_revision( text )
45- # Replace smileys
46- rv = _insert_smileys( rv )
47+ # Replace smileys; only outside "code-tags"
48+ if not text.parent.name == "code":
49+ rv = _insert_smileys( rv )
50
51 for name, (pattern,replacement) in custom_filters.iteritems():
52 if not len(text.strip()) or not keyw.get(name, True):
53
54=== modified file 'media/css/base.css'
55--- media/css/base.css 2014-12-23 16:59:05 +0000
56+++ media/css/base.css 2015-01-08 21:40:45 +0000
57@@ -69,8 +69,25 @@
58 display: inline;
59 }
60
61+/**************/
62+/* Codeblocks */
63+/**************/
64+
65 pre {
66 white-space: pre-wrap;
67+ background-image: url("../img/black50.png");
68+ padding: 5px 10px;
69+ margin: 5px 10px;
70+ display: inline-block;
71+ border: 1px solid black;
72+}
73+
74+code {
75+ background-image: url("../img/black50.png");
76+}
77+/*No double background*/
78+pre > code {
79+ background-image: none;
80 }
81
82 input, button, textarea, .button {
83@@ -122,7 +139,7 @@
84 }
85
86 .posLeft {
87- float: left
88+ float: left;
89 }
90
91 .posRight {
92@@ -199,10 +216,6 @@
93 margin: 0px 20px;
94 }
95
96-div#header {
97-
98-}
99-
100 div #main {
101 min-height: 500px;
102 }
103@@ -225,7 +238,9 @@
104 border-radius: 4px;
105 }
106
107+/**********/
108 /* Header */
109+/**********/
110
111 div#header img{
112 position: relative;
113@@ -280,7 +295,9 @@
114 color: #ffffff;
115 }
116
117+/****************/
118 /* Right Column */
119+/****************/
120
121 div#rightColumn {
122 width: 220px;
123@@ -418,3 +435,4 @@
124 border: none;
125 clear: left;
126 }
127+
128
129=== modified file 'media/css/wiki.css'
130--- media/css/wiki.css 2014-12-20 18:49:15 +0000
131+++ media/css/wiki.css 2015-01-08 21:40:45 +0000
132@@ -2,7 +2,7 @@
133 border: 1px solid black;
134 display: inline-block;
135 padding: 0px 8px;
136- background-image: url("../img/black50.png");
137+ background-image: url("../img/black20.png");
138 font-size: 12px;
139 margin: 0em 0em 1em 1em;
140 line-height: 18px;
141
142=== modified file 'pybb/util.py'
143--- pybb/util.py 2012-04-19 20:21:28 +0000
144+++ pybb/util.py 2015-01-08 21:40:45 +0000
145@@ -174,7 +174,9 @@
146
147 # if markup == 'markdown':
148 if markup == 'markdown':
149- return '>'+text.replace('\r','').replace('\n','\n>') + '\n'
150+ # Inserting a space after ">" will not change the generated HTML,
151+ # but it will unbreak certain constructs like '>:-))'.
152+ return '> '+text.replace('\r','').replace('\n','\n> ') + '\n'
153 elif markup == 'bbcode':
154 return '[quote]\n%s\n[/quote]\n' % text
155 else:
156
157=== modified file 'settings.py'
158--- settings.py 2013-06-30 12:53:49 +0000
159+++ settings.py 2015-01-08 21:40:45 +0000
160@@ -139,14 +139,18 @@
161 ("O:-)", "face-angel.png"),
162 ("O:)", "face-angel.png"),
163 (":-/", "face-confused.png"),
164- #(":/", "face-confused.png"),
165+ (":/", "face-confused.png"),
166 ("B-)", "face-cool.png"),
167 ("B)", "face-cool.png"),
168 (":'-(", "face-crying.png"),
169 (":'(", "face-crying.png"),
170+ (":-))", "face-smile-big.png"),
171+ (":))", "face-smile-big.png"),
172+ (":-)", "face-smile.png"),
173+ (":)", "face-smile.png"),
174 ("&gt;:-)", "face-devilish.png"), # Hack around markdown replacement. see also SMILEY_PREESCAPING
175 ("8-)", "face-glasses.png"),
176- #("8)", "face-glasses.png"), # Might occur unwanted
177+ ("8)", "face-glasses.png"),
178 (":-D", "face-grin.png"),
179 (":D", "face-grin.png"),
180 (":-x", "face-kiss.png"),
181@@ -164,10 +168,6 @@
182 (":(", "face-sad.png"),
183 (":-O", "face-shock.png"),
184 (":O", "face-shock.png"),
185- (":-)", "face-smile.png"),
186- (":)", "face-smile.png"),
187- (":-))", "face-smile-big.png"),
188- (":))", "face-smile-big.png"),
189 (":-o", "face-surprise.png"),
190 (":o", "face-surprise.png"),
191 (":-P", "face-tongue.png"),
192@@ -179,9 +179,7 @@
193 ]
194 # This needs to be done to keep some stuff hidden from markdown
195 SMILEY_PREESCAPING = [
196- (">:-)", "\>:-)"),
197- (":-*", ":-\*"),
198- #(":*", ":\*"),
199+ (">:-)", "\>:-)")
200 ]
201
202 ###############################

Subscribers

People subscribed via source and target branches