動作環境
ideone (Python 3.5)
関連
- Python3 > colorText_180707.py > v0.1 > optという文字に色付けした結果を出力
- Python3 > colorText_180707.py > v0.2 > 実行時引数によるキーワード指定 (sys.argvの使用) || v0.3 > 改行用に
追加
ideone動作版
Pythonを実行できない環境でソースの色付けをできるようにするためideoneで動作する実装に変更。
import sys
import re
'''
v0.2 Jul. 08, 2018
- fix bug > color attributed using double quotation
v0.1 Jul. 08, 2018
- add <BR> for each new line
- read from stdin
=== branched from [colorText_180707.py] v0.1 ===
v0.1 Jul. 07, 2018
- add color html tag for a fixed text ('opt')
'''
# on Python 3.5.2
# --- Configuration ----
COL_TEXT = 'opt'
# ---
SRC_FILE = 'in_180707.txt'
inRed = '<font color="red">' + COL_TEXT + '</font>'
lines = sys.stdin.readlines()
for aline in lines:
wrk = aline.replace(COL_TEXT, inRed)
print(wrk, end='<BR>')
使い方
- https://ideone.com/q6NUyd をforkする
- enter input (stdin)に色付けしたいテキストをペースト
- コード中の
COL_TEXT
に色付けしたいテキストを指定 - Run
- stdoutの内容をコピー
- 任意の名前のhtmlファイルとして保存 (例: tmp.html)
- ブラウザで開く
Python環境での実行版とどちらが使いやすいか。