Guest User

Untitled

a guest
Jan 23rd, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.18 KB | None | 0 0
  1. // export_tagged_text_and_putback(app.selection[0].parentStory);
  2.  
  3. /**
  4. * export tagged text, do something and put it back
  5. */
  6. function export_tagged_text_and_putback (story) {
  7. var path = app.activeScript.parent;
  8.  
  9. //export tagged text
  10. with(app.taggedTextExportPreferences){
  11. characterSet = TagTextExportCharacterSet.SHIFT_JIS;
  12. tagFrom = TagTextForm.VERBOSE;
  13. }
  14. var tmp_file = File( path + "/_tmp.txt" );
  15. story.exportFile(ExportFormat.TAGGED_TEXT, tmp_file);
  16.  
  17. // read tagged text
  18. var a_arr = [];
  19. tmp_file.encoding = "SHIFT_JIS";
  20. if (tmp_file.open('r')) {
  21. while(! tmp_file.eof){
  22. a_arr.push( tmp_file.readln() );
  23. }
  24. };
  25. tmp_file.close();
  26. // edit tagged text
  27. var c_arr = [];
  28. for (var ai=0, aiL=a_arr.length; ai < aiL ; ai++) {
  29. b_arr = a_arr[ai].replace(/>/g,">\n").split('\n');
  30. for (var bi=0, biL=b_arr.length; bi < biL ; bi++) {
  31. // replace rubystrings
  32. if (b_arr[bi].match(/<cRubyString:[ぁ-ー]+?>/) !== null){
  33. b_arr[bi] = b_arr[bi]
  34. .replace(/ぁ/g,'あ')
  35. .replace(/ぃ/g,'い')
  36. .replace(/ぅ/g,'う')
  37. .replace(/ぇ/g,'え')
  38. .replace(/ぉ/g,'お')
  39. .replace(/っ/g,'つ')
  40. .replace(/ゃ/g,'や')
  41. .replace(/ゅ/g,'ゆ')
  42. .replace(/ょ/g,'よ')
  43. .replace(/ァ/g,'ア')
  44. .replace(/ィ/g,'イ')
  45. .replace(/ゥ/g,'ウ')
  46. .replace(/ェ/g,'エ')
  47. .replace(/ォ/g,'オ')
  48. .replace(/ッ/g,'ツ')
  49. .replace(/ャ/g,'ヤ')
  50. .replace(/ュ/g,'ユ')
  51. .replace(/ョ/g,'ヨ');
  52. }
  53. };
  54. // reconstruct tagged text
  55. c_arr.push(b_arr.join(''));
  56. };
  57. var src = c_arr.join('\n');
  58. var rev_file = File(path+"/_rest.txt");
  59. rev_file.encoding = "SHIFT_JIS";
  60. rev_file.lineFeed = "UNIX";
  61. rev_file.open('w');
  62. rev_file.write(src);
  63. rev_file.close();
  64.  
  65. // import tagged text
  66. with(app.taggedTextImportPreferences){
  67. removeTextFormatting = false;
  68. styleConflict = StyleConflict.PUBLICATION_DEFINITION;
  69. useTypographersQuotes = true;
  70. }
  71. // remove original story and place new
  72. story.remove();
  73. story.parent.place(rev_file, /*showing-option*/false);
  74.  
  75. // remove temp files
  76. tmp_file.remove();
  77. rev_file.remove();
  78. }
Add Comment
Please, Sign In to add comment