(self)
Pass code to the [Pygments](http://pygments.pocoo.org/) highliter with
        optional line numbers. The output should then be styled with css to
        your liking. No styles are applied by default - only styling hooks
        (i.e.: <span class="k">).

        returns : A string of html.
Pass code to the [Pygments](http://pygments.pocoo.org/) highliter with
        optional line numbers. The output should then be styled with css to
        your liking. No styles are applied by default - only styling hooks
        (i.e.: <span class="k">).
Pass code to the [ Pygments ] ( http : // pygments . pocoo . org / ) highliter with optional line numbers . The output should then be styled with css to your liking . No styles are applied by default - only styling hooks ( i . e . : <span class = k > ) .
def hilite(self):
        """
        Pass code to the [Pygments](http://pygments.pocoo.org/) highliter with
        optional line numbers. The output should then be styled with css to
        your liking. No styles are applied by default - only styling hooks
        (i.e.: <span class="k">).

        returns : A string of html.

        """

        self.src = self.src.strip('\n')

        if self.lang is None:
            self._getLang()

        if pygments:
            try:
                lexer = get_lexer_by_name(self.lang)
            except ValueError:
                try:
                    if self.guess_lang:
                        lexer = guess_lexer(self.src)
                    else:
                        lexer = TextLexer()
                except ValueError:
                    lexer = TextLexer()
            formatter = HtmlFormatter(linenos=self.linenos,
                                      cssclass=self.css_class,
                                      style=self.style,
                                      noclasses=self.noclasses)
            return highlight(self.src, lexer, formatter)
        else:
            # just escape and build markup usable by JS highlighting libs
            txt = self.src.replace('&', '&amp;')
            txt = txt.replace('<', '&lt;')
            txt = txt.replace('>', '&gt;')
            txt = txt.replace('"', '&quot;')
            classes = []
            if self.lang:
                classes.append('language-%s' % self.lang)
            if self.linenos:
                classes.append('linenums')
            class_str = ''
            if classes:
                class_str = ' class="%s"' % ' '.join(classes) 
            return '<pre class="%s"><code%s>%s</code></pre>\n'% \
                        (self.css_class, class_str, txt)
def hilite ( self ) : self . src = self . src . strip ( '\n' ) if self . lang is None : self . _getLang ( ) if pygments : try : lexer = get_lexer_by_name ( self . lang ) except ValueError : try : if self . guess_lang : lexer = guess_lexer ( self . src ) else : lexer = TextLexer ( ) except ValueError : lexer = TextLexer ( ) formatter = HtmlFormatter ( linenos = self . linenos , cssclass = self . css_class , style = self . style , noclasses = self . noclasses ) return highlight ( self . src , lexer , formatter ) else : # just escape and build markup usable by JS highlighting libs txt = self . src . replace ( '&' , '&amp;' ) txt = txt . replace ( '<' , '&lt;' ) txt = txt . replace ( '>' , '&gt;' ) txt = txt . replace ( '"' , '&quot;' ) classes = [ ] if self . lang : classes . append ( 'language-%s' % self . lang ) if self . linenos : classes . append ( 'linenums' ) class_str = '' if classes : class_str = ' class="%s"' % ' ' . join ( classes ) return '<pre class="%s"><code%s>%s</code></pre>\n' % ( self . css_class , class_str , txt )