How can I show syntax-highlighted Python code in a HTML-page?

Viewed 4082

Is it somehow possible to show syntax-highlighted python code in a webpage?

I found this:

<pre class="brush: python">
    # python code here
</pre>

However, it shows all the code in black. I want import to be orange, strings to be green.

Is it possible to do this?

Thank you!

2 Answers

If you wish to only display code, python in this case, consider using Github gist.

You can then embed it using the 'embed' option on the top right corner. It will give you a script tag that you can copy and add to your webpage like so:

<script src="https://gist.github.com/username/a39a422ebdff6e732753b90573100b16.js"></script>

I use prism.js

It looks Like this, it has many features

enter image description here

Related