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