views:

92

answers:

2

I have some problems with following string while trying to syntax highlight them:

Example

<code class="php"><? echo "<input type=\"text\">"; ?></code>

The php part is rendered correctly, but the html part breaks.

I use the Markdown and Syntax Highlighting snippet from

http://www.djangosnippets.org/snippets/119/

Any idea how to escape the html part inside the php code correctly ?

+1  A: 

Looks like you need to pass your PHP/HTML hybrid code through the escape filter, to convert instances of < to &lt; etc.

Use it like this in a template, assuming you've got your code in a template context variable called mycode:

{{ mycode|escape }}
Dominic Rodger
thanks for your help, but it does not work...i will ask our local python user group this evening thanks anyway !
nfo
+1  A: 

Python markdown integrates with Pygments that do the syntax highlighting.

You can go from markdown to html formatted text with source code with highlighted syntax.

The short version is:

import markdown
html = markdown.markdown(text,['codehilite'])

html contains the html formatted text with the source code highlighted. You just need to point to css style, that's it.

Have a look at how to setup markdow and pygments to do syntax highlight for blogger.

In your solution you can just include a reference to css which makes it even easier.

stefanB