タイトルのスクリプトをChatGPT(無料。2025/06/08)で作ってもらった。
作ってもらったもの
import re
def convert_to_markdown(text):
# コードブロックの変換
text = re.sub(r"(?i)`{3,}\s*(\w+)?\n(.*?)\n`{3,}", r"```\1\n\2\n```", text, flags=re.DOTALL)
# プレーンなコード行(インデントされている)
text = re.sub(r"(^|\n)( |\t)(.*)", r"\1 \3", text)
# 見出し変換(例: "## " で始まる行)
text = re.sub(r"^#+ .*$", lambda m: m.group(0).strip(), text, flags=re.MULTILINE)
# 箇条書きの正規化
text = re.sub(r"^\s*[-*・●] ?", "- ", text, flags=re.MULTILINE)
# リンク変換(httpで始まるURLに<>をつける)
text = re.sub(r"(http[s]?://[^\s)]+)", r"<\1>", text)
return text.strip()
# 実行例
if __name__ == "__main__":
print("=== ChatGPT Output to Markdown Converter ===")
input_file = "chat_output.txt"
output_file = "output.md"
with open(input_file, "r", encoding="utf-8") as f:
content = f.read()
md_content = convert_to_markdown(content)
with open(output_file, "w", encoding="utf-8") as f:
f.write(md_content)
print(f"✅ Markdown形式に変換しました → {output_file}")
評価
すごく、野心的だけど。。。。 弊害多し。 使ってみて下さい。コメント等頂けると、さらに、ありがたい。