Lol, yes :)
-Thadeus



On Sun, Nov 15, 2009 at 3:59 PM, mr.freeze <nat...@freezable.com> wrote:

>
> Do you mean this one?
> http://www.web2pyslices.com/main/slices/take_slice/32
>
>
> On Nov 15, 3:55 pm, Thadeus Burgess <thade...@thadeusb.com> wrote:
> > By the way
> >
> > http://www.web2pyslices.com/main/slices/take_slice/30
> >
> > -Thadeus
> >
> > On Sun, Nov 15, 2009 at 3:51 PM, Thadeus Burgess <thade...@thadeusb.com
> >wrote:
> >
> > > [SOLVED], this is the final model.
> >
> > > I had to parse the content and replace the html entities.
> >
> > > functions.py
> > >http://pastebin.com/f25d3c971
> >
> > > usage
> >
> > > {{=XML(__highlight__(blog_post.content))}}
> >
> > > -Thadeus
> >
> > > On Sun, Nov 15, 2009 at 3:22 PM, Thadeus Burgess <
> thade...@thadeusb.com>wrote:
> >
> > >> How would I convert html char codes into their actual UTF-8
> > >> representation?
> >
> > >> Because
> >
> > >> def somefunc(avar="hi"): pass
> >
> > >> gets turned into this by CKeditors.
> >
> > >> def somefunc(avar=&#39;hi&#39): pass
> >
> > >> -Thadeus
> >
> > >> On Sun, Nov 15, 2009 at 3:14 PM, Thadeus Burgess <
> thade...@thadeusb.com>wrote:
> >
> > >>> Ok, the problem was using <code> tags, CKEditor attempts to format
> them.
> >
> > >>> Switching to <pre> tags, CKEditor will not format them.... So
> >
> > >>> def __highlight__(content, dom_element='pre'):
> >
> > >>>     from pygments import highlight
> > >>>     from pygments.lexers import get_lexer_by_name
> > >>>     from pygments.formatters import HtmlFormatter
> > >>>     from BeautifulSoup import BeautifulSoup
> >
> > >>>     soup = BeautifulSoup(content)
> >
> > >>>     formatter = HtmlFormatter(linenos=True, noclasses=True)
> >
> > >>>     for tag in soup.findAll(dom_element):
> >
> > >>>         language = tag.get('lang')
> > >>>         lexer = get_lexer_by_name(language, encoding='UTF-8')
> > >>>         tag.replaceWith(highlight(tag.renderContents(), lexer,
> > >>> formatter))
> > >>>         pass
> > >>>     return unicode(soup)
> >
> > >>> -Thadeus
> >
> > >>> On Sun, Nov 15, 2009 at 2:55 PM, Thadeus Burgess <
> thade...@thadeusb.com>wrote:
> >
> > >>>> Thanks that got me on the right track!
> >
> > >>>> This is what I ended up with, a view function that gets called on
> the
> > >>>> blog posts content. The only problem is CKEditor tries to format the
> code
> > >>>> during editing, so you end up with alot of <br/> leaked in, working
> on
> > >>>> solving that.
> >
> > >>>> {{
> > >>>> def __highlight__(content):
> > >>>>     from pygments import highlight
> > >>>>     from pygments.lexers import get_lexer_by_name
> > >>>>     from pygments.formatters import HtmlFormatter
> > >>>>     from BeautifulSoup import BeautifulSoup
> >
> > >>>>     soup = BeautifulSoup(content)
> >
> > >>>>     formatter = HtmlFormatter(linenos=True, noclasses=True)
> >
> > >>>>     for tag in soup.findAll('code'):
> > >>>>         language = tag.get('lang')
> > >>>>         lexer = get_lexer_by_name(language, encoding='UTF-8')
> > >>>>         tag.replaceWith(highlight(tag.renderContents(), lexer,
> > >>>> formatter))
> > >>>>         pass
> > >>>>     return unicode(soup)
> > >>>> }}
> >
> > >>>> -Thadeus
> >
> > >>>> On Sun, Nov 15, 2009 at 1:35 PM, Mengu <whalb...@gmail.com> wrote:
> >
> > >>>>> hi Thadeus,
> >
> > >>>>> hope it helps:
> > >>>>>http://github.com/mengu/blog/blob/master/models/post.py#L39
> >
> > >>>>> On Nov 15, 8:48 am, Thadeus Burgess <thade...@thadeusb.com> wrote:
> > >>>>> > I have a html content (for a blog) and would like to parse the
> > >>>>> content for
> > >>>>> > <code> tags, and of course replace the content with web2py syntax
> > >>>>> > highlighting using CODE helper.
> >
> > >>>>> > Has anybody done this yet?
> >
> > >>>>> > -Thadeus
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To post to this group, send email to web2py@googlegroups.com
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to