Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
アウトラインプロセッサのファイル変換 (AUTRA -> Outliner)
# Windowsのアウトラインプロセッサ "あうとら"から
# androidのアウトラインプロセッサ "Outliner"へのファイル変換
#
# あうとらでは、「階層付きテキスト」としてエクスポート。
# Outlinerでは、「bonsai CSV (UTF-8)」としてインポート。
require "csv"
def write_page(w, l, t, b)
line = [t, 0, 1, (l - 1), 0, 2, 0, "", "", "", "", "Unfiled", "", "", b]
w << line
end
txt_file_name = ARGV[0]
unless txt_file_name =~ /\.txt$/
puts "テキストファイルではありません"
exit
end
csv_file_name = txt_file_name.sub(/(.*)\.txt$/) { "#{$1}.csv" }
open(txt_file_name, "r:windows-31j") do |f|
body = title = ""
level = eline = 0
writer = CSV.open(csv_file_name, 'w:utf-8')
f.each_line do |s|
if s.start_with? ('.')
write_page(writer, level, title, body) unless title.empty?
level = s[/^(\.+)/].length
title = s[level..-1].chomp
body = ""
eline = 0
else
if s == "\n"
eline = eline + 1
else
eline.times {body << "\n"}
eline = 0
body << s
end
end
end
write_page(writer, level, title, body)
writer.close
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment