How do I show code of any language on a web page? [closed]

1

I'm doing a blog with Bootstrap (to save me time in the design) and with php. What I want is to go publishing programming codes (php, jquery, html, css, java, etc) and I do not know how to make it appear on the page.

    
asked by Sagara 28.02.2017 в 01:03
source

1 answer

1

Good morning.

You can use google Pretify , which is the code highlight used by StackOverflow . This is the example that exists in the same script repository

.

Another example is:

<script src="https://rawgit.com/google/code-prettify/master/loader/run_prettify.js?autoload=true&skin=desert"></script>


<h1>Ejemplo de código</h1>
<p>
El contenido que está abajo está formateado.
</p>

<p>La etiqueta <code>&lt;pre&gt;</code>
está formateada por que tiene <code>class="prettyprint"</code> y por que se incluye una librería javascript que genera la estructura necesaria para mostar el código.
</p>

<?prettify lang=java linenums=true?>
<pre class="prettyprint" >
public class Main {

    public static void main(String[] args) {

        double angulo = Math.toRadians(60),
                calcularPorSerie = serieTaylor(angulo),
                calcularPorMath = Math.cos(angulo);

        System.out.println("Serie: " + calcularPorSerie);
        System.out.println("Cos: " + calcularPorMath);
    }

    static double serieTaylor(double x) {
        double sumando, sumatoria = 0, precision = 0.0001d;

        // limite superior, iteracion de la sumatoria
        int n = 0; 

        do {
            sumando = Math.pow(-1, n) / factorial(2 * n) * Math.pow(x, 2 * n);
            sumatoria = sumatoria + sumando;
            n = n + 1;
        } while (Math.abs(sumando) > precision);

        return sumatoria;
    }

    static double factorial(int numero) {
        double factorial = 1.0d;

        while (numero != 0) {
            factorial *= numero--;
        }

        return factorial;
    }
}</pre>
    
answered by 28.02.2017 / 05:22
source