Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // export_tagged_text_and_putback(app.selection[0].parentStory);
- /**
- * export tagged text, do something and put it back
- */
- function export_tagged_text_and_putback (story) {
- var path = app.activeScript.parent;
- //export tagged text
- with(app.taggedTextExportPreferences){
- characterSet = TagTextExportCharacterSet.SHIFT_JIS;
- tagFrom = TagTextForm.VERBOSE;
- }
- var tmp_file = File( path + "/_tmp.txt" );
- story.exportFile(ExportFormat.TAGGED_TEXT, tmp_file);
- // read tagged text
- var a_arr = [];
- tmp_file.encoding = "SHIFT_JIS";
- if (tmp_file.open('r')) {
- while(! tmp_file.eof){
- a_arr.push( tmp_file.readln() );
- }
- };
- tmp_file.close();
- // edit tagged text
- var c_arr = [];
- for (var ai=0, aiL=a_arr.length; ai < aiL ; ai++) {
- b_arr = a_arr[ai].replace(/>/g,">\n").split('\n');
- for (var bi=0, biL=b_arr.length; bi < biL ; bi++) {
- // replace rubystrings
- if (b_arr[bi].match(/<cRubyString:[ぁ-ー]+?>/) !== null){
- b_arr[bi] = b_arr[bi]
- .replace(/ぁ/g,'あ')
- .replace(/ぃ/g,'い')
- .replace(/ぅ/g,'う')
- .replace(/ぇ/g,'え')
- .replace(/ぉ/g,'お')
- .replace(/っ/g,'つ')
- .replace(/ゃ/g,'や')
- .replace(/ゅ/g,'ゆ')
- .replace(/ょ/g,'よ')
- .replace(/ァ/g,'ア')
- .replace(/ィ/g,'イ')
- .replace(/ゥ/g,'ウ')
- .replace(/ェ/g,'エ')
- .replace(/ォ/g,'オ')
- .replace(/ッ/g,'ツ')
- .replace(/ャ/g,'ヤ')
- .replace(/ュ/g,'ユ')
- .replace(/ョ/g,'ヨ');
- }
- };
- // reconstruct tagged text
- c_arr.push(b_arr.join(''));
- };
- var src = c_arr.join('\n');
- var rev_file = File(path+"/_rest.txt");
- rev_file.encoding = "SHIFT_JIS";
- rev_file.lineFeed = "UNIX";
- rev_file.open('w');
- rev_file.write(src);
- rev_file.close();
- // import tagged text
- with(app.taggedTextImportPreferences){
- removeTextFormatting = false;
- styleConflict = StyleConflict.PUBLICATION_DEFINITION;
- useTypographersQuotes = true;
- }
- // remove original story and place new
- story.remove();
- story.parent.place(rev_file, /*showing-option*/false);
- // remove temp files
- tmp_file.remove();
- rev_file.remove();
- }
Add Comment
Please, Sign In to add comment