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