Moxkiriyaプロジェクト事前開発用の作業部屋
修订版 | de8d33f14d21eee0c3258a5251b3dc649fbf70a1 (tree) |
---|---|
时间 | 2018-09-01 11:54:33 |
作者 | Harold_Andoh <andolloyd@gmai...> |
Commiter | Harold_Andoh |
[Moxkiriya7]
@@ -935,13 +935,12 @@ public class WikiMainWindowController implements Initializable { | ||
935 | 935 | try { |
936 | 936 | MouseEvent mouseEvent = (MouseEvent)event; |
937 | 937 | EventTarget target = mouseEvent.getCurrentTarget(); |
938 | - | |
939 | 938 | if(isExternalLink(target) == true) { |
940 | - externalLinkHandle(target); | |
941 | 939 | /* |
942 | 940 | * WebEngineのデフォルトの動作(リンク先ページをロード)をキャンセル |
943 | 941 | */ |
944 | - event.preventDefault(); | |
942 | + event.preventDefault(); | |
943 | + externalLinkHandle(target); | |
945 | 944 | } |
946 | 945 | else { |
947 | 946 | internalLinkHandle(target); |
@@ -73,9 +73,8 @@ public class WikiExternalLinkInlineParser extends WikiInlineParserBase { | ||
73 | 73 | boolean isMatch = false; |
74 | 74 | |
75 | 75 | Matcher startMatcher |
76 | - = Pattern.compile(WikiExternalLinkInlineParser.PATTERN_START) | |
77 | - .matcher(line); | |
78 | - | |
76 | + = Pattern.compile(WikiExternalLinkInlineParser.PATTERN_START).matcher(line); | |
77 | + | |
79 | 78 | if(startMatcher.find() == true) { |
80 | 79 | /* |
81 | 80 | * PATTERN_STARTの開始位置を取得 |
@@ -84,21 +83,12 @@ public class WikiExternalLinkInlineParser extends WikiInlineParserBase { | ||
84 | 83 | |
85 | 84 | /* |
86 | 85 | * PATTERN_ENDの開始位置を取得 |
87 | - */ | |
88 | - String subline = line.substring(startIndex + 1); | |
89 | - Matcher endMatcher = Pattern.compile(WikiExternalLinkInlineParser.PATTERN_END) | |
90 | - .matcher(subline); | |
86 | + */ | |
87 | + String startString = line.substring(startIndex + 1); | |
88 | + Matcher endMatcher = Pattern.compile(WikiExternalLinkInlineParser.PATTERN_END).matcher(startString); | |
91 | 89 | |
92 | 90 | if(endMatcher.find() == true) { |
93 | - /* | |
94 | - * schemeチェック | |
95 | - */ | |
96 | - for(String scheme: schemeList) { | |
97 | - if(subline.startsWith(scheme) == true) { | |
98 | - isMatch = true; | |
99 | - break; | |
100 | - } | |
101 | - } | |
91 | + isMatch = isSchemeString(startString); | |
102 | 92 | } |
103 | 93 | } |
104 | 94 |
@@ -106,19 +96,91 @@ public class WikiExternalLinkInlineParser extends WikiInlineParserBase { | ||
106 | 96 | } |
107 | 97 | |
108 | 98 | @Override |
109 | - public String deleteWikiToken(String line) { | |
110 | - String deleteTop = line.replaceFirst(Pattern.quote(WIKI_TOKEN_START), ""); | |
111 | - String text = deleteTop.substring(0, deleteTop.lastIndexOf(WIKI_TOKEN_END)); | |
112 | - | |
113 | - if(text.contains("|") == true) { | |
114 | - url_ = text.substring(0, text.indexOf("|")); | |
115 | - textNode_ = text.substring(text.indexOf("|") + "|".length()); | |
99 | + public String[] devideLine(String line) { | |
100 | + int depth = 0; | |
101 | + char[] charArrayLine = line.toCharArray(); | |
102 | + int startIndex = -1; | |
103 | + int endIndex = -1; | |
104 | + int lastIndex = -1; | |
105 | + boolean withinElem = false; | |
106 | + | |
107 | + for(int count = 0; count < charArrayLine.length; count++) { | |
108 | + if(charArrayLine[count] == '>') { | |
109 | + withinElem = false; | |
110 | + continue; | |
111 | + } else if(charArrayLine[count] == '<') { | |
112 | + withinElem = true; | |
113 | + } | |
114 | + | |
115 | + if(withinElem == true) { | |
116 | + /* | |
117 | + * HTML要素内をスキップ | |
118 | + */ | |
119 | + continue; | |
120 | + } | |
121 | + | |
122 | + if(charArrayLine[count] == '[') { | |
123 | + String startString = line.substring(count + 1); | |
124 | + if(isSchemeString(startString) == true) { | |
125 | + if(startIndex != -1) { | |
126 | + /* | |
127 | + * 次の外部リンクの開始の場合、 | |
128 | + */ | |
129 | + endIndex = lastIndex; | |
130 | + break; | |
131 | + } | |
132 | + else if(depth == 0) { | |
133 | + startIndex = count; | |
134 | + } | |
135 | + } | |
136 | + else if(startString.startsWith("[")) { | |
137 | + /* | |
138 | + * 内部リンクの開始に到達した場合、 | |
139 | + */ | |
140 | + endIndex = lastIndex; | |
141 | + break; | |
142 | + } | |
143 | + depth++; | |
144 | + } | |
145 | + else if(charArrayLine[count] == ']') { | |
146 | + lastIndex = count; | |
147 | + if(depth > 0) { | |
148 | + depth--; | |
149 | + | |
150 | + if(depth == 0) { | |
151 | + endIndex = count; | |
152 | + break; | |
153 | + } | |
154 | + } | |
155 | + } | |
116 | 156 | } |
117 | - else { | |
118 | - url_ = text; | |
119 | - textNode_ = text; | |
157 | + | |
158 | + if(endIndex == -1) { | |
159 | + endIndex = (lastIndex == -1) ? line.length() - 1 : lastIndex; | |
120 | 160 | } |
121 | - return textNode_; | |
161 | + | |
162 | + String split0 = line.substring(0, startIndex); | |
163 | + String split1 = line.substring(startIndex, endIndex + 1); | |
164 | + String split2 = line.substring(endIndex + 1); | |
165 | + | |
166 | + return new String[] {split0, split1, split2}; | |
167 | + } | |
168 | + | |
169 | + @Override | |
170 | + public String deleteWikiToken(String line) { | |
171 | + String deleteTop = line.replaceFirst(Pattern.quote(WIKI_TOKEN_START), ""); | |
172 | + String text = deleteTop.substring(0, deleteTop.lastIndexOf(WIKI_TOKEN_END)); | |
173 | + | |
174 | + if(text.contains("|") == true) { | |
175 | + url_ = text.substring(0, text.indexOf("|")); | |
176 | + textNode_ = text.substring(text.indexOf("|") + "|".length()); | |
177 | + } | |
178 | + else { | |
179 | + url_ = text; | |
180 | + textNode_ = text; | |
181 | + } | |
182 | + return textNode_.replaceAll(Pattern.quote("["), "[") | |
183 | + .replaceAll(Pattern.quote("]"), "]"); | |
122 | 184 | } |
123 | 185 | |
124 | 186 | @Override |
@@ -161,4 +223,22 @@ public class WikiExternalLinkInlineParser extends WikiInlineParserBase { | ||
161 | 223 | public String getEndPattern() { |
162 | 224 | return PATTERN_END; |
163 | 225 | } |
226 | + | |
227 | + /** | |
228 | + * lineがscheme文字列で始まるか判定する。 | |
229 | + * @param line | |
230 | + * @return 判定結果 | |
231 | + */ | |
232 | + private static boolean isSchemeString(String line) { | |
233 | + boolean result = false; | |
234 | + | |
235 | + for(String scheme: schemeList) { | |
236 | + if(line.startsWith(scheme) == true) { | |
237 | + result = true; | |
238 | + break; | |
239 | + } | |
240 | + } | |
241 | + | |
242 | + return result; | |
243 | + } | |
164 | 244 | } |
@@ -174,6 +174,55 @@ public class WikiInternalLinkInlineParser extends WikiInlineParserBase { | ||
174 | 174 | } |
175 | 175 | |
176 | 176 | @Override |
177 | + public String[] devideLine(String line) { | |
178 | + char[] charArrayLine = line.toCharArray(); | |
179 | + int startIndex = -1; | |
180 | + int endIndex = -1; | |
181 | + boolean withinElem = false; | |
182 | + | |
183 | + for(int count = 0; count < charArrayLine.length; count++) { | |
184 | + if(charArrayLine[count] == '>') { | |
185 | + withinElem = false; | |
186 | + continue; | |
187 | + } else if(charArrayLine[count] == '<') { | |
188 | + withinElem = true; | |
189 | + } | |
190 | + | |
191 | + if(withinElem == true) { | |
192 | + /* | |
193 | + * HTML要素内をスキップ | |
194 | + */ | |
195 | + continue; | |
196 | + } | |
197 | + | |
198 | + if(charArrayLine[count] == '[') { | |
199 | + String startString = line.substring(count); | |
200 | + if(startString.startsWith(WIKI_TOKEN_START) == true) { | |
201 | + startIndex = count; | |
202 | + } | |
203 | + } | |
204 | + else if(charArrayLine[count] == ']') { | |
205 | + if(startIndex != -1) { | |
206 | + String endString = line.substring(count); | |
207 | + if(endString.startsWith(WIKI_TOKEN_END) == true) { | |
208 | + endIndex = count; | |
209 | + break; | |
210 | + } | |
211 | + } | |
212 | + } | |
213 | + } | |
214 | + | |
215 | + String split0 = line.substring(0, startIndex); | |
216 | + String split1 = line.substring(startIndex, endIndex + 2); | |
217 | + String split2 = line.substring(endIndex + 2); | |
218 | + | |
219 | + return new String[] {split0.replaceAll(Pattern.quote("["), "[") | |
220 | + .replaceAll(Pattern.quote("]"), "]"), | |
221 | + split1, | |
222 | + split2}; | |
223 | + } | |
224 | + | |
225 | + @Override | |
177 | 226 | public String deleteWikiToken(String line) { |
178 | 227 | String deleteTop = line.replaceFirst(Pattern.quote(WIKI_TOKEN_START), ""); |
179 | 228 | String deleteToken = deleteTop.substring(0, deleteTop.lastIndexOf(WIKI_TOKEN_END)); |