自己用的md转Discuz程序
本帖最后由 Ewan-Ahiouy 于 2023-7-21 07:24 编辑Tw大佬的转换器不咋好用,不支持列表和表格,于是自己做了一个自己用,大佬别喷{:10_278:}
import os
def zhuanhuan(t):
t = t.split("\n")
ret = ""
k = True
kk = True
e = True
for i in range(len(t)):
e = True
if "-" not in t and "#" not in t and "|" not in t:
if not k:
k = True
ret += "\n"
if not kk:
kk = True
ret += "\n"
ret += t + "\n"
continue
if "# " in t and t + t == "# ":
ret += "" + t + ""
if t + t == "- " and k:
k = False
ret += "\n" + "[*]" + t
elif t + t == "- ":
ret += "[*]" + t
if t == "|" and t.count("|") >= 3 and kk:
kk = False
ret += ""
elif t == "|" and ":" not in t:
r = t.split("|")
m = ""
for i in r:
if i:
m += "" + i + ""
ret += "" + m + ""
elif t == "|" and ":" in t:
e = False
if e:
ret += "\n"
return ret
e = input("请输入文件名:")
oslist = os.listdir()
x = e + ".md"
if x not in oslist:
print("没有这个文件!")
else:
f = open(x, "r", encoding="utf-8")
t = f.read() + "\n\n\n"
f.close()
zhuan = zhuanhuan(t)
f = open("new_" + e + ".txt", "w", encoding="utf-8")
f.write(zhuan)
print("OK~")
这个代码只是用来转换我的英语笔记而已,所以没有多少功能{:10_292:}
仅支持最大标题、列表、表格而已{:10_255:}
以后可能会更GUI版{:9_226:}
第二代更新:
支持代码格式
import os
def zhuanhuan(t):
t = t.split("\n")
ret = ""
k = True
kk = True
e = True
g = True
for i in range(len(t)):
e = True
if "-" not in t and "# " not in t and "|" not in t and "```" not in t:
if not k:
k = True
ret += "\n"
if not kk:
kk = True
ret += "\n"
ret += t + "\n"
continue
if "# " in t and t + t == "# " and "" not in t:
ret += "" + t + ""
if t + t == "- " and k:
k = False
ret += "\n" + "[*]" + t
elif t + t == "- ":
ret += "[*]" + t
if t == "|" and t.count("|") >= 3 and kk:
kk = False
ret += ""
elif t == "|" and ":" not in t:
r = t.split("|")
m = ""
for j in r:
if i:
m += "" + j + ""
ret += "" + m + ""
elif t == "|" and ":" in t:
e = False
if "`" in t:
g = not g
if not g:
ret += ""
else:
ret += ""
if e:
ret += "\n"
return ret
e = input("请输入文件名:")
oslist = os.listdir()
x = e + ".md"
if x not in oslist:
print("没有这个文件!")
else:
f = open(x, "r", encoding="utf-8")
t = f.read() + "\n\n\n"
f.close()
zhuan = zhuanhuan(t)
f = open("new_" + e + ".txt", "w", encoding="utf-8")
f.write(zhuan)
print("OK~")
建议把引用加上
liuhongrun2022 发表于 2023-7-19 13:45
建议把引用加上
这只是我英语笔记用的而已{:10_330:}
但是以后可能会出{:10_323:} 可惜没评分次数了,不过还是力顶 大佬好厉害求给我评点封,我想赶快升级 https://fishc.com.cn/thread-231007-1-1.html
我的第一个作品!!!
页:
[1]