Moxkiriyaプロジェクト事前開発用の作業部屋
Revision | 7c1d308b25ab0264a315f8875647d789e25a3020 (tree) |
---|---|
Zeit | 2018-08-25 08:53:24 |
Autor | Harold_Andoh <andolloyd@gmai...> |
Commiter | Harold_Andoh |
[Moxkiriya7]
@@ -62,6 +62,12 @@ public class WikiBlockParserCreator { | ||
62 | 62 | return new WikiOrderedListBlockParser(file); |
63 | 63 | } |
64 | 64 | } ); |
65 | + put(WikiBlockquoteBlockParser.NOTATION_REGEX, new Creator() { | |
66 | + @Override | |
67 | + public WikiBlockParser create(File file) { | |
68 | + return new WikiBlockquoteBlockParser(file); | |
69 | + } | |
70 | + } ); | |
65 | 71 | put(WikiPreBlockParser.NOTATION_REGEX, new Creator() { |
66 | 72 | @Override |
67 | 73 | public WikiBlockParser create(File file) { |
@@ -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 | + }} |
@@ -88,12 +88,7 @@ public class WikiBodyBlockParser { | ||
88 | 88 | tagBuf.append(lineCharArray[count]); |
89 | 89 | } |
90 | 90 | else { |
91 | - if(lineCharArray[count] == '>') { | |
92 | - buf.append(">"); | |
93 | - } | |
94 | - else { | |
95 | - buf.append(lineCharArray[count]); | |
96 | - } | |
91 | + buf.append(lineCharArray[count]); | |
97 | 92 | } |
98 | 93 | } |
99 | 94 | else if(status == PreprocessStatus.OPEN) { |
@@ -111,12 +106,11 @@ public class WikiBodyBlockParser { | ||
111 | 106 | /* |
112 | 107 | * acceptリストにないタグパターンの場合 |
113 | 108 | */ |
114 | - buf.append(tag.replaceAll("<", "lt;") | |
109 | + buf.append(tag.replaceAll("<", "<") | |
115 | 110 | .replaceAll(">", ">")); |
116 | 111 | tagBuf = null; |
117 | 112 | } |
118 | 113 | status = PreprocessStatus.INIT; |
119 | - | |
120 | 114 | } |
121 | 115 | } |
122 | 116 | else { |
@@ -140,6 +134,7 @@ public class WikiBodyBlockParser { | ||
140 | 134 | */ |
141 | 135 | private String parseCore(BufferedReader reader) throws Exception { |
142 | 136 | StringBuffer buf = new StringBuffer(""); |
137 | + StringBuffer paragraphBuf = null; | |
143 | 138 | String line = null; |
144 | 139 | ParseStatus status = ParseStatus.INIT; |
145 | 140 |
@@ -150,47 +145,45 @@ public class WikiBodyBlockParser { | ||
150 | 145 | /* |
151 | 146 | * XSS殺し |
152 | 147 | */ |
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(); | |
162 | 154 | } |
163 | - } | |
164 | - | |
165 | - while(line.isEmpty() != true) { | |
155 | + | |
166 | 156 | 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); | |
175 | 159 | } |
176 | - | |
177 | - line = parser.parse(line, buf); | |
160 | + | |
161 | + processingline = parser.parse(processingline, paragraphBuf); | |
178 | 162 | |
179 | 163 | if(parser.isBlockEnd() == true) { |
180 | - line = parser.endElementProcess(line, buf); | |
164 | + processingline = parser.endElementProcess(processingline, paragraphBuf); | |
181 | 165 | 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 | + } | |
183 | 175 | } |
184 | - } | |
176 | + } while(processingline.isEmpty() != true); | |
185 | 177 | } |
186 | 178 | |
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); | |
193 | 182 | } |
183 | + buf.append("<p>\n"); | |
184 | + buf.append(paragraphBuf + "\n"); | |
185 | + buf.append("</p>\n"); | |
186 | + status = ParseStatus.CLOSE; | |
194 | 187 | } |
195 | 188 | |
196 | 189 | return buf.toString(); |
@@ -17,7 +17,9 @@ public class WikiDefaultBlockParser extends WikiBlockParserBase { | ||
17 | 17 | |
18 | 18 | @Override |
19 | 19 | public String parse(String line, StringBuffer buf) throws Exception { |
20 | + buf.append("<div>"); | |
20 | 21 | buf.append(inlineParse(line)); |
22 | + buf.append("</div>\n"); | |
21 | 23 | return ""; |
22 | 24 | } |
23 | 25 |
@@ -3,9 +3,9 @@ package com.wiki.standalone.moxkiriya.parser.blockparser; | ||
3 | 3 | import java.io.File; |
4 | 4 | |
5 | 5 | public class WikiH2BlockParser extends WikiBlockParserBase { |
6 | - private static final String START_TAG = "<h2>"; | |
6 | + private static final String START_TAG = "<div><h2>"; | |
7 | 7 | |
8 | - private static final String END_TAG = "</h2>\n"; | |
8 | + private static final String END_TAG = "</h2></div>\n"; | |
9 | 9 | |
10 | 10 | /** WIKI記法の正規表現文字列 行頭パターン */ |
11 | 11 | private static final String NOTATION_REGEX_LINEHEAD = "^=="; |
@@ -34,7 +34,7 @@ public class WikiH2BlockParser extends WikiBlockParserBase { | ||
34 | 34 | |
35 | 35 | @Override |
36 | 36 | public String endElementProcess(String line, StringBuffer buf) { |
37 | - buf.append(END_TAG + "\n"); | |
37 | + buf.append(END_TAG); | |
38 | 38 | return ""; |
39 | 39 | } |
40 | 40 |
@@ -3,9 +3,9 @@ package com.wiki.standalone.moxkiriya.parser.blockparser; | ||
3 | 3 | import java.io.File; |
4 | 4 | |
5 | 5 | public class WikiH3BlockParser extends WikiH2BlockParser { |
6 | - private static final String START_TAG = "<h3>"; | |
6 | + private static final String START_TAG = "<div><h3>"; | |
7 | 7 | |
8 | - private static final String END_TAG = "</h3>\n"; | |
8 | + private static final String END_TAG = "</h3></div>\n"; | |
9 | 9 | |
10 | 10 | /** WIKI記法の正規表現文字列 行頭パターン */ |
11 | 11 | private static final String NOTATION_REGEX_LINEHEAD = "^==="; |
@@ -34,7 +34,7 @@ public class WikiH3BlockParser extends WikiH2BlockParser { | ||
34 | 34 | |
35 | 35 | @Override |
36 | 36 | public String endElementProcess(String line, StringBuffer buf) { |
37 | - buf.append(END_TAG + "\n"); | |
37 | + buf.append(END_TAG); | |
38 | 38 | return ""; |
39 | 39 | } |
40 | 40 |
@@ -5,7 +5,7 @@ import java.io.File; | ||
5 | 5 | public class WikiHrBlockParser extends WikiBlockParserBase { |
6 | 6 | private static final String START_TAG = "<hr>"; |
7 | 7 | |
8 | - private static final String END_TAG = "\n"; | |
8 | + private static final String END_TAG = ""; | |
9 | 9 | |
10 | 10 | /** WIKI記法の正規表現文字列 行頭パターン */ |
11 | 11 | private static final String NOTATION_REGEX_LINEHEAD = "^----"; |
@@ -32,7 +32,7 @@ public class WikiHrBlockParser extends WikiBlockParserBase { | ||
32 | 32 | |
33 | 33 | @Override |
34 | 34 | public String endElementProcess(String line, StringBuffer buf) { |
35 | - buf.append(END_TAG + "\n"); | |
35 | + buf.append(END_TAG); | |
36 | 36 | return ""; |
37 | 37 | } |
38 | 38 |
@@ -14,9 +14,9 @@ import java.io.File; | ||
14 | 14 | * |
15 | 15 | */ |
16 | 16 | public class WikiOrderedListBlockParser extends WikiBlockParserBase { |
17 | - private static final String START_TAG = "<ol>\n"; | |
17 | + private static final String START_TAG = "<div><ol>\n"; | |
18 | 18 | |
19 | - private static final String END_TAG = "</ol>\n"; | |
19 | + private static final String END_TAG = "</ol></div>\n"; | |
20 | 20 | |
21 | 21 | /** WIKI記法の正規表現文字列 行頭パターン */ |
22 | 22 | private static final String NOTATION_REGEX_LINEHEAD = "^[ \t]*" |
@@ -13,10 +13,10 @@ import java.util.regex.Pattern; | ||
13 | 13 | |
14 | 14 | public class WikiTableBlockParser extends WikiBlockParserBase { |
15 | 15 | /** startタグ */ |
16 | - private static final String START_TAG = "<table"; | |
16 | + private static final String START_TAG = "<div><table"; | |
17 | 17 | |
18 | 18 | /** endタグ*/ |
19 | - private static final String END_TAG = "</table>\n"; | |
19 | + private static final String END_TAG = "</table></div>\n"; | |
20 | 20 | |
21 | 21 | /** WIKI記法の正規表現文字列 行頭パターン */ |
22 | 22 | private static final String NOTATION_REGEX_LINEHEAD = "^[ \t]*" |
@@ -172,7 +172,7 @@ public class WikiTableRowBlockParser extends WikiBlockParserBase { | ||
172 | 172 | status_ = Status.OPEN; |
173 | 173 | } |
174 | 174 | flushRowBuf(buf); |
175 | - buf.append(tagpair_.endTag_ + "\n"); | |
175 | + buf.append(tagpair_.endTag_); | |
176 | 176 | return remain_; |
177 | 177 | } |
178 | 178 |
@@ -15,9 +15,9 @@ import java.util.regex.Pattern; | ||
15 | 15 | * |
16 | 16 | */ |
17 | 17 | public class WikiUnorderedListBlockParser extends WikiBlockParserBase { |
18 | - private static final String START_TAG = "<ul>\n"; | |
18 | + private static final String START_TAG = "<div><ul>\n"; | |
19 | 19 | |
20 | - private static final String END_TAG = "</ul>\n"; | |
20 | + private static final String END_TAG = "</ul></div>\n"; | |
21 | 21 | |
22 | 22 | /** WIKI記法の正規表現文字列 行頭パターン */ |
23 | 23 | private static final String NOTATION_REGEX_LINEHEAD = "^[ \t]*" |
@@ -3,21 +3,21 @@ body { | ||
3 | 3 | } |
4 | 4 | |
5 | 5 | 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; | |
9 | 9 | } |
10 | 10 | |
11 | 11 | 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; | |
15 | 15 | } |
16 | 16 | |
17 | 17 | 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; | |
21 | 21 | } |
22 | 22 | |
23 | 23 | pre { |
@@ -75,3 +75,30 @@ a.noexist { | ||
75 | 75 | color: #ff8c00; |
76 | 76 | } |
77 | 77 | |
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 |