annotate src/goodjava/bbcode/BBCode.java @ 1714:31a82b0d0a87

bbcode and html work
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 18 Jul 2022 23:49:47 -0600
parents 36c28be6d432
children 6c9aea554691
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1702
8ad468cc88d4 add goodjava/bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents: 1563
diff changeset
1 package goodjava.bbcode;
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
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
3a61451f8130 add bbcode video
Franklin Schmidt <fschmidt@gmail.com>
parents: 1702
diff changeset
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
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
10
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
11 public final class BBCode {
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
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
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
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
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
42 }
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
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
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
49
1702
8ad468cc88d4 add goodjava/bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents: 1563
diff changeset
50 private final Parser parser;
8ad468cc88d4 add goodjava/bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents: 1563
diff changeset
51
1705
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
52 private BBCode(String text) {
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
53 this.parser = new Parser(text);
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
54 }
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
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
728d8e75f476 html encode bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents: 1111
diff changeset
58 StringBuilder text = new StringBuilder();
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
59 while( !parser.endOfInput() ) {
1711
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
60 Element block = parseBlock(false);
1247
728d8e75f476 html encode bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents: 1111
diff changeset
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
728d8e75f476 html encode bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents: 1111
diff changeset
64 } else {
728d8e75f476 html encode bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents: 1111
diff changeset
65 text.append( parser.currentChar() );
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
66 parser.anyChar();
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
67 }
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
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
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
71 }
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
72
1711
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
73 private Object parseUntil(String end) {
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
74 return parseUntil(end,false);
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
75 }
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
76
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
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
728d8e75f476 html encode bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents: 1111
diff changeset
79 StringBuilder text = new StringBuilder();
1711
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
80 while( !parser.matchIgnoreCase(end) ) {
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
81 if( parser.endOfInput() )
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
82 return null;
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
83 Element block = parseBlock(inList);
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
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
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
87 } else {
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
88 text.append( parser.currentChar() );
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
89 parser.anyChar();
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
90 }
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
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
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
94 }
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
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
728d8e75f476 html encode bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents: 1111
diff changeset
101 }
728d8e75f476 html encode bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents: 1111
diff changeset
102
1711
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
103 private Element parseBlock(boolean inList) {
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
104 if( parser.currentChar() != '[' )
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
105 return null;
1705
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
106 Element s;
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
107 s = parseB(); if(s!=null) return s;
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
108 s = parseI(); if(s!=null) return s;
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
109 s = parseU(); if(s!=null) return s;
1711
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
110 s = parseS(); if(s!=null) return s;
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
111 s = parseSup(); if(s!=null) return s;
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
112 s = parseBrackets(); if(s!=null) return s;
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
113 s = parseUrl(); if(s!=null) return s;
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
114 s = parseCode(); if(s!=null) return s;
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
115 s = parseImg(); if(s!=null) return s;
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
116 s = parseColor(); if(s!=null) return s;
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
117 s = parseSize(); if(s!=null) return s;
1703
3a61451f8130 add bbcode video
Franklin Schmidt <fschmidt@gmail.com>
parents: 1702
diff changeset
118 s = parseVideo(); if(s!=null) return s;
1711
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
119 s = parseQuote(); if(s!=null) return s;
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
120 s = parseUl(); if(s!=null) return s;
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
121 s = parseOl(); if(s!=null) return s;
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
122 if( inList ) {
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
123 s = parseLi(); if(s!=null) return s;
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
124 }
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
125 return null;
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
126 }
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
127
1705
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
128 private Element parseB() {
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
129 parser.begin();
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
130 if( !parser.matchIgnoreCase("[b]") )
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
131 return parser.failure(null);
1711
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
132 Object content = parseUntil("[/b]");
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
133 if( content==null )
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
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
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
136 return parser.success(rtn);
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
137 }
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
138
1705
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
139 private Element parseI() {
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
140 parser.begin();
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
141 if( !parser.matchIgnoreCase("[i]") )
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
142 return parser.failure(null);
1711
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
143 Object content = parseUntil("[/i]");
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
144 if( content==null )
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
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
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
147 return parser.success(rtn);
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
148 }
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
149
1705
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
150 private Element parseU() {
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
151 parser.begin();
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
152 if( !parser.matchIgnoreCase("[u]") )
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
153 return parser.failure(null);
1711
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
154 Object content = parseUntil("[/u]");
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
155 if( content==null )
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
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
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
158 return parser.success(rtn);
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
159 }
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
160
1711
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
161 private Element parseS() {
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
162 parser.begin();
1711
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
163 if( !parser.matchIgnoreCase("[s]") )
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
164 return parser.failure(null);
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
165 Object content = parseUntil("[/s]");
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
166 if( content==null )
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
167 return parser.failure(null);
1711
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
168 Element rtn = new Element("s",content);
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
169 return parser.success(rtn);
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
170 }
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
171
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
172 private Element parseSup() {
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
173 parser.begin();
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
174 if( !parser.matchIgnoreCase("[sup]") )
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
175 return parser.failure(null);
1711
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
176 Object content = parseUntil("[/sup]");
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
177 if( content==null )
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
178 return parser.failure(null);
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
179 Element rtn = new Element("sup",content);
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
180 return parser.success(rtn);
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
181 }
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
182
1711
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
183 private Element parseBrackets() {
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
184 parser.begin();
1711
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
185 if( !parser.matchIgnoreCase("[brackets]") )
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
186 return parser.failure(null);
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
187 Object content = parseUntil("[/brackets]");
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
188 if( content==null )
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
189 return parser.failure(null);
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
190 Element rtn = new Element("brackets",content);
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
191 return parser.success(rtn);
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
192 }
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
193
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
194 private Element parseUrl() {
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
195 parser.begin();
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
196 if( !parser.matchIgnoreCase("[url") )
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
197 return parser.failure(null);
1711
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
198 String url;
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
199 Object content;
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
200 if( parser.match(']') ) {
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
201 url = parseRealUrl();
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
202 content = null;
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
203 if( !parser.matchIgnoreCase("[/url]") )
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
204 return parser.failure(null);
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
205 } else if( parser.match('=') ) {
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
206 url = parseRealUrl();
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
207 if( !parser.match(']') )
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
208 return parser.failure(null);
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
209 content = parseUntil("[/url]");
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
210 if( content==null )
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
211 return parser.failure(null);
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
212 } else
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
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
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
215 return parser.success(rtn);
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
216 }
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
217
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
218 private String parseRealUrl() {
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
219 parser.begin();
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
220 while( parser.match(' ') );
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
221 int start = parser.currentIndex();
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
222 if( !parser.matchIgnoreCase("http") )
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
223 return parser.failure(null);
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
224 parser.matchIgnoreCase("s");
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
225 if( !parser.matchIgnoreCase("://") )
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
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
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
228 String url = parser.textFrom(start);
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
229 while( parser.match(' ') );
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
230 return parser.success(url);
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
231 }
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
232
1705
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
233 private Element parseCode() {
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
234 parser.begin();
1711
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
235 String param;
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
236 String end;
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
237 if( !parser.matchIgnoreCase("[code") )
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
238 return parser.failure(null);
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
239 if( parser.match(']') ) {
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
240 param = null;
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
241 end = "[/code]";
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
242 } else if( parser.match('=') ) {
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
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
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
245 param = parser.textFrom(start);
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
246 if( !parser.match(']') )
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
247 return parser.failure(null);
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
248 end = "[/code=" + param + "]";
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
249 } else
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
250 return parser.failure(null);
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
251 int start = parser.currentIndex();
1711
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
252 while( !parser.testIgnoreCase(end) ) {
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
253 if( !parser.anyChar() )
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
254 return parser.failure(null);
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
255 }
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
256 String content = parser.textFrom(start);
1711
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
257 if( !parser.matchIgnoreCase(end) ) throw new RuntimeException();
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
258 Element rtn = new Element("code",param,content);
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
259 return parser.success(rtn);
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
260 }
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
261
1705
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
262 private Element parseImg() {
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
263 parser.begin();
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
264 if( !parser.matchIgnoreCase("[img]") )
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
265 return parser.failure(null);
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
266 String url = parseRealUrl();
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
267 if( !parser.matchIgnoreCase("[/img]") )
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
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
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
270 return parser.success(rtn);
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
271 }
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
272
1705
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
273 private Element parseColor() {
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
274 parser.begin();
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
275 if( !parser.matchIgnoreCase("[color=") )
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
276 return parser.failure(null);
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
277 int start = parser.currentIndex();
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
278 while( parser.inCharRange('0','9')
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
279 || parser.inCharRange('a','z')
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
280 || parser.inCharRange('A','Z')
1714
31a82b0d0a87 bbcode and html work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1712
diff changeset
281 || parser.anyOf("#(, )")
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
282 );
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
283 String color = parser.textFrom(start);
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
284 if( !parser.match(']') )
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
285 return parser.failure(null);
1711
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
286 Object content = parseUntil("[/color]");
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
287 if( content==null )
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
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
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
290 return parser.success(rtn);
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
291 }
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
292
1705
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
293 private Element parseSize() {
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
294 parser.begin();
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
295 if( !parser.matchIgnoreCase("[size=") )
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
296 return parser.failure(null);
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
297 int start = parser.currentIndex();
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
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
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
301 String size = parser.textFrom(start);
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
302 if( !parser.match(']') )
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
303 return parser.failure(null);
1711
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
304 Object content = parseUntil("[/size]");
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
305 if( content==null )
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
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
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
308 return parser.success(rtn);
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
309 }
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
310
1705
a6e27c8e7ef4 bbcode now returns data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1703
diff changeset
311 private Element parseVideo() {
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
312 parser.begin();
1703
3a61451f8130 add bbcode video
Franklin Schmidt <fschmidt@gmail.com>
parents: 1702
diff changeset
313 if( !parser.matchIgnoreCase("[video]") )
3a61451f8130 add bbcode video
Franklin Schmidt <fschmidt@gmail.com>
parents: 1702
diff changeset
314 return parser.failure(null);
3a61451f8130 add bbcode video
Franklin Schmidt <fschmidt@gmail.com>
parents: 1702
diff changeset
315 String url = parseRealUrl();
3a61451f8130 add bbcode video
Franklin Schmidt <fschmidt@gmail.com>
parents: 1702
diff changeset
316 if( !parser.matchIgnoreCase("[/video]") )
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
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
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
320 }
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
321
1703
3a61451f8130 add bbcode video
Franklin Schmidt <fschmidt@gmail.com>
parents: 1702
diff changeset
322
1711
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
323 private Element parseQuote() {
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
324 parser.begin();
1711
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
325 if( !parser.matchIgnoreCase("[quote") )
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
326 return parser.failure(null);
1711
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
327 String name;
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
328 if( parser.match(']') ) {
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
329 name = null;
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
330 } else if( parser.match('=') ) {
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
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
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
334 if( !parser.match(']') )
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
335 return parser.failure(null);
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
336 } else
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
337 return parser.failure(null);
1711
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
338 Object content = parseUntil("[/quote]");
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
339 if( content==null )
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
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
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
343 }
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
344
1711
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
345
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
346 private Element parseUl() {
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
347 parser.begin();
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
348 if( !parser.matchIgnoreCase("[ul]") )
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
349 return parser.failure(null);
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
350 Object content = parseUntil("[/ul]",true);
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
351 if( content==null )
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
352 return parser.failure(null);
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
353 Element rtn = new Element("ul",content);
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
354 return parser.success(rtn);
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
355 }
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
356
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
357 private Element parseOl() {
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
358 parser.begin();
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
359 if( !parser.matchIgnoreCase("[ol]") )
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
360 return parser.failure(null);
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
361 Object content = parseUntil("[/ol]",true);
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
362 if( content==null )
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
363 return parser.failure(null);
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
364 Element rtn = new Element("ol",content);
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
365 return parser.success(rtn);
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
366 }
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
367
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
368 private Element parseLi() {
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
369 parser.begin();
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
370 if( !parser.matchIgnoreCase("[li]") )
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
371 return parser.failure(null);
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
372 Object content = parseUntil("[/li]");
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
373 if( content==null )
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
374 return parser.failure(null);
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
375 Element rtn = new Element("li",content);
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
376 return parser.success(rtn);
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
377 }
05d14db623b6 add bbcodes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1705
diff changeset
378
585
bb3818249dfb add Parsers
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
379 }