13

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

2 Answers 2

6

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

5 Comments

@aadev151 Glad I could be of help. Please upvote/accept the answer, helps with your rep too :)
is this still working? I get 404 when I try to see the js source script
Replace the value for src with the gist URL you wish to display
Awesome! It works now but does not show up with python color highlights and colors (the script is all black and flat).. Is there any way I can get that to work?
I learned when I update .txt to .py, the color code is there but it shows up in a vertical format. a = 2 print ( a * 2 ) --> url of my page using gist: saeedmirshekari.com/blog/test
5

I use prism.js

It looks Like this, it has many features

enter image description here

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.