[Web] 美化網頁程式碼

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

簡介:支援各種程式語言
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""docstring with a description"""

__author__ = "子風"
__copyright__ = "Copyright 2015, Sun All rights reserved"
__version__ = "1.0.0"

import urllib.request
from io import BytesIO


def opener(username, password):
    # User Name & Password
    password_mgr = urllib.request.HTTPPasswordMgrWithDefaultRealm()
    top_level_url = 'http://www.pythonchallenge.com/'
    password_mgr.add_password(None, top_level_url, username, password)
    handler = urllib.request.HTTPBasicAuthHandler(password_mgr)

    # Proxy setting
    proxy = urllib.request.getproxies()
    proxy_support = urllib.request.ProxyHandler({'sock5': proxy.get('http')})

    # opener setting
    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
2
3
4

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

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

風格設定可參考此處

留言