未添加着色功能,這個比較麻煩,好比變量是什麼色,函數是什麼色,須要使用正則。python
使用blog裏自帶的python代碼着色,更改以下:print('<pre class="brush:python;toolbar:false">' + all + '</pre>')ide
效果及代碼以下:函數
# -*- coding: utf-8 -*- codedic={'"':'"',"'":''','<':'<','>':'>','&':'&'} codekey=codedic.keys() filename=input('input file path:') print(filename) f=open(filename,'r') all='' for line in f: ltmp='' for c in line: if c in codekey: ltmp+=codedic[c] elif ord(c)==9: ltmp+=' ' elif ord(c)==32: ltmp+=' ' else: ltmp+=c all=all+'<p style="margin-top: 0px; margin-bottom: 0px;">'+ltmp+'</p>' f.close() print('<pre class="brush:python;toolbar:false">' + all + '</pre>')