code-prettify 代码格式化
原创    bluesky    发表于:2018-04-28 10:51:24
  阅读 :131   收藏   编辑

github地址:https://github.com/google/code-prettify

下载:prettify-small.zip

页面引用

<link href="~google-code-prettify/prettify.css" rel="stylesheet" type="text/css" >
<script src="~google-code-prettify/prettify.js" type="text/javascript" ></script>

添加样式,默认每隔5行显示,添加以下css每行都可显示

<style type="text/css">
li.L0, li.L1, li.L2, li.L3,li.L5, li.L6, li.L7, li.L8{ list-style-type: decimal !important }
</style>

body添加onload事件

<body onload="PR.prettyPrint()">

pre 标签添加prettyprint linenums

<pre class="prettyprint linenums">

    code~

</pre>

完整代码

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <title></title>
        <link href="js/google-code-prettify/prettify.css" rel="stylesheet" type="text/css" >
        <script src="js/google-code-prettify/prettify.js" type="text/javascript" ></script>
        <style type="text/css">
        li.L0, li.L1, li.L2, li.L3,li.L5, li.L6, li.L7, li.L8{ list-style-type: decimal !important }
        </style>

    </head>
    <body onload="PR.prettyPrint()"> 

            <pre class="prettyprint linenums">
package com.plus;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class ArticleQr
 */
public class ArticleQr extends HttpServlet {

    private static final long serialVersionUID = 1L;

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }

}

         </pre>

    </body>
</html>

显示结果

评论
条评论