John J Lee | 4 Aug 00:05 2006
Picon

ReST syntax for colourizing source?

What's the best reST syntax to use when you want colourized (Python) 
source code in your HTML output?

I have two cases:

1. Inline source.  Would it be normal to use a directive here, or to just
    use a normal indented block after a "::" (reimplementing or extending
    rst2html as necessary)?

2. Source from an external file.

I notice rest2web has a colorize "macro" to handle case 2., but not sure 
if that's part of reST proper.

Any examples of code to implement "similar" things would be appreciated 
too.

TIA

John

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
John J Lee | 4 Aug 00:13 2006
Picon

Re: ReST syntax for colourizing source?

On Thu, 3 Aug 2006, John J Lee wrote:
[...]
> Any examples of code to implement "similar" things would be appreciated
> too.

Hmm, that's not clear.  I'm talking there about extending / reimplementing 
(parts of) rst2html so that it will do colorized output.  I've already got 
code to render Python source code colorized to HTML, so I don't need help 
with that.

The main question remains about the syntax to use, not the implementation.

John

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
Martin Blais | 25 Aug 17:06 2006
Picon

Re: ReST syntax for colourizing source?

On 8/3/06, John J Lee <jjl <at> pobox.com> wrote:
> On Thu, 3 Aug 2006, John J Lee wrote:
> [...]
> > Any examples of code to implement "similar" things would be appreciated
> > too.
>
> Hmm, that's not clear.  I'm talking there about extending / reimplementing
> (parts of) rst2html so that it will do colorized output.  I've already got
> code to render Python source code colorized to HTML, so I don't need help
> with that.
>
> The main question remains about the syntax to use, not the implementation.

Hi John
I think the question boils down to one of specificity, i.e. does reST
allow the document author to specify that a literal block is to
contain <stuff from language X> (in your case, Python).  (I don't know
the answer BTW, but I suspect you could use a container with a class
to informally achieve the same thing, although I don't know how well
received the corresponding changes to the html writer would be.)

Isn't there a way in reST to specify a "block of code" other than just
a litteral block?  If so, we should add an option to specify what the
contents are.  There is such a thing in the Trac wiki rest support:
http://trac.edgewall.org/wiki/WikiRestructuredText

{{{
#!rst

.. code-block:: python
(Continue reading)

Michael Foord | 4 Aug 00:19 2006
Picon

Re: ReST syntax for colourizing source?

John J Lee wrote:
> What's the best reST syntax to use when you want colourized (Python) 
> source code in your HTML output?
>
> I have two cases:
>
> 1. Inline source.  Would it be normal to use a directive here, or to just
>     use a normal indented block after a "::" (reimplementing or extending
>     rst2html as necessary)?
>
> 2. Source from an external file.
>
>
> I notice rest2web has a colorize "macro" to handle case 2., but not sure 
> if that's part of reST proper.
>
>   
rest2web can also colorize Python code included in a source file, and 
with the use of the raw role could probably be used for inline source :

.. raw:: html

    {+coloring}
    print 'something'
    # etc...
    {-coloring}

or :raw:`{+coloring}print 'something'{-coloring}` (or whatever the 
correct syntax is for roles).

(Continue reading)


Gmane