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
  • If you tell me in what way my solution doesn't work (what output do you get? What output are you expecting? What errors do you get?) I might be able to help you more. Sorry my answer didn't work for you. Commented Jan 17, 2010 at 20:07

2 Answers 2

1

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 }}
Sign up to request clarification or add additional context in comments.

1 Comment

thanks for your help, but it does not work... i will ask our local python user group this evening thanks anyway !
1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.