简体   繁体   中英

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

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!

I use prism.js

It looks Like this, it has many features

在此处输入图像描述

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM