Search code examples
htmlwebweb-applicationsblogger

How to display CPP, Java or any other programming language codes in proper format in html page?


I want to write codes in proper format in a blog as Sample here

How it can be done? Is there any plugin that I need to install?


Solution

  • You can use the "Plugin" from Google called code pretiffier. First of all import the following script into your website:

    <script src="https://cdn.jsdelivr.net/gh/google/code-prettify@master/loader/run_prettify.js"></script>
    

    After you imported this, you can write the wished code into a pre tag with the class "prettyprint". It should look like this:

    <pre class="prettyprint">
       //Your custom code
    </pre>