← Back to team overview

widelands-dev team mailing list archive

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

 

kaputtnik has proposed merging lp:~franku/widelands-website/smiley-and-codeblock-enhancements into lp:widelands-website.

Requested reviews:
  Widelands Developers (widelands-dev)

For more details, see:
https://code.launchpad.net/~franku/widelands-website/smiley-and-codeblock-enhancements/+merge/245742

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.


-- 
Your team Widelands Developers is requested to review the proposed merge of lp:~franku/widelands-website/smiley-and-codeblock-enhancements into lp:widelands-website.
=== modified file 'mainpage/templatetags/wl_markdown.py'
--- mainpage/templatetags/wl_markdown.py	2014-12-23 16:59:05 +0000
+++ mainpage/templatetags/wl_markdown.py	2015-01-07 14:22:19 +0000
@@ -55,12 +55,16 @@
 def _insert_smileys( text ):
     """
     This searches for smiley symbols in the current text
-    and replaces them with the correct images
+    and replaces them with the correct images.
+    Only replacing if smiley symbols aren't in a word (e.g. http://....)
     """
+    words = text.split(" ")
     for sc,img in SMILEYS:
-        text = text.replace(sc,"<img src='%s%s' alt='%s' />" % ( SMILEY_DIR, img, img ))
+        if sc in words:
+            words[words.index(sc)] = "<img src='%s%s' alt='%s' />" % ( SMILEY_DIR, img, img )
+    text = " ".join(words)
+    return text
 
-    return text
 def _insert_smiley_preescaping( text ):
     """
     This searches for smiley symbols in the current text
@@ -140,6 +144,7 @@
 
 def do_wl_markdown( value, *args, **keyw ):
     # Do Preescaping for markdown, so that some things stay intact
+    # This is currently only needed for this smiley ">:-)"
     value = _insert_smiley_preescaping( value )
 
     custom = keyw.pop('custom', True)
@@ -154,7 +159,7 @@
         # well, empty soup. Return it
         return unicode(soup)
 
-    ctag = soup.contents[0]
+    #ctag = soup.contents[0]
 
     for text in soup.findAll(text=True):
         # Do not replace inside a link
@@ -167,8 +172,10 @@
         if custom:
             # Replace bzr revisions
             rv = _insert_revision( text )
-            # Replace smileys
-            rv = _insert_smileys( rv )
+            # Replace smileys; only outside "code-tags"
+            if not text.parent.name == "code":
+                rv = _insert_smileys( rv )
+                #b
 
             for name, (pattern,replacement) in custom_filters.iteritems():
                 if not len(text.strip()) or not keyw.get(name, True):
@@ -182,7 +189,7 @@
     # The function goes from .5 ms to 1.5ms on my system
     # Well, for our site with it's little traffic it's maybe not so important...
     soup = BeautifulSoup(unicode(soup)) # What a waste of cycles :(
-
+    #b
     # We have to go over this to classify links
     
     for tag in soup.findAll("a"):

=== modified file 'media/css/base.css'
--- media/css/base.css	2014-12-23 16:59:05 +0000
+++ media/css/base.css	2015-01-07 14:22:19 +0000
@@ -69,8 +69,25 @@
 	display: inline;
 }
 
+/**************/
+/* Codeblocks */
+/**************/
+
 pre {
 	white-space: pre-wrap;
+	background-image: url("../img/black50.png");
+	padding: 5px 10px;
+	margin: 5px 10px;
+	display: inline-block;
+	border: 1px solid black;
+}
+
+code {
+	background-image: url("../img/black50.png");
+}
+/*No double background*/
+pre > code {
+	background-image: none;
 }
 
 input, button, textarea, .button {
@@ -199,10 +216,6 @@
 	margin: 0px 20px;
 }
 
-div#header {
-
-}
-
 div #main {
 	min-height: 500px;
 }
@@ -225,7 +238,9 @@
 	border-radius: 4px;
 }
 
+/**********/
 /* Header */
+/**********/
 
 div#header  img{
 	position: relative;
@@ -280,7 +295,9 @@
 	color: #ffffff;
 }
 
+/****************/
 /* Right Column */
+/****************/
 
 div#rightColumn {
 	width: 220px;
@@ -418,3 +435,4 @@
 	border: none;
 	clear: left;
 }
+

=== modified file 'media/css/wiki.css'
--- media/css/wiki.css	2014-12-20 18:49:15 +0000
+++ media/css/wiki.css	2015-01-07 14:22:19 +0000
@@ -2,7 +2,7 @@
 	border: 1px solid black;
 	display: inline-block;
 	padding: 0px 8px;
-	background-image: url("../img/black50.png");
+	background-image: url("../img/black20.png");
 	font-size: 12px;
 	margin: 0em 0em 1em 1em;
 	line-height: 18px;

=== modified file 'pybb/util.py'
--- pybb/util.py	2012-04-19 20:21:28 +0000
+++ pybb/util.py	2015-01-07 14:22:19 +0000
@@ -174,7 +174,8 @@
 
     # if markup == 'markdown':
     if markup == 'markdown':
-        return '>'+text.replace('\r','').replace('\n','\n>') + '\n'
+        #Adding a space after ">" will kepp some things stay in tact
+        return '> '+text.replace('\r','').replace('\n','\n> ') + '\n'
     elif markup == 'bbcode':
         return '[quote]\n%s\n[/quote]\n' % text
     else:

=== modified file 'settings.py'
--- settings.py	2013-06-30 12:53:49 +0000
+++ settings.py	2015-01-07 14:22:19 +0000
@@ -139,14 +139,18 @@
     ("O:-)", "face-angel.png"),
     ("O:)", "face-angel.png"),
     (":-/", "face-confused.png"),
-    #(":/", "face-confused.png"),
+    (":/", "face-confused.png"),
     ("B-)", "face-cool.png"),
     ("B)", "face-cool.png"),
     (":'-(", "face-crying.png"),
     (":'(", "face-crying.png"),
+    (":-))", "face-smile-big.png"),
+    (":))", "face-smile-big.png"),
+    (":-)", "face-smile.png"),
+    (":)", "face-smile.png"),
     ("&gt;:-)", "face-devilish.png"), # Hack around markdown replacement. see also SMILEY_PREESCAPING
     ("8-)", "face-glasses.png"),
-    #("8)", "face-glasses.png"), # Might occur unwanted
+    ("8)", "face-glasses.png"), # Might occur unwanted (why?)
     (":-D", "face-grin.png"),
     (":D", "face-grin.png"),
     (":-x", "face-kiss.png"),
@@ -164,10 +168,6 @@
     (":(", "face-sad.png"),
     (":-O", "face-shock.png"),
     (":O", "face-shock.png"),
-    (":-)", "face-smile.png"),
-    (":)", "face-smile.png"),
-    (":-))", "face-smile-big.png"),
-    (":))", "face-smile-big.png"),
     (":-o", "face-surprise.png"),
     (":o", "face-surprise.png"),
     (":-P", "face-tongue.png"),
@@ -180,7 +180,7 @@
 # This needs to be done to keep some stuff hidden from markdown
 SMILEY_PREESCAPING = [
     (">:-)", "\>:-)"),
-    (":-*", ":-\*"),
+    #(":-*", ":-\*"),
     #(":*", ":\*"),
 ]
 


Follow ups