Re: code blocks in blog posts

Ian Bicking <[email protected]> Sat, 27 Mar 2004 14:44:46 -0500
Newsgroups gmane.comp.pythin.pyds.devel
Message-ID <[email protected]>
On Mar 27, 2004, at 2:33 PM, rand-kzPqTZqrtG+O+QkcXTtFxKWz8mPg4b/[email protected] wrote:
> I had two problems:
> 1. After finally settling on <pre> to simplify some of the formatting, 
> there was one thing about <pre> I didn't
> like, and that is that it seems to have a fixed width for lines 
> entered. That is, one of the code lines was
> quite long, and it didn't wrap when the rendered form was narrowed. 
> How do people usually deal with inline code
> and wrapping? I ended up manually making the entered code be 
> multi-line with '\' at the end of partial lines.

That's probably the best way.  There's a CSS trick you can use to make 
PRE blocks scroll separately from the rest of the page (so a wide PRE 
won't mess up your three-column layout).  I think if you do:

pre {
     overflow: auto
}

that it will do this.

> 2. I had to manually replace the '<' and '>' with &lt; and &gt; every 
> time I edited the post.

Yep, you must quote.  You can use restructured text to have it do some 
stuff like this for you, like:

Here's my example code, which I mark with two colons::

     code stuff...
     all of it is indented...
     but the indent is removed later...

And back to the main text.


This will do the quoting for you, as well as all sorts of other nice 
stuff reST can do.

> I thought I recalled seeing mention on this list of a cheetah 
> directive called code-block, but couldn't find
> enough on it to figure it out. Any pointers?

No relation -- it's for inlining code that actually gets run.

--
Ian Bicking | [email protected] | http://blog.ianbicking.org