Mercurial Hosting > luan
annotate src/goodjava/bbcode/BBCode.java @ 1716:b82767112d8e
add String.regex
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sun, 24 Jul 2022 23:43:03 -0600 |
parents | 31a82b0d0a87 |
children | 6c9aea554691 |
rev | line source |
---|---|
1702 | 1 package goodjava.bbcode; |
585 | 2 |
637
6ea90dc10375
bbcode parser now takes a quoter function
Franklin Schmidt <fschmidt@gmail.com>
parents:
588
diff
changeset
|
3 import java.util.List; |
6ea90dc10375
bbcode parser now takes a quoter function
Franklin Schmidt <fschmidt@gmail.com>
parents:
588
diff
changeset
|
4 import java.util.ArrayList; |
1705
a6e27c8e7ef4
bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents:
1703
diff
changeset
|
5 import java.util.Map; |
a6e27c8e7ef4
bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents:
1703
diff
changeset
|
6 import java.util.LinkedHashMap; |
1703 | 7 import java.util.regex.Pattern; |
1402
27efb1fcbcb5
move luan.lib to goodjava
Franklin Schmidt <fschmidt@gmail.com>
parents:
1335
diff
changeset
|
8 import goodjava.parser.Parser; |
637
6ea90dc10375
bbcode parser now takes a quoter function
Franklin Schmidt <fschmidt@gmail.com>
parents:
588
diff
changeset
|
9 |
585 | 10 |
11 public final class BBCode { | |
12 | |
1712
36c28be6d432
improve html and bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents:
1711
diff
changeset
|
13 private static final Pattern tagPtn = Pattern.compile( |
36c28be6d432
improve html and bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents:
1711
diff
changeset
|
14 "\\[(/?[a-zA-Z]+(=[^ \\n\\t\\[\\]]*)?)\\]" |
36c28be6d432
improve html and bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents:
1711
diff
changeset
|
15 ); |
36c28be6d432
improve html and bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents:
1711
diff
changeset
|
16 |
36c28be6d432
improve html and bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents:
1711
diff
changeset
|
17 public static String encode(String s) { |
36c28be6d432
improve html and bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents:
1711
diff
changeset
|
18 return tagPtn.matcher(s).replaceAll("[brackets]$1[/brackets]"); |
36c28be6d432
improve html and bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents:
1711
diff
changeset
|
19 } |
36c28be6d432
improve html and bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents:
1711
diff
changeset
|
20 |
36c28be6d432
improve html and bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents:
1711
diff
changeset
|
21 |
1705
a6e27c8e7ef4
bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents:
1703
diff
changeset
|
22 public final class Element { |
a6e27c8e7ef4
bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents:
1703
diff
changeset
|
23 public final String name; |
a6e27c8e7ef4
bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents:
1703
diff
changeset
|
24 public final String param; |
a6e27c8e7ef4
bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents:
1703
diff
changeset
|
25 public final Object contents; // String, Element, or List |
a6e27c8e7ef4
bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents:
1703
diff
changeset
|
26 public final Map<String,String> extra; |
a6e27c8e7ef4
bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents:
1703
diff
changeset
|
27 |
a6e27c8e7ef4
bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents:
1703
diff
changeset
|
28 private Element(String name,Object contents) { |
a6e27c8e7ef4
bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents:
1703
diff
changeset
|
29 this(name,null,contents); |
a6e27c8e7ef4
bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents:
1703
diff
changeset
|
30 } |
585 | 31 |
1705
a6e27c8e7ef4
bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents:
1703
diff
changeset
|
32 private Element(String name,String param,Object contents) { |
a6e27c8e7ef4
bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents:
1703
diff
changeset
|
33 this(name,param,contents,null); |
a6e27c8e7ef4
bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents:
1703
diff
changeset
|
34 } |
a6e27c8e7ef4
bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents:
1703
diff
changeset
|
35 |
a6e27c8e7ef4
bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents:
1703
diff
changeset
|
36 private Element(String name,String param,Object contents,Map<String,String> extra) { |
a6e27c8e7ef4
bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents:
1703
diff
changeset
|
37 this.name = name.toLowerCase(); |
a6e27c8e7ef4
bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents:
1703
diff
changeset
|
38 this.param = param; |
a6e27c8e7ef4
bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents:
1703
diff
changeset
|
39 this.contents = contents; |
a6e27c8e7ef4
bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents:
1703
diff
changeset
|
40 this.extra = extra; |
a6e27c8e7ef4
bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents:
1703
diff
changeset
|
41 } |
585 | 42 } |
43 | |
1705
a6e27c8e7ef4
bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents:
1703
diff
changeset
|
44 public static Object parse(String text) { |
a6e27c8e7ef4
bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents:
1703
diff
changeset
|
45 if( text.indexOf('[') == -1 ) |
a6e27c8e7ef4
bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents:
1703
diff
changeset
|
46 return text; |
a6e27c8e7ef4
bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents:
1703
diff
changeset
|
47 return new BBCode(text).parse(); |
a6e27c8e7ef4
bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents:
1703
diff
changeset
|
48 } |
585 | 49 |
1702 | 50 private final Parser parser; |
51 | |
1705
a6e27c8e7ef4
bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents:
1703
diff
changeset
|
52 private BBCode(String text) { |
585 | 53 this.parser = new Parser(text); |
54 } | |
55 | |
1705
a6e27c8e7ef4
bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents:
1703
diff
changeset
|
56 private Object parse() { |
a6e27c8e7ef4
bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents:
1703
diff
changeset
|
57 List list = new ArrayList(); |
1247 | 58 StringBuilder text = new StringBuilder(); |
585 | 59 while( !parser.endOfInput() ) { |
1711 | 60 Element block = parseBlock(false); |
1247 | 61 if( block != null ) { |
1705
a6e27c8e7ef4
bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents:
1703
diff
changeset
|
62 add(list,text); |
a6e27c8e7ef4
bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents:
1703
diff
changeset
|
63 list.add( block ); |
1247 | 64 } else { |
65 text.append( parser.currentChar() ); | |
585 | 66 parser.anyChar(); |
67 } | |
68 } | |
1705
a6e27c8e7ef4
bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents:
1703
diff
changeset
|
69 add(list,text); |
a6e27c8e7ef4
bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents:
1703
diff
changeset
|
70 return list.size()==1 ? list.get(0) : list; |
585 | 71 } |
72 | |
1711 | 73 private Object parseUntil(String end) { |
74 return parseUntil(end,false); | |
75 } | |
76 | |
77 private Object parseUntil(String end,boolean inList) { | |
1705
a6e27c8e7ef4
bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents:
1703
diff
changeset
|
78 List list = new ArrayList(); |
1247 | 79 StringBuilder text = new StringBuilder(); |
1711 | 80 while( !parser.matchIgnoreCase(end) ) { |
81 if( parser.endOfInput() ) | |
82 return null; | |
83 Element block = parseBlock(inList); | |
585 | 84 if( block != null ) { |
1705
a6e27c8e7ef4
bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents:
1703
diff
changeset
|
85 add(list,text); |
a6e27c8e7ef4
bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents:
1703
diff
changeset
|
86 list.add( block ); |
1711 | 87 } else { |
88 text.append( parser.currentChar() ); | |
89 parser.anyChar(); | |
585 | 90 } |
91 } | |
1705
a6e27c8e7ef4
bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents:
1703
diff
changeset
|
92 add(list,text); |
a6e27c8e7ef4
bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents:
1703
diff
changeset
|
93 return list.size()==1 ? list.get(0) : list; |
585 | 94 } |
95 | |
1705
a6e27c8e7ef4
bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents:
1703
diff
changeset
|
96 private void add(List list,StringBuilder text) { |
a6e27c8e7ef4
bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents:
1703
diff
changeset
|
97 if( text.length() > 0 ) { |
a6e27c8e7ef4
bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents:
1703
diff
changeset
|
98 list.add( text.toString() ); |
a6e27c8e7ef4
bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents:
1703
diff
changeset
|
99 text.setLength(0); |
a6e27c8e7ef4
bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents:
1703
diff
changeset
|
100 } |
1247 | 101 } |
102 | |
1711 | 103 private Element parseBlock(boolean inList) { |
585 | 104 if( parser.currentChar() != '[' ) |
105 return null; | |
1705
a6e27c8e7ef4
bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents:
1703
diff
changeset
|
106 Element s; |
585 | 107 s = parseB(); if(s!=null) return s; |
108 s = parseI(); if(s!=null) return s; | |
109 s = parseU(); if(s!=null) return s; | |
1711 | 110 s = parseS(); if(s!=null) return s; |
111 s = parseSup(); if(s!=null) return s; | |
112 s = parseBrackets(); if(s!=null) return s; | |
113 s = parseUrl(); if(s!=null) return s; | |
585 | 114 s = parseCode(); if(s!=null) return s; |
115 s = parseImg(); if(s!=null) return s; | |
116 s = parseColor(); if(s!=null) return s; | |
117 s = parseSize(); if(s!=null) return s; | |
1703 | 118 s = parseVideo(); if(s!=null) return s; |
1711 | 119 s = parseQuote(); if(s!=null) return s; |
120 s = parseUl(); if(s!=null) return s; | |
121 s = parseOl(); if(s!=null) return s; | |
122 if( inList ) { | |
123 s = parseLi(); if(s!=null) return s; | |
124 } | |
585 | 125 return null; |
126 } | |
127 | |
1705
a6e27c8e7ef4
bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents:
1703
diff
changeset
|
128 private Element parseB() { |
585 | 129 parser.begin(); |
130 if( !parser.matchIgnoreCase("[b]") ) | |
131 return parser.failure(null); | |
1711 | 132 Object content = parseUntil("[/b]"); |
133 if( content==null ) | |
585 | 134 return parser.failure(null); |
1705
a6e27c8e7ef4
bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents:
1703
diff
changeset
|
135 Element rtn = new Element("b",content); |
585 | 136 return parser.success(rtn); |
137 } | |
138 | |
1705
a6e27c8e7ef4
bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents:
1703
diff
changeset
|
139 private Element parseI() { |
585 | 140 parser.begin(); |
141 if( !parser.matchIgnoreCase("[i]") ) | |
142 return parser.failure(null); | |
1711 | 143 Object content = parseUntil("[/i]"); |
144 if( content==null ) | |
585 | 145 return parser.failure(null); |
1705
a6e27c8e7ef4
bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents:
1703
diff
changeset
|
146 Element rtn = new Element("i",content); |
585 | 147 return parser.success(rtn); |
148 } | |
149 | |
1705
a6e27c8e7ef4
bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents:
1703
diff
changeset
|
150 private Element parseU() { |
585 | 151 parser.begin(); |
152 if( !parser.matchIgnoreCase("[u]") ) | |
153 return parser.failure(null); | |
1711 | 154 Object content = parseUntil("[/u]"); |
155 if( content==null ) | |
585 | 156 return parser.failure(null); |
1705
a6e27c8e7ef4
bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents:
1703
diff
changeset
|
157 Element rtn = new Element("u",content); |
585 | 158 return parser.success(rtn); |
159 } | |
160 | |
1711 | 161 private Element parseS() { |
585 | 162 parser.begin(); |
1711 | 163 if( !parser.matchIgnoreCase("[s]") ) |
164 return parser.failure(null); | |
165 Object content = parseUntil("[/s]"); | |
166 if( content==null ) | |
585 | 167 return parser.failure(null); |
1711 | 168 Element rtn = new Element("s",content); |
169 return parser.success(rtn); | |
170 } | |
171 | |
172 private Element parseSup() { | |
173 parser.begin(); | |
174 if( !parser.matchIgnoreCase("[sup]") ) | |
585 | 175 return parser.failure(null); |
1711 | 176 Object content = parseUntil("[/sup]"); |
177 if( content==null ) | |
178 return parser.failure(null); | |
179 Element rtn = new Element("sup",content); | |
585 | 180 return parser.success(rtn); |
181 } | |
182 | |
1711 | 183 private Element parseBrackets() { |
585 | 184 parser.begin(); |
1711 | 185 if( !parser.matchIgnoreCase("[brackets]") ) |
186 return parser.failure(null); | |
187 Object content = parseUntil("[/brackets]"); | |
188 if( content==null ) | |
189 return parser.failure(null); | |
190 Element rtn = new Element("brackets",content); | |
191 return parser.success(rtn); | |
192 } | |
193 | |
194 private Element parseUrl() { | |
195 parser.begin(); | |
196 if( !parser.matchIgnoreCase("[url") ) | |
585 | 197 return parser.failure(null); |
1711 | 198 String url; |
199 Object content; | |
200 if( parser.match(']') ) { | |
201 url = parseRealUrl(); | |
202 content = null; | |
203 if( !parser.matchIgnoreCase("[/url]") ) | |
204 return parser.failure(null); | |
205 } else if( parser.match('=') ) { | |
206 url = parseRealUrl(); | |
207 if( !parser.match(']') ) | |
208 return parser.failure(null); | |
209 content = parseUntil("[/url]"); | |
210 if( content==null ) | |
211 return parser.failure(null); | |
212 } else | |
585 | 213 return parser.failure(null); |
1705
a6e27c8e7ef4
bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents:
1703
diff
changeset
|
214 Element rtn = new Element("url",url,content); |
585 | 215 return parser.success(rtn); |
216 } | |
217 | |
218 private String parseRealUrl() { | |
219 parser.begin(); | |
220 while( parser.match(' ') ); | |
221 int start = parser.currentIndex(); | |
222 if( !parser.matchIgnoreCase("http") ) | |
223 return parser.failure(null); | |
224 parser.matchIgnoreCase("s"); | |
225 if( !parser.matchIgnoreCase("://") ) | |
226 return parser.failure(null); | |
1712
36c28be6d432
improve html and bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents:
1711
diff
changeset
|
227 while( parser.noneOf(" \n\t[]") ); |
585 | 228 String url = parser.textFrom(start); |
229 while( parser.match(' ') ); | |
230 return parser.success(url); | |
231 } | |
232 | |
1705
a6e27c8e7ef4
bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents:
1703
diff
changeset
|
233 private Element parseCode() { |
585 | 234 parser.begin(); |
1711 | 235 String param; |
236 String end; | |
237 if( !parser.matchIgnoreCase("[code") ) | |
238 return parser.failure(null); | |
239 if( parser.match(']') ) { | |
240 param = null; | |
241 end = "[/code]"; | |
242 } else if( parser.match('=') ) { | |
243 int start = parser.currentIndex(); | |
1712
36c28be6d432
improve html and bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents:
1711
diff
changeset
|
244 while( parser.noneOf("[]\n") ); |
1711 | 245 param = parser.textFrom(start); |
246 if( !parser.match(']') ) | |
247 return parser.failure(null); | |
248 end = "[/code=" + param + "]"; | |
249 } else | |
585 | 250 return parser.failure(null); |
251 int start = parser.currentIndex(); | |
1711 | 252 while( !parser.testIgnoreCase(end) ) { |
585 | 253 if( !parser.anyChar() ) |
254 return parser.failure(null); | |
255 } | |
256 String content = parser.textFrom(start); | |
1711 | 257 if( !parser.matchIgnoreCase(end) ) throw new RuntimeException(); |
258 Element rtn = new Element("code",param,content); | |
585 | 259 return parser.success(rtn); |
260 } | |
261 | |
1705
a6e27c8e7ef4
bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents:
1703
diff
changeset
|
262 private Element parseImg() { |
585 | 263 parser.begin(); |
264 if( !parser.matchIgnoreCase("[img]") ) | |
265 return parser.failure(null); | |
266 String url = parseRealUrl(); | |
267 if( !parser.matchIgnoreCase("[/img]") ) | |
268 return parser.failure(null); | |
1705
a6e27c8e7ef4
bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents:
1703
diff
changeset
|
269 Element rtn = new Element("img",url); |
585 | 270 return parser.success(rtn); |
271 } | |
272 | |
1705
a6e27c8e7ef4
bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents:
1703
diff
changeset
|
273 private Element parseColor() { |
585 | 274 parser.begin(); |
275 if( !parser.matchIgnoreCase("[color=") ) | |
276 return parser.failure(null); | |
277 int start = parser.currentIndex(); | |
278 while( parser.inCharRange('0','9') | |
279 || parser.inCharRange('a','z') | |
280 || parser.inCharRange('A','Z') | |
1714
31a82b0d0a87
bbcode and html work
Franklin Schmidt <fschmidt@gmail.com>
parents:
1712
diff
changeset
|
281 || parser.anyOf("#(, )") |
585 | 282 ); |
283 String color = parser.textFrom(start); | |
284 if( !parser.match(']') ) | |
285 return parser.failure(null); | |
1711 | 286 Object content = parseUntil("[/color]"); |
287 if( content==null ) | |
585 | 288 return parser.failure(null); |
1705
a6e27c8e7ef4
bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents:
1703
diff
changeset
|
289 Element rtn = new Element("color",color,content); |
585 | 290 return parser.success(rtn); |
291 } | |
292 | |
1705
a6e27c8e7ef4
bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents:
1703
diff
changeset
|
293 private Element parseSize() { |
585 | 294 parser.begin(); |
295 if( !parser.matchIgnoreCase("[size=") ) | |
296 return parser.failure(null); | |
297 int start = parser.currentIndex(); | |
298 while( parser.match('.') || parser.inCharRange('0','9') ); | |
1714
31a82b0d0a87
bbcode and html work
Franklin Schmidt <fschmidt@gmail.com>
parents:
1712
diff
changeset
|
299 if( parser.matchIgnoreCase("pt") || parser.match('%') ) |
31a82b0d0a87
bbcode and html work
Franklin Schmidt <fschmidt@gmail.com>
parents:
1712
diff
changeset
|
300 ; // ok |
585 | 301 String size = parser.textFrom(start); |
302 if( !parser.match(']') ) | |
303 return parser.failure(null); | |
1711 | 304 Object content = parseUntil("[/size]"); |
305 if( content==null ) | |
585 | 306 return parser.failure(null); |
1705
a6e27c8e7ef4
bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents:
1703
diff
changeset
|
307 Element rtn = new Element("size",size,content); |
585 | 308 return parser.success(rtn); |
309 } | |
310 | |
1705
a6e27c8e7ef4
bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents:
1703
diff
changeset
|
311 private Element parseVideo() { |
585 | 312 parser.begin(); |
1703 | 313 if( !parser.matchIgnoreCase("[video]") ) |
314 return parser.failure(null); | |
315 String url = parseRealUrl(); | |
316 if( !parser.matchIgnoreCase("[/video]") ) | |
585 | 317 return parser.failure(null); |
1714
31a82b0d0a87
bbcode and html work
Franklin Schmidt <fschmidt@gmail.com>
parents:
1712
diff
changeset
|
318 Element rtn = new Element("video",null,url); |
1705
a6e27c8e7ef4
bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents:
1703
diff
changeset
|
319 return parser.success(rtn); |
585 | 320 } |
321 | |
1703 | 322 |
1711 | 323 private Element parseQuote() { |
585 | 324 parser.begin(); |
1711 | 325 if( !parser.matchIgnoreCase("[quote") ) |
585 | 326 return parser.failure(null); |
1711 | 327 String name; |
328 if( parser.match(']') ) { | |
329 name = null; | |
330 } else if( parser.match('=') ) { | |
331 int start = parser.currentIndex(); | |
1712
36c28be6d432
improve html and bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents:
1711
diff
changeset
|
332 while( parser.noneOf("[]\n") ); |
36c28be6d432
improve html and bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents:
1711
diff
changeset
|
333 name = parser.textFrom(start); |
1711 | 334 if( !parser.match(']') ) |
335 return parser.failure(null); | |
336 } else | |
585 | 337 return parser.failure(null); |
1711 | 338 Object content = parseUntil("[/quote]"); |
339 if( content==null ) | |
585 | 340 return parser.failure(null); |
1705
a6e27c8e7ef4
bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents:
1703
diff
changeset
|
341 Element rtn = new Element("quote",name,content); |
637
6ea90dc10375
bbcode parser now takes a quoter function
Franklin Schmidt <fschmidt@gmail.com>
parents:
588
diff
changeset
|
342 return parser.success(rtn); |
585 | 343 } |
344 | |
1711 | 345 |
346 private Element parseUl() { | |
347 parser.begin(); | |
348 if( !parser.matchIgnoreCase("[ul]") ) | |
349 return parser.failure(null); | |
350 Object content = parseUntil("[/ul]",true); | |
351 if( content==null ) | |
352 return parser.failure(null); | |
353 Element rtn = new Element("ul",content); | |
354 return parser.success(rtn); | |
355 } | |
356 | |
357 private Element parseOl() { | |
358 parser.begin(); | |
359 if( !parser.matchIgnoreCase("[ol]") ) | |
360 return parser.failure(null); | |
361 Object content = parseUntil("[/ol]",true); | |
362 if( content==null ) | |
363 return parser.failure(null); | |
364 Element rtn = new Element("ol",content); | |
365 return parser.success(rtn); | |
366 } | |
367 | |
368 private Element parseLi() { | |
369 parser.begin(); | |
370 if( !parser.matchIgnoreCase("[li]") ) | |
371 return parser.failure(null); | |
372 Object content = parseUntil("[/li]"); | |
373 if( content==null ) | |
374 return parser.failure(null); | |
375 Element rtn = new Element("li",content); | |
376 return parser.success(rtn); | |
377 } | |
378 | |
585 | 379 } |