~osomon/software-center/too_many_refreshes

« back to all changes in this revision

Viewing changes to softwarecenter/view/appdetailsview.py

  • Committer: Michael Vogt
  • Date: 2010-04-14 22:42:14 UTC
  • mfrom: (685.1.2 improve-html)
  • Revision ID: michael.vogt@ubuntu.com-20100414224214-ijdf76a2xec8jx74
merged lp:~zkrynicki/software-center/improve-html, many thanks
(final bits for LP: #455320), add simple test

Show diffs side-by-side

added added

removed removed

Lines of Context:
215
215
 
216
216
        # format for html
217
217
        description = self.pkg.description
218
 
        #print description
219
 
 
 
218
        logging.debug("Description (text) %r", description)
220
219
        # format bullets (*-) as lists
221
 
        regx = re.compile("\n\s*([*-]+) (.*)")
222
 
        description = re.sub(regx, r'<li>\2</li>', description)
 
220
        description = "\n".join(htmlize_package_desc(description))
223
221
        description = self.add_ul_tags(description)
224
 
        
225
 
        #line breaks
226
 
        regx = re.compile("(\n\n)")
227
 
        description = re.sub(regx, r'<p></p>', description)
228
 
        
229
222
        # urls
230
223
        regx = re.compile("((ftp|http|https):\/\/[a-zA-Z0-9\/\\\:\?\%\.\&\;=#\-\_\!\+\~]*)")
231
 
        
232
 
        return re.sub(regx, r'<a href="\1">\1</a>', description)
 
224
        description = re.sub(regx, r'<a href="\1">\1</a>', description)
 
225
        logging.debug("Description (HTML) %r", description)
 
226
        return description
233
227
 
234
228
    def add_ul_tags(self, description):
235
 
        n = description.find("<li>")
236
 
        if not n == -1:
237
 
            description[n:n+3].replace("<li>", "<ul><li>")
238
 
            description = description[0:n] + description[n:n+3].replace("<li>", "<ul><li>") + description[n+3:]
239
 
            description_list_tmp = []
240
 
            len_description = range(len(description))
241
 
            len_description.reverse()
242
 
        
243
 
            for letter in len_description:
244
 
                description_list_tmp.append(description[letter])
245
 
                
246
 
            description_list_tmp = "".join(description_list_tmp)
247
 
            n = len(description) - description_list_tmp.find(">il/<")
248
 
            return description[0:n] + description[n-5:n].replace("</li>", "</li></ul>") + description[n:]
 
229
        """ add <ul></ul> around a bunch of <li></li> lists
 
230
        """
 
231
        first_li = description.find("<li>")
 
232
        last_li =  description.rfind("</li>")
 
233
        if first_li >= 0 and last_li >= 0:
 
234
            last_li += len("</li>")
 
235
            return '%s<ul tabindex="0">%s</ul>%s' % (
 
236
                description[:first_li],
 
237
                description[first_li:last_li],
 
238
                description[last_li:])
249
239
        return description
250
240
 
251
241
    def wksub_iconpath_loading(self):
622
612
    # gui
623
613
    scroll = gtk.ScrolledWindow()
624
614
    view = AppDetailsView(db, distro, icons, cache, datadir)
625
 
    view.show_app(Application("3D Chess", "3dchess"))
626
 
    #view.show_app("Movie Player", "totem")
 
615
    #view.show_app(Application("3D Chess", "3dchess"))
 
616
    view.show_app(Application("Movie Player", "totem"))
627
617
    #view.show_app(Application("ACE", "unace"))
628
618
    #view.show_app(Application("", "2vcard"))
629
619