comparison src/luan/modules/parsers/BBCode.java @ 777:1460d297e960

add bbcode to blog example
author Franklin Schmidt <fschmidt@gmail.com>
date Fri, 26 Aug 2016 15:42:15 -0600
parents 1a68fc55a80c
children 88b5b81cad4a
comparison
equal deleted inserted replaced
776:815c119dac7a 777:1460d297e960
24 private final LuanFunction quoter; 24 private final LuanFunction quoter;
25 private final boolean toHtml; 25 private final boolean toHtml;
26 26
27 private BBCode(LuanState luan,String text,LuanFunction quoter,boolean toHtml) throws LuanException { 27 private BBCode(LuanState luan,String text,LuanFunction quoter,boolean toHtml) throws LuanException {
28 Utils.checkNotNull(text,1); 28 Utils.checkNotNull(text,1);
29 Utils.checkNotNull(quoter,2); 29 // Utils.checkNotNull(quoter,2);
30 this.luan = luan; 30 this.luan = luan;
31 this.parser = new Parser(text); 31 this.parser = new Parser(text);
32 this.quoter = quoter; 32 this.quoter = quoter;
33 this.toHtml = toHtml; 33 this.toHtml = toHtml;
34 } 34 }
262 String rtn = toHtml ? "<iframe width='420' height='315' src='https://www.youtube.com/embed/"+id+"' frameborder='0' allowfullscreen></iframe>" : ""; 262 String rtn = toHtml ? "<iframe width='420' height='315' src='https://www.youtube.com/embed/"+id+"' frameborder='0' allowfullscreen></iframe>" : "";
263 return parser.success(rtn); 263 return parser.success(rtn);
264 } 264 }
265 265
266 private String quote(Object... args) throws LuanException { 266 private String quote(Object... args) throws LuanException {
267 if( quoter==null )
268 throw new LuanException("BBCode quoter function not defined");
267 Object obj = quoter.call(luan,args); 269 Object obj = quoter.call(luan,args);
268 if( !(obj instanceof String) ) 270 if( !(obj instanceof String) )
269 throw new LuanException("BBCode quoter function returned "+Luan.type(obj)+" but string required"); 271 throw new LuanException("BBCode quoter function returned "+Luan.type(obj)+" but string required");
270 return (String)obj; 272 return (String)obj;
271 } 273 }