[Web] 美化網頁程式碼

程式語言:JavaScript
工具:google code-prettify

簡介:支援各種程式語言
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. """docstring with a description"""
  4.  
  5. __author__ = "子風"
  6. __copyright__ = "Copyright 2015, Sun All rights reserved"
  7. __version__ = "1.0.0"
  8.  
  9. import urllib.request
  10. from io import BytesIO
  11.  
  12.  
  13. def opener(username, password):
  14. # User Name & Password
  15. password_mgr = urllib.request.HTTPPasswordMgrWithDefaultRealm()
  16. top_level_url = 'http://www.pythonchallenge.com/'
  17. password_mgr.add_password(None, top_level_url, username, password)
  18. handler = urllib.request.HTTPBasicAuthHandler(password_mgr)
  19.  
  20. # Proxy setting
  21. proxy = urllib.request.getproxies()
  22. proxy_support = urllib.request.ProxyHandler({'sock5': proxy.get('http')})
  23.  
  24. # opener setting
  25. return urllib.request.build_opener(proxy_support, handler)

引用

<script src="https://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js"></script>

使用方法

兩種皆可
<pre class="prettyprint">...</pre> 
<code class="prettyprint">...</code>

加入行號

加入 linenums
<pre class="prettyprint linenums">
  1. 1
  2. 2
  3. 3
  4. 4

加上數字為指定初始值
<pre class="prettyprint linenums:4">
  1. 4
  2. 5
  3. 6
  4. 7

預設行號為每五行跳一次
需設定 list-style-type: decimal
  1. li.L0, li.L1, li.L2, li.L3,
  2. li.L5, li.L6, li.L7, li.L8
  3. { list-style-type: decimal !important }
  4. </style>

風格設定可參考此處

留言