• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Keine Tags

Frequently used words (click to add to your profile)

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

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


Commit MetaInfo

Revision7c1d308b25ab0264a315f8875647d789e25a3020 (tree)
Zeit2018-08-25 08:53:24
AutorHarold_Andoh <andolloyd@gmai...>
CommiterHarold_Andoh

Log Message

[Moxkiriya7]

  • blockquoteマークアップに対応
  • <div>, <p>要素の範囲があいまいだったのを整理、改善

Ändern Zusammenfassung

Diff

--- a/src/com/wiki/standalone/moxkiriya/parser/blockparser/WikiBlockParserCreator.java
+++ b/src/com/wiki/standalone/moxkiriya/parser/blockparser/WikiBlockParserCreator.java
@@ -62,6 +62,12 @@ public class WikiBlockParserCreator {
6262 return new WikiOrderedListBlockParser(file);
6363 }
6464 } );
65+ put(WikiBlockquoteBlockParser.NOTATION_REGEX, new Creator() {
66+ @Override
67+ public WikiBlockParser create(File file) {
68+ return new WikiBlockquoteBlockParser(file);
69+ }
70+ } );
6571 put(WikiPreBlockParser.NOTATION_REGEX, new Creator() {
6672 @Override
6773 public WikiBlockParser create(File file) {
--- /dev/null
+++ b/src/com/wiki/standalone/moxkiriya/parser/blockparser/WikiBlockquoteBlockParser.java
@@ -0,0 +1,135 @@
1+/**
2+ * Moxkiriya standalone Wiki.
3+ * Unordered list block parser.
4+ *
5+ * @author Ryuhei Terada
6+ * See the '<a href="{@docRoot}/copyright.html">Copyright</a>'
7+ */
8+package com.wiki.standalone.moxkiriya.parser.blockparser;
9+
10+import java.io.File;
11+
12+/**
13+ * 番号なしリストのマークアップを解析し、HTML形式に変換する。
14+ *
15+ */
16+public class WikiBlockquoteBlockParser extends WikiBlockParserBase {
17+ private static final String START_TAG = "<blockquote";
18+
19+ private static final String END_TAG = "</blockquote>\n";
20+
21+ /** WIKI記法の正規表現文字列 行頭パターン */
22+ private static final String NOTATION_REGEX_LINEHEAD = "^>";
23+
24+ /** WIKI記法の正規表現文字列 行末パターン */
25+ private static final String NOTATION_REGEX_LINETAIL = "";
26+
27+ /** WIKI記法の正規表現文字列 */
28+ public static final String NOTATION_REGEX = NOTATION_REGEX_LINEHEAD
29+ + "..*"
30+ + NOTATION_REGEX_LINETAIL;
31+
32+ /** ブロック終了状態 */
33+ private boolean isBlockEnd_ = false;
34+
35+ /** 処理終了後の残り文字列 */
36+ private String remain_;
37+
38+ /**
39+ *  コンストラクタ
40+ */
41+ public WikiBlockquoteBlockParser(File file) {
42+ this(file, Status.INIT);
43+ }
44+
45+ /**
46+ *  コンストラクタ
47+ */
48+ public WikiBlockquoteBlockParser(File file, Status status) {
49+ super(file);
50+ status_ = status;
51+ }
52+
53+ @Override
54+ public String startElementProcess(String line, StringBuffer buf) {
55+ status_ = Status.OPEN;
56+ buf.append(START_TAG + " class=\"quotation\">");
57+ return line;
58+ }
59+
60+ @Override
61+ public String parse(String line, StringBuffer buf) throws Exception {
62+ if(line.matches(NOTATION_REGEX) == true) {
63+ String token = line.substring(line.indexOf(">"));
64+ int countToken = countToken(token);
65+ if(countToken > 1) {
66+ /*
67+ * '>'を一つ減らして子parserへ渡す。
68+ */
69+ String daughterPart = token.substring(1);
70+
71+ if(status_ == Status.OPEN) {
72+ startDaughterParse(new WikiBlockParserCreator.Creator() {
73+ @Override
74+ public WikiBlockquoteBlockParser create(File file) {
75+ return new WikiBlockquoteBlockParser(file, Status.OPEN);
76+ }
77+ });
78+
79+ daughterParser_.startElementProcess(daughterPart, buf);
80+ }
81+ daughterParser_.parse(daughterPart, buf);
82+ }
83+ else {
84+ if(status_ == Status.NESTING) {
85+ /*
86+ * トークンが1つでネスト処理中の場合、
87+ * ネスト処理を終了する。
88+ */
89+ daughterParser_.endElementProcess(line, buf);
90+ daughterParser_ = null;
91+ status_ = Status.OPEN;
92+ }
93+ buf.append("<div>");
94+ super.parse(token.substring(countToken), buf);
95+ buf.append("</div>\n");
96+ remain_ = "";
97+ }
98+ }
99+ else {
100+ isBlockEnd_ = true;
101+ remain_ = line;
102+ }
103+
104+ return "";
105+ }
106+
107+ @Override
108+ public String endElementProcess(String line, StringBuffer buf) {
109+ if(status_ == Status.NESTING) {
110+ daughterParser_.endElementProcess(line, buf);
111+ }
112+ buf.append(END_TAG + "\n");
113+ return remain_;
114+ }
115+
116+ @Override
117+ public boolean isBlockEnd() {
118+ return isBlockEnd_;
119+ }
120+
121+ /**
122+ * lineの行頭からの#の数をカウントする。
123+ * @param line
124+ * @return 行頭からの#の数
125+ */
126+ private int countToken(String line) {
127+ int count = 0;
128+ for(count = 0; count < line.length(); count++) {
129+ if('>' != line.charAt(count)) {
130+ break;
131+ }
132+ }
133+
134+ return count;
135+ }}
--- a/src/com/wiki/standalone/moxkiriya/parser/blockparser/WikiBodyBlockParser.java
+++ b/src/com/wiki/standalone/moxkiriya/parser/blockparser/WikiBodyBlockParser.java
@@ -88,12 +88,7 @@ public class WikiBodyBlockParser {
8888 tagBuf.append(lineCharArray[count]);
8989 }
9090 else {
91- if(lineCharArray[count] == '>') {
92- buf.append("&gt;");
93- }
94- else {
95- buf.append(lineCharArray[count]);
96- }
91+ buf.append(lineCharArray[count]);
9792 }
9893 }
9994 else if(status == PreprocessStatus.OPEN) {
@@ -111,12 +106,11 @@ public class WikiBodyBlockParser {
111106 /*
112107 * acceptリストにないタグパターンの場合
113108 */
114- buf.append(tag.replaceAll("<", "lt;")
109+ buf.append(tag.replaceAll("<", "&lt;")
115110 .replaceAll(">", "&gt;"));
116111 tagBuf = null;
117112 }
118113 status = PreprocessStatus.INIT;
119-
120114 }
121115 }
122116 else {
@@ -140,6 +134,7 @@ public class WikiBodyBlockParser {
140134 */
141135 private String parseCore(BufferedReader reader) throws Exception {
142136 StringBuffer buf = new StringBuffer("");
137+ StringBuffer paragraphBuf = null;
143138 String line = null;
144139 ParseStatus status = ParseStatus.INIT;
145140
@@ -150,47 +145,45 @@ public class WikiBodyBlockParser {
150145 /*
151146 * XSS殺し
152147 */
153- line = parsePreprocess(line);
154- if(status == ParseStatus.OPEN) {
155- if(line.isEmpty() == true) {
156- /*
157- * 空白行があった場合、 paragraphを刷新する。
158- */
159- buf.append("</p>\n");
160- status = ParseStatus.CLOSE;
161- continue;
148+ String processingline = parsePreprocess(line);
149+
150+ do {
151+ if(status != ParseStatus.OPEN) {
152+ status = ParseStatus.OPEN;
153+ paragraphBuf = new StringBuffer();
162154 }
163- }
164-
165- while(line.isEmpty() != true) {
155+
166156 if(parser == null) {
167- if(status != ParseStatus.OPEN) {
168- buf.append("<p>\n");
169- status = ParseStatus.OPEN;
170- }
171-
172- buf.append("<div>\n");
173- parser = blockParserCreator.create(line, file_);
174- line = parser.startElementProcess(line, buf);
157+ parser = blockParserCreator.create(processingline, file_);
158+ processingline = parser.startElementProcess(processingline, paragraphBuf);
175159 }
176-
177- line = parser.parse(line, buf);
160+
161+ processingline = parser.parse(processingline, paragraphBuf);
178162
179163 if(parser.isBlockEnd() == true) {
180- line = parser.endElementProcess(line, buf);
164+ processingline = parser.endElementProcess(processingline, paragraphBuf);
181165 parser = null;
182- buf.append("</div>\n");
166+
167+ if(line.isEmpty() == true) {
168+ buf.append("<p>\n");
169+ buf.append(paragraphBuf + "\n");
170+ buf.append("</p>\n");
171+
172+ status = ParseStatus.CLOSE;
173+ paragraphBuf = null;
174+ }
183175 }
184- }
176+ } while(processingline.isEmpty() != true);
185177 }
186178
187- if(parser != null) {
188- parser.endElementProcess(line, buf);
189- buf.append("</div>\n");
190- if(status == ParseStatus.OPEN) {
191- buf.append("</p>\n");
192- status = ParseStatus.CLOSE;
179+ if(status == ParseStatus.OPEN) {
180+ if(parser != null) {
181+ parser.endElementProcess(line, paragraphBuf);
193182 }
183+ buf.append("<p>\n");
184+ buf.append(paragraphBuf + "\n");
185+ buf.append("</p>\n");
186+ status = ParseStatus.CLOSE;
194187 }
195188
196189 return buf.toString();
--- a/src/com/wiki/standalone/moxkiriya/parser/blockparser/WikiDefaultBlockParser.java
+++ b/src/com/wiki/standalone/moxkiriya/parser/blockparser/WikiDefaultBlockParser.java
@@ -17,7 +17,9 @@ public class WikiDefaultBlockParser extends WikiBlockParserBase {
1717
1818 @Override
1919 public String parse(String line, StringBuffer buf) throws Exception {
20+ buf.append("<div>");
2021 buf.append(inlineParse(line));
22+ buf.append("</div>\n");
2123 return "";
2224 }
2325
--- a/src/com/wiki/standalone/moxkiriya/parser/blockparser/WikiH2BlockParser.java
+++ b/src/com/wiki/standalone/moxkiriya/parser/blockparser/WikiH2BlockParser.java
@@ -3,9 +3,9 @@ package com.wiki.standalone.moxkiriya.parser.blockparser;
33 import java.io.File;
44
55 public class WikiH2BlockParser extends WikiBlockParserBase {
6- private static final String START_TAG = "<h2>";
6+ private static final String START_TAG = "<div><h2>";
77
8- private static final String END_TAG = "</h2>\n";
8+ private static final String END_TAG = "</h2></div>\n";
99
1010 /** WIKI記法の正規表現文字列 行頭パターン */
1111 private static final String NOTATION_REGEX_LINEHEAD = "^==";
@@ -34,7 +34,7 @@ public class WikiH2BlockParser extends WikiBlockParserBase {
3434
3535 @Override
3636 public String endElementProcess(String line, StringBuffer buf) {
37- buf.append(END_TAG + "\n");
37+ buf.append(END_TAG);
3838 return "";
3939 }
4040
--- a/src/com/wiki/standalone/moxkiriya/parser/blockparser/WikiH3BlockParser.java
+++ b/src/com/wiki/standalone/moxkiriya/parser/blockparser/WikiH3BlockParser.java
@@ -3,9 +3,9 @@ package com.wiki.standalone.moxkiriya.parser.blockparser;
33 import java.io.File;
44
55 public class WikiH3BlockParser extends WikiH2BlockParser {
6- private static final String START_TAG = "<h3>";
6+ private static final String START_TAG = "<div><h3>";
77
8- private static final String END_TAG = "</h3>\n";
8+ private static final String END_TAG = "</h3></div>\n";
99
1010 /** WIKI記法の正規表現文字列 行頭パターン */
1111 private static final String NOTATION_REGEX_LINEHEAD = "^===";
@@ -34,7 +34,7 @@ public class WikiH3BlockParser extends WikiH2BlockParser {
3434
3535 @Override
3636 public String endElementProcess(String line, StringBuffer buf) {
37- buf.append(END_TAG + "\n");
37+ buf.append(END_TAG);
3838 return "";
3939 }
4040
--- a/src/com/wiki/standalone/moxkiriya/parser/blockparser/WikiHrBlockParser.java
+++ b/src/com/wiki/standalone/moxkiriya/parser/blockparser/WikiHrBlockParser.java
@@ -5,7 +5,7 @@ import java.io.File;
55 public class WikiHrBlockParser extends WikiBlockParserBase {
66 private static final String START_TAG = "<hr>";
77
8- private static final String END_TAG = "\n";
8+ private static final String END_TAG = "";
99
1010 /** WIKI記法の正規表現文字列 行頭パターン */
1111 private static final String NOTATION_REGEX_LINEHEAD = "^----";
@@ -32,7 +32,7 @@ public class WikiHrBlockParser extends WikiBlockParserBase {
3232
3333 @Override
3434 public String endElementProcess(String line, StringBuffer buf) {
35- buf.append(END_TAG + "\n");
35+ buf.append(END_TAG);
3636 return "";
3737 }
3838
--- a/src/com/wiki/standalone/moxkiriya/parser/blockparser/WikiOrderedListBlockParser.java
+++ b/src/com/wiki/standalone/moxkiriya/parser/blockparser/WikiOrderedListBlockParser.java
@@ -14,9 +14,9 @@ import java.io.File;
1414 *
1515 */
1616 public class WikiOrderedListBlockParser extends WikiBlockParserBase {
17- private static final String START_TAG = "<ol>\n";
17+ private static final String START_TAG = "<div><ol>\n";
1818
19- private static final String END_TAG = "</ol>\n";
19+ private static final String END_TAG = "</ol></div>\n";
2020
2121 /** WIKI記法の正規表現文字列 行頭パターン */
2222 private static final String NOTATION_REGEX_LINEHEAD = "^[ \t]*"
--- a/src/com/wiki/standalone/moxkiriya/parser/blockparser/WikiTableBlockParser.java
+++ b/src/com/wiki/standalone/moxkiriya/parser/blockparser/WikiTableBlockParser.java
@@ -13,10 +13,10 @@ import java.util.regex.Pattern;
1313
1414 public class WikiTableBlockParser extends WikiBlockParserBase {
1515 /** startタグ */
16- private static final String START_TAG = "<table";
16+ private static final String START_TAG = "<div><table";
1717
1818 /** endタグ*/
19- private static final String END_TAG = "</table>\n";
19+ private static final String END_TAG = "</table></div>\n";
2020
2121 /** WIKI記法の正規表現文字列 行頭パターン */
2222 private static final String NOTATION_REGEX_LINEHEAD = "^[ \t]*"
--- a/src/com/wiki/standalone/moxkiriya/parser/blockparser/WikiTableRowBlockParser.java
+++ b/src/com/wiki/standalone/moxkiriya/parser/blockparser/WikiTableRowBlockParser.java
@@ -172,7 +172,7 @@ public class WikiTableRowBlockParser extends WikiBlockParserBase {
172172 status_ = Status.OPEN;
173173 }
174174 flushRowBuf(buf);
175- buf.append(tagpair_.endTag_ + "\n");
175+ buf.append(tagpair_.endTag_);
176176 return remain_;
177177 }
178178
--- a/src/com/wiki/standalone/moxkiriya/parser/blockparser/WikiUnorderedListBlockParser.java
+++ b/src/com/wiki/standalone/moxkiriya/parser/blockparser/WikiUnorderedListBlockParser.java
@@ -15,9 +15,9 @@ import java.util.regex.Pattern;
1515 *
1616 */
1717 public class WikiUnorderedListBlockParser extends WikiBlockParserBase {
18- private static final String START_TAG = "<ul>\n";
18+ private static final String START_TAG = "<div><ul>\n";
1919
20- private static final String END_TAG = "</ul>\n";
20+ private static final String END_TAG = "</ul></div>\n";
2121
2222 /** WIKI記法の正規表現文字列 行頭パターン */
2323 private static final String NOTATION_REGEX_LINEHEAD = "^[ \t]*"
--- a/src/com/wiki/standalone/moxkiriya/resources/defaultstylesheet.css
+++ b/src/com/wiki/standalone/moxkiriya/resources/defaultstylesheet.css
@@ -3,21 +3,21 @@ body {
33 }
44
55 h1 {
6- padding: 0.25em;/*文字周りの余白*/
7- color: #494949;/*文字色*/
8- border-bottom: solid 3px #d7d7d7;/*下線*/
6+ padding: 0.25em;
7+ color: #494949;
8+ border-bottom: solid 3px #d7d7d7;
99 }
1010
1111 h2 {
12- padding: 0.25em;/*文字周りの余白*/
13- color: #494949;/*文字色*/
14- border-bottom: solid 3px #d7d7d7;/*下線*/
12+ padding: 0.25em;
13+ color: #494949;
14+ border-bottom: solid 3px #d7d7d7;
1515 }
1616
1717 h3 {
18- padding: 0.25em;/*文字周りの余白*/
19- color: #494949;/*文字色*/
20- border-bottom: solid 1px #d7d7d7;/*下線*/
18+ padding: 0.25em;
19+ color: #494949;
20+ border-bottom: solid 1px #d7d7d7;
2121 }
2222
2323 pre {
@@ -75,3 +75,30 @@ a.noexist {
7575 color: #ff8c00;
7676 }
7777
78+blockquote.quotation {
79+ margin: 0.2em 0.5em;
80+ border-style: solid;
81+ border-width: 0 0 0 2px;
82+ padding-left: 0.5em;
83+ border-color: red;
84+}
85+
86+.quotation blockquote.quotation {
87+ border-color: blue;
88+}
89+
90+.quotation .quotation blockquote.quotation {
91+ border-color: green;
92+}
93+
94+.quotation .quotation .quotation blockquote.quotation {
95+ border-color: red;
96+}
97+
98+.quotation .quotation .quotation .quotation blockquote.quotation {
99+ border-color: blue;
100+}
101+
102+.quotation .quotation .quotation .quotation .quotation blockquote.quotation {
103+ border-color: green;
104+}
\ No newline at end of file