Last active
August 29, 2015 14:19
-
-
Save milligramme/c267bec20ee0e995adcb to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| #target "InDesign" | |
| /* | |
| NestedGrepStyleの GrepExpressionの構文エラーをさがす | |
| InDesignでは構文チェックとかしてくれない | |
| RegExpオブジェクトの生成をこころみてチェック | |
| */ | |
| var nested_grep_styles_expression_check = function (doc) { | |
| var all_para_styles = doc.allParagraphStyles; | |
| var errs = []; | |
| for (var i=0, len=all_para_styles.length; i < len ; i++) { | |
| var para_style = all_para_styles[i]; | |
| var err = validate_grep_expressions(para_style); | |
| if (err.length > 0) { | |
| // 親段落スタイル名 | |
| errs.push("::" + para_style.name); | |
| errs.push(err.join("\n")); | |
| } | |
| }; | |
| if (errs.length > 0) { | |
| // ドキュメント名 | |
| errs.unshift(":" + doc.name); | |
| var path = write_csv("~/Desktop/" + doc.name + "_NestedGrepStyleExpressionError.csv", errs.join("\n")/*, {encoding: "cp932"}*/) | |
| return path | |
| } | |
| } | |
| var validate_grep_expressions = function (para_style) { | |
| var error_mess = []; | |
| var ng_styles = para_style.nestedGrepStyles; | |
| for (var i=0, len=ng_styles.length; i < len ; i++) { | |
| var ng_style = ng_styles[i]; | |
| var grep_expression = ng_style.grepExpression; | |
| try { | |
| var regex = new RegExp(grep_expression); | |
| } | |
| catch(x_x){ | |
| error_mess.push([ | |
| x_x.message, | |
| grep_expression | |
| ].join("\t")); | |
| } | |
| }; | |
| return error_mess | |
| } | |
| // csv書出し | |
| var write_csv = function (path, string, opts) { | |
| var opts = opts || {}; | |
| var file = new File(path); | |
| file.encoding = (opts['encoding'] || 'utf-8'); | |
| file.lineFeed = (opts['lineFeed'] || 'unix'); | |
| if (file.open("w")) { | |
| file.write(string); | |
| file.close(); | |
| return path | |
| } | |
| } | |
| if (new File($.fileName).name==$.stack.replace(/[\[\]\n]/g,"")) { | |
| // 単体 | |
| // var doc = app.documents[0] | |
| // nested_grep_styles_expression_check(doc) | |
| // フォルダ | |
| var f = Folder.selectDialog('indd folder'); | |
| if (f !== null) { | |
| indds = f.getFiles(function (file) { | |
| return /\.indd$/i.test(file.name) | |
| }); | |
| app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT; | |
| var mess = []; | |
| for (var i=0, len=indds.length; i < len ; i++) { | |
| var doc = app.open(indds[i], false) | |
| var _mess = nested_grep_styles_expression_check(doc); | |
| doc.close(SaveOptions.NO); | |
| if (_mess) { | |
| mess.push(_mess) | |
| } | |
| }; | |
| app.scriptPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL; | |
| } | |
| if (mess.length > 0) { | |
| alert("Found Syntax Error\n" + mess.join("\n")); | |
| } | |
| else { | |
| alert("No Syntax Error Found"); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment