showing source code in blog posts

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

showing source code in blog posts

Dieter Plaetinck
Hi all,
is anyone showing source in pyblosxom blog posts?
I'm in the process of migrating from a drupal blog to pyblosxom (*)
But one stumbling block is currently showing source code.
On Drupal the common solution is using geshi, a php-based syntax
hilighter.
an example to see how it looks like:
http://dieter.plaetinck.be/tweaking_lighttpd_stat_performance_with_fcgi-stat-accel
The code is something like:
<code lang="c">
some_C_code_here
<h1>some html</h1>
some_more_C
</code>

With pyblosxom, the <code> tag is just ignored and everything in
between is parsed as if it's normal html.
There are also syntax schemes for other languages like php, but this is
not even my main concern, if I could just make pyblosxom escape the
stuff between <code> tags and maybe put a <pre>..</pre> around it, it
would already be a nice step forward.

How can I solve this?

Thanks,
Dieter


(*) I'm writing a tool which is pretty useful for this:
http://github.com/Dieterbe/drupal-to-pyblosxom

------------------------------------------------------------------------------
Nokia and AT&T present the 2010 Calling All Innovators-North America contest
Create new apps & games for the Nokia N8 for consumers in  U.S. and Canada
$10 million total in prizes - $4M cash, 500 devices, nearly $6M in marketing
Develop with Nokia Qt SDK, Web Runtime, or Java and Publish to Ovi Store
http://p.sf.net/sfu/nokia-dev2dev
_______________________________________________
pyblosxom-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/pyblosxom-users
Reply | Threaded
Open this post in threaded view
|

Re: showing source code in blog posts

MrPete-2
What about writing a plugin that parses your <code> blocks and runs them through something like http://pygments.org/

?

On Mon, Nov 1, 2010 at 09:08, Dieter Plaetinck <[hidden email]> wrote:
Hi all,
is anyone showing source in pyblosxom blog posts?
<snip>
 


------------------------------------------------------------------------------
Nokia and AT&T present the 2010 Calling All Innovators-North America contest
Create new apps & games for the Nokia N8 for consumers in  U.S. and Canada
$10 million total in prizes - $4M cash, 500 devices, nearly $6M in marketing
Develop with Nokia Qt SDK, Web Runtime, or Java and Publish to Ovi Store
http://p.sf.net/sfu/nokia-dev2dev
_______________________________________________
pyblosxom-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/pyblosxom-users
Reply | Threaded
Open this post in threaded view
|

Re: showing source code in blog posts

Dieter Plaetinck
On Mon, 1 Nov 2010 10:10:51 +1100
Pete Goldsmith <[hidden email]> wrote:

> What about writing a plugin that parses your <code> blocks and runs
> them through something like http://pygments.org/
>
> ?

Thanks, that seems like a good idea.
I've been looking at the markdown and linebreak parser plugins to see
how to do it, but I can't get it to work.
Just to get the first step working (modifying the page content), I use
this code (comments stripped for clarity):


__author__ = 'Dieter Plaetinck <[hidden email]>'
__version__ = "0.1"
PREFORMATTER_ID = 'pygments'

import re
def cb_preformat(args):
    if args['parser'] == PREFORMATTER_ID:
        return parse(''.join(args['story']))

def parse(text):
    text = re.sub('\n','<h1>somethinghappens</h1>',text)
    return text


and my config:
$ grep pygment /srv/http/dieterblog/config.py
py["load_plugins"] = ["comments", "tags", 'pygments']
py['parser'] = 'pygments'
the code is in this file: /srv/http/dieterblog/plugins/pygments.py

Normally I should see "<h1>somethinghappens</h1>" all over the place,
right?  But my pages are the way they were before, as if it's still
using the plain parser.  When I use the debug renderer it confirms that
Request.get_configuration() dict contains parser -> pygments

No errors in my lighttpd error log either.

Dieter

------------------------------------------------------------------------------
Nokia and AT&T present the 2010 Calling All Innovators-North America contest
Create new apps & games for the Nokia N8 for consumers in  U.S. and Canada
$10 million total in prizes - $4M cash, 500 devices, nearly $6M in marketing
Develop with Nokia Qt SDK, Web Runtime, or Java and Publish to Ovi Store
http://p.sf.net/sfu/nokia-dev2dev
_______________________________________________
pyblosxom-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/pyblosxom-users
Reply | Threaded
Open this post in threaded view
|

Re: showing source code in blog posts

will kahn-greene
When you say "I can't get it to work", what does that entail?  What's
failing?  Does it do something, but not the right thing?  Are there \n
in the text?  Is there an error?...


On 11/01/2010 05:50 AM, Dieter Plaetinck wrote:

>
> Thanks, that seems like a good idea.
> I've been looking at the markdown and linebreak parser plugins to see
> how to do it, but I can't get it to work.
> Just to get the first step working (modifying the page content), I use
> this code (comments stripped for clarity):
>
>
> __author__ = 'Dieter Plaetinck <[hidden email]>'
> __version__ = "0.1"
> PREFORMATTER_ID = 'pygments'
>
> import re
> def cb_preformat(args):
>     if args['parser'] == PREFORMATTER_ID:
>         return parse(''.join(args['story']))
>
> def parse(text):
>     text = re.sub('\n','<h1>somethinghappens</h1>',text)
>     return text
>
>
> and my config:
> $ grep pygment /srv/http/dieterblog/config.py
> py["load_plugins"] = ["comments", "tags", 'pygments']
> py['parser'] = 'pygments'
> the code is in this file: /srv/http/dieterblog/plugins/pygments.py
>
> Normally I should see "<h1>somethinghappens</h1>" all over the place,
> right?  But my pages are the way they were before, as if it's still
> using the plain parser.  When I use the debug renderer it confirms that
> Request.get_configuration() dict contains parser -> pygments
>
> No errors in my lighttpd error log either.
>
> Dieter
>
> ------------------------------------------------------------------------------
> Nokia and AT&T present the 2010 Calling All Innovators-North America contest
> Create new apps & games for the Nokia N8 for consumers in  U.S. and Canada
> $10 million total in prizes - $4M cash, 500 devices, nearly $6M in marketing
> Develop with Nokia Qt SDK, Web Runtime, or Java and Publish to Ovi Store
> http://p.sf.net/sfu/nokia-dev2dev
> _______________________________________________
> pyblosxom-users mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/pyblosxom-users
>

------------------------------------------------------------------------------
Nokia and AT&T present the 2010 Calling All Innovators-North America contest
Create new apps & games for the Nokia N8 for consumers in  U.S. and Canada
$10 million total in prizes - $4M cash, 500 devices, nearly $6M in marketing
Develop with Nokia Qt SDK, Web Runtime, or Java and Publish to Ovi Store
http://p.sf.net/sfu/nokia-dev2dev
_______________________________________________
pyblosxom-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/pyblosxom-users
Reply | Threaded
Open this post in threaded view
|

Re: showing source code in blog posts

Dieter Plaetinck
Well, like I said, the pages are rendered exactly like they were before
and my lighttpd logs contain no errors (and the pyblosxom logging
doesn't work for me, but that's another story)

There definitely are \n in the text.
In fact, I now tried this:

in plugins/comments.py:
def cb_preformat(args):
    return ''.join(args['story']) + '<h1>comments</h1>'

in plugins/pygments.py:
def cb_preformat(args):
    return ''.join(args['story']) + '<h1>PYGMENTS</h1>'


Then my rendered stories contain '<h1>comments</h1>', but not
'<h1>PYGMENTS</h1>'
I also tried putting the pygments plugin first in py["load_plugins"] in
the config.py, but no change.

here's the entire pygments.py source code
http://sprunge.us/TGST
I checked permissions/ownership, it's correct (and the same as the
other plugins)
This is my entire config:
http://sprunge.us/OfGb

Dieter



On Mon, 01 Nov 2010 08:46:00 -0400
will kahn-greene <[hidden email]> wrote:

> When you say "I can't get it to work", what does that entail?  What's
> failing?  Does it do something, but not the right thing?  Are there \n
> in the text?  Is there an error?...
>
>
> On 11/01/2010 05:50 AM, Dieter Plaetinck wrote:
> >
> > Thanks, that seems like a good idea.
> > I've been looking at the markdown and linebreak parser plugins to
> > see how to do it, but I can't get it to work.
> > Just to get the first step working (modifying the page content), I
> > use this code (comments stripped for clarity):
> >
> >
> > __author__ = 'Dieter Plaetinck <[hidden email]>'
> > __version__ = "0.1"
> > PREFORMATTER_ID = 'pygments'
> >
> > import re
> > def cb_preformat(args):
> >     if args['parser'] == PREFORMATTER_ID:
> >         return parse(''.join(args['story']))
> >
> > def parse(text):
> >     text = re.sub('\n','<h1>somethinghappens</h1>',text)
> >     return text
> >
> >
> > and my config:
> > $ grep pygment /srv/http/dieterblog/config.py
> > py["load_plugins"] = ["comments", "tags", 'pygments']
> > py['parser'] = 'pygments'
> > the code is in this file: /srv/http/dieterblog/plugins/pygments.py
> >
> > Normally I should see "<h1>somethinghappens</h1>" all over the
> > place, right?  But my pages are the way they were before, as if
> > it's still using the plain parser.  When I use the debug renderer
> > it confirms that Request.get_configuration() dict contains parser
> > -> pygments
> >
> > No errors in my lighttpd error log either.
> >
> > Dieter
> >
> > ------------------------------------------------------------------------------
> > Nokia and AT&T present the 2010 Calling All Innovators-North
> > America contest Create new apps & games for the Nokia N8 for
> > consumers in  U.S. and Canada $10 million total in prizes - $4M
> > cash, 500 devices, nearly $6M in marketing Develop with Nokia Qt
> > SDK, Web Runtime, or Java and Publish to Ovi Store
> > http://p.sf.net/sfu/nokia-dev2dev
> > _______________________________________________ pyblosxom-users
> > mailing list [hidden email]
> > https://lists.sourceforge.net/lists/listinfo/pyblosxom-users
> >


------------------------------------------------------------------------------
Nokia and AT&T present the 2010 Calling All Innovators-North America contest
Create new apps & games for the Nokia N8 for consumers in  U.S. and Canada
$10 million total in prizes - $4M cash, 500 devices, nearly $6M in marketing
Develop with Nokia Qt SDK, Web Runtime, or Java and Publish to Ovi Store
http://p.sf.net/sfu/nokia-dev2dev
_______________________________________________
pyblosxom-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/pyblosxom-users
Reply | Threaded
Open this post in threaded view
|

Re: showing source code in blog posts

Terry Brown-2
In reply to this post by Dieter Plaetinck
On Sun, 31 Oct 2010 23:08:15 +0100
Dieter Plaetinck <[hidden email]> wrote:

> Hi all,
> is anyone showing source in pyblosxom blog posts?

I have a blog posting on that here:

  http://codemostly.blogspot.com/2009/08/syntax-highlighting-for-pyblosxom.html

it assumes you're writing restructured text, but you could start from there for other dialects.

There's also http://alexgorbatchev.com/SyntaxHighlighter which is a javascript approach.

Cheers -Terry

------------------------------------------------------------------------------
Nokia and AT&T present the 2010 Calling All Innovators-North America contest
Create new apps & games for the Nokia N8 for consumers in  U.S. and Canada
$10 million total in prizes - $4M cash, 500 devices, nearly $6M in marketing
Develop with Nokia Qt SDK, Web Runtime, or Java and Publish to Ovi Store
http://p.sf.net/sfu/nokia-dev2dev
_______________________________________________
pyblosxom-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/pyblosxom-users
Reply | Threaded
Open this post in threaded view
|

Re: showing source code in blog posts

will kahn-greene
I just started using SyntaxHighlighter.  It works super for me and my
needs, plus it was a couple of easy changes to my html flavour's head
template.

I'd love to add helper tips like this to the documentation somehow.
Would it be good to add a FAQ section to the manual?  Or should these
kinds of configuration tips be sprinkled in appropriate sections?


On 11/01/2010 11:35 AM, Terry Brown wrote:

> On Sun, 31 Oct 2010 23:08:15 +0100
> Dieter Plaetinck <[hidden email]> wrote:
>
>> Hi all,
>> is anyone showing source in pyblosxom blog posts?
>
> I have a blog posting on that here:
>
>   http://codemostly.blogspot.com/2009/08/syntax-highlighting-for-pyblosxom.html
>
> it assumes you're writing restructured text, but you could start from there for other dialects.
>
> There's also http://alexgorbatchev.com/SyntaxHighlighter which is a javascript approach.
>
> Cheers -Terry

------------------------------------------------------------------------------
Nokia and AT&T present the 2010 Calling All Innovators-North America contest
Create new apps & games for the Nokia N8 for consumers in  U.S. and Canada
$10 million total in prizes - $4M cash, 500 devices, nearly $6M in marketing
Develop with Nokia Qt SDK, Web Runtime, or Java and Publish to Ovi Store
http://p.sf.net/sfu/nokia-dev2dev
_______________________________________________
pyblosxom-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/pyblosxom-users
Reply | Threaded
Open this post in threaded view
|

Re: showing source code in blog posts

seanh-4
In reply to this post by Dieter Plaetinck
On Sun, Oct 31, 2010 at 11:08:15PM +0100, Dieter Plaetinck wrote:
> Hi all,
> is anyone showing source in pyblosxom blog posts?

My Python Markdown 2 plugin can do source code highlighting if you have
python pygments. It's another plugin that isn't in the plugin registry:

http://github.com/seanh/PyBlosxom-Python-Markdown-2-Plugin

See the Python Markdown 2 instructions for how to use source code
highlighting:

http://www.freewisdom.org/projects/python-markdown/CodeHilite

You will have to edit line 35 of markdown-plugin.py to enable the
codehilite extension.

------------------------------------------------------------------------------
Nokia and AT&T present the 2010 Calling All Innovators-North America contest
Create new apps & games for the Nokia N8 for consumers in  U.S. and Canada
$10 million total in prizes - $4M cash, 500 devices, nearly $6M in marketing
Develop with Nokia Qt SDK, Web Runtime, or Java and Publish to Ovi Store
http://p.sf.net/sfu/nokia-dev2dev
_______________________________________________
pyblosxom-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/pyblosxom-users
Reply | Threaded
Open this post in threaded view
|

Re: showing source code in blog posts

Dieter Plaetinck
In reply to this post by Terry Brown-2
Thanks guys for your input.

On Mon, 1 Nov 2010 10:35:10 -0500
Terry Brown <[hidden email]> wrote:

> There's also http://alexgorbatchev.com/SyntaxHighlighter which is a
> javascript approach.

Seems wrong by design to me.  They even mention it themselves (at
http://alexgorbatchev.com/SyntaxHighlighter/manual/installation.html)
If you want the code to be shown instead of interpreted, you must do
all the escaping yourself, and then still rss readers will not apply
the hilighting ("<pre> method").  The alternative "<script>" method
allows you to not escape the html yourself, but will break horribly
without support for js (i.e. in rss readers)

On Mon, 1 Nov 2010 19:53:53 +0000
seanh <[hidden email]> wrote:

> My Python Markdown 2 plugin can do source code highlighting if you
> have python pygments. It's another plugin that isn't in the plugin
> registry:
>
> http://github.com/seanh/PyBlosxom-Python-Markdown-2-Plugin
>
> See the Python Markdown 2 instructions for how to use source code
> highlighting:
>
> http://www.freewisdom.org/projects/python-markdown/CodeHilite
>
> You will have to edit line 35 of markdown-plugin.py to enable the
> codehilite extension.

Thanks, although I don't use markdown (nor RST), your plugin seems
simple enough to try using as a starting point.
Although i still don't get why my own plugin doesn't affect the text..
really weird..

Dieter

------------------------------------------------------------------------------
Nokia and AT&T present the 2010 Calling All Innovators-North America contest
Create new apps & games for the Nokia N8 for consumers in  U.S. and Canada
$10 million total in prizes - $4M cash, 500 devices, nearly $6M in marketing
Develop with Nokia Qt SDK, Web Runtime, or Java and Publish to Ovi Store
http://p.sf.net/sfu/nokia-dev2dev
_______________________________________________
pyblosxom-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/pyblosxom-users
Reply | Threaded
Open this post in threaded view
|

Re: showing source code in blog posts

Dieter Plaetinck
Will figured out why my plugin didn't work.
I called it plugins/pygments.py which conflicts with the real pygments
package on my system.
I renamed it and now it works fine.

There is more info @
http://pyblosxom.bluesock.org/1.5/dev_writing_plugins.html#name

Now on to making it actually highlight source code \o/
Stay tuned.

Dieter

------------------------------------------------------------------------------
The Next 800 Companies to Lead America's Growth: New Video Whitepaper
David G. Thomson, author of the best-selling book "Blueprint to a
Billion" shares his insights and actions to help propel your
business during the next growth cycle. Listen Now!
http://p.sf.net/sfu/SAP-dev2dev
_______________________________________________
pyblosxom-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/pyblosxom-users
Reply | Threaded
Open this post in threaded view
|

Re: showing source code in blog posts

Dieter Plaetinck
First version of my plugin is done.
Some rough edges, a day of swearing and cursing, but it's working.
https://github.com/Dieterbe/dieterblog/blob/master/plugins/syntaxhighlight.py

Dieter

------------------------------------------------------------------------------
The Next 800 Companies to Lead America's Growth: New Video Whitepaper
David G. Thomson, author of the best-selling book "Blueprint to a
Billion" shares his insights and actions to help propel your
business during the next growth cycle. Listen Now!
http://p.sf.net/sfu/SAP-dev2dev
_______________________________________________
pyblosxom-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/pyblosxom-users