• R/O
  • HTTP
  • SSH
  • HTTPS

提交

标签
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Moxkiriyaプロジェクト事前開発用の作業部屋


Commit MetaInfo

修订版de8d33f14d21eee0c3258a5251b3dc649fbf70a1 (tree)
时间2018-09-01 11:54:33
作者Harold_Andoh <andolloyd@gmai...>
CommiterHarold_Andoh

Log Message

[Moxkiriya7]

  • 外部リンク/内部リンクのネストをなるべく正しく処理するように修正

更改概述

差异

--- a/src/com/wiki/standalone/moxkiriya/WikiMainWindowController.java
+++ b/src/com/wiki/standalone/moxkiriya/WikiMainWindowController.java
@@ -935,13 +935,12 @@ public class WikiMainWindowController implements Initializable {
935935 try {
936936 MouseEvent mouseEvent = (MouseEvent)event;
937937 EventTarget target = mouseEvent.getCurrentTarget();
938-
939938 if(isExternalLink(target) == true) {
940- externalLinkHandle(target);
941939 /*
942940 * WebEngineのデフォルトの動作(リンク先ページをロード)をキャンセル
943941 */
944- event.preventDefault();
942+ event.preventDefault();
943+ externalLinkHandle(target);
945944 }
946945 else {
947946 internalLinkHandle(target);
--- a/src/com/wiki/standalone/moxkiriya/parser/inlineparser/WikiExternalLinkInlineParser.java
+++ b/src/com/wiki/standalone/moxkiriya/parser/inlineparser/WikiExternalLinkInlineParser.java
@@ -73,9 +73,8 @@ public class WikiExternalLinkInlineParser extends WikiInlineParserBase {
7373 boolean isMatch = false;
7474
7575 Matcher startMatcher
76- = Pattern.compile(WikiExternalLinkInlineParser.PATTERN_START)
77- .matcher(line);
78-
76+ = Pattern.compile(WikiExternalLinkInlineParser.PATTERN_START).matcher(line);
77+
7978 if(startMatcher.find() == true) {
8079 /*
8180 * PATTERN_STARTの開始位置を取得
@@ -84,21 +83,12 @@ public class WikiExternalLinkInlineParser extends WikiInlineParserBase {
8483
8584 /*
8685 * 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);
9189
9290 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);
10292 }
10393 }
10494
@@ -106,19 +96,91 @@ public class WikiExternalLinkInlineParser extends WikiInlineParserBase {
10696 }
10797
10898 @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+ }
116156 }
117- else {
118- url_ = text;
119- textNode_ = text;
157+
158+ if(endIndex == -1) {
159+ endIndex = (lastIndex == -1) ? line.length() - 1 : lastIndex;
120160 }
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("["), "&#91;")
183+ .replaceAll(Pattern.quote("]"), "&#93;");
122184 }
123185
124186 @Override
@@ -161,4 +223,22 @@ public class WikiExternalLinkInlineParser extends WikiInlineParserBase {
161223 public String getEndPattern() {
162224 return PATTERN_END;
163225 }
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+ }
164244 }
--- a/src/com/wiki/standalone/moxkiriya/parser/inlineparser/WikiInternalLinkInlineParser.java
+++ b/src/com/wiki/standalone/moxkiriya/parser/inlineparser/WikiInternalLinkInlineParser.java
@@ -174,6 +174,55 @@ public class WikiInternalLinkInlineParser extends WikiInlineParserBase {
174174 }
175175
176176 @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("["), "&#91;")
220+ .replaceAll(Pattern.quote("]"), "&#93;"),
221+ split1,
222+ split2};
223+ }
224+
225+ @Override
177226 public String deleteWikiToken(String line) {
178227 String deleteTop = line.replaceFirst(Pattern.quote(WIKI_TOKEN_START), "");
179228 String deleteToken = deleteTop.substring(0, deleteTop.lastIndexOf(WIKI_TOKEN_END));