関連
処理概要
はてな記法のテーブル表記をMarkdown記法にする。
| 1 | 2 |
| | |
| | |
テスト
| 1 | 2 |
| | |
| | |
| 1 | 2 |
|:-:|:-:|
| | |
| | |
テスト
| 1 | 2 |
|:-:|:-:|
| | |
| | |
code v0.1
import sys
# on Python 3.5
# read from stdin
lines = sys.stdin.readlines()
def getTableFormat(numVertical):
wrk = "|"
for loop in range(numVertical - 1): # -1: except for first
wrk += ":-:|"
return wrk
count = 0
for elem in lines:
wrk = elem
if "|" in wrk:
count += 1
if count == 2:
num = wrk.count('|')
fmt = getTableFormat(num)
print(fmt)
else:
count = 0
print(elem, end='')
code v0.2
import sys
# on Python 3.5
'''
v0.1 Apr. 24, 2018
- sub list is converted to Markdown style
'''
# read from stdin
lines = sys.stdin.readlines()
def getTableFormat(numVertical):
wrk = "|"
for loop in range(numVertical - 1): # -1: except for first
wrk += ":-:|"
return wrk
def conv_tableFormat(astr):
global countTbl
if "|" in astr:
countTbl += 1
if countTbl == 2:
num = astr.count('|')
fmt = getTableFormat(num)
return fmt + "\r\n" + astr
else:
countTbl = 0
return astr
countTbl = 0 # Table format counter
for elem in lines:
wrk = conv_tableFormat(elem)
print(wrk, end='')