Mercurial Hosting > luan
changeset 1247:728d8e75f476
html encode bbcode
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Tue, 17 Jul 2018 22:17:01 -0600 |
parents | 299996e03876 |
children | 475905984870 |
files | src/luan/modules/parsers/BBCode.java |
diffstat | 1 files changed, 19 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/src/luan/modules/parsers/BBCode.java Tue Jul 17 15:43:11 2018 -0600 +++ b/src/luan/modules/parsers/BBCode.java Tue Jul 17 22:17:01 2018 -0600 @@ -7,6 +7,7 @@ import luan.LuanFunction; import luan.LuanException; import luan.modules.Utils; +import luan.modules.HtmlLuan; import luan.lib.parser.Parser; @@ -36,34 +37,48 @@ private String parse() throws LuanException { StringBuilder sb = new StringBuilder(); + StringBuilder text = new StringBuilder(); while( !parser.endOfInput() ) { String block = parseBlock(); - if( block != null ) + if( block != null ) { + sb.append( textToString(text) ); sb.append(block); - else { - sb.append( parser.currentChar() ); + } else { + text.append( parser.currentChar() ); parser.anyChar(); } } + sb.append( textToString(text) ); return sb.toString(); } private String parseWellFormed() throws LuanException { StringBuilder sb = new StringBuilder(); + StringBuilder text = new StringBuilder(); while( !parser.endOfInput() ) { String block = parseBlock(); if( block != null ) { + sb.append( textToString(text) ); sb.append(block); continue; } if( couldBeTag() ) break; - sb.append( parser.currentChar() ); + text.append( parser.currentChar() ); parser.anyChar(); } + sb.append( textToString(text) ); return sb.toString(); } + private String textToString(StringBuilder text) throws LuanException { + String s = text.toString(); + text.setLength(0); + if( toHtml ) + s = HtmlLuan.encode(s); + return s; + } + private boolean couldBeTag() { if( parser.currentChar() != '[' ) return false;