diff options
author | haturatu <taro@eyes4you.org> | 2024-09-01 02:04:57 +0900 |
---|---|---|
committer | haturatu <taro@eyes4you.org> | 2024-09-01 02:04:57 +0900 |
commit | f08411e3d4cec3be138eaef300fa419b02bd286d (patch) | |
tree | 3926a6c14efe708ab9428530b932601bd63afa07 /md.rb |
first commit
Diffstat (limited to 'md.rb')
-rwxr-xr-x | md.rb | 26 |
1 files changed, 26 insertions, 0 deletions
@@ -0,0 +1,26 @@ +#!/usr/bin/env ruby + +def convert_to_markdown(input_file, output_file) + content = File.read(input_file, encoding: 'utf-8') + + pairs = content.scan(/URL: (.*?)\nTitle: (.*?)\n/m) + + File.open(output_file, 'w', encoding: 'utf-8') do |f| + pairs.each do |url, title| + # URLが空でない場合のみ処理 + next if url.strip.empty? + + # タイトルが空の場合、URLの最後の部分を使用 + title = url.split('/')[-1] if title.strip.empty? + + # 特殊文字をエスケープ + title = title.gsub('[', '\\[').gsub(']', '\\]') + + # md形式のリンクを作成 + markdown_link = "[#{title}](#{url})\n\n" + f.write(markdown_link) + end + end +end + +convert_to_markdown('Result', 'Result.md') |