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!
The new PyScript project lets you embed Python programs directly in HTML pages and execute them within the browser without any server-based requirements.
HTML provides many methods for text-formatting but <code> tag is displayed with fixed letter size, font, and spacing. Some points about <code> tag: It is mainly used to display the code snippet into the web browser. This tag styles its element to match the computer's default text format.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With