Created
August 1, 2012 07:37
-
-
Save tekei/3224645 to your computer and use it in GitHub Desktop.
アウトラインプロセッサのファイル変換 (AUTRA -> Outliner)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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