Mercurial Hosting > luan
diff 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 |
line wrap: on
line diff
--- a/src/goodjava/bbcode/BBCode.java Fri Jul 15 11:55:27 2022 -0600 +++ b/src/goodjava/bbcode/BBCode.java Mon Jul 18 23:49:47 2022 -0600 @@ -4,7 +4,6 @@ import java.util.ArrayList; import java.util.Map; import java.util.LinkedHashMap; -import java.util.regex.Matcher; import java.util.regex.Pattern; import goodjava.parser.Parser; @@ -276,10 +275,10 @@ if( !parser.matchIgnoreCase("[color=") ) return parser.failure(null); int start = parser.currentIndex(); - parser.match('#'); while( parser.inCharRange('0','9') || parser.inCharRange('a','z') || parser.inCharRange('A','Z') + || parser.anyOf("#(, )") ); String color = parser.textFrom(start); if( !parser.match(']') ) @@ -297,6 +296,8 @@ return parser.failure(null); int start = parser.currentIndex(); while( parser.match('.') || parser.inCharRange('0','9') ); + if( parser.matchIgnoreCase("pt") || parser.match('%') ) + ; // ok String size = parser.textFrom(start); if( !parser.match(']') ) return parser.failure(null); @@ -307,15 +308,6 @@ return parser.success(rtn); } - private static final Pattern youtubePtn1 = Pattern.compile("https://youtu.be/([a-zA-Z0-9_-]+)(?:\\?t=([0-9]+))?"); - private static final Pattern youtubePtn2 = Pattern.compile("https://www.youtube.com/watch?v=([a-zA-Z0-9_-]+)(?:\\?t=([0-9]+)s)?"); - private static final Pattern bitchutePtn = Pattern.compile("https://www.bitchute.com/video/([a-zA-Z0-9]+)/"); - - private static Matcher find(Pattern ptn,String s) { - Matcher m = ptn.matcher(s); - return m.find() ? m : null; - } - private Element parseVideo() { parser.begin(); if( !parser.matchIgnoreCase("[video]") ) @@ -323,26 +315,7 @@ String url = parseRealUrl(); if( !parser.matchIgnoreCase("[/video]") ) return parser.failure(null); - Map<String,String> extra = new LinkedHashMap<String,String>(); - Element rtn = new Element("video",null,url,extra); - Matcher m; - m = find(youtubePtn1,url); - if( m == null ) - m = find(youtubePtn2,url); - if( m != null ) { - extra.put( "site", "youtube" ); - extra.put( "id", m.group(1) ); - String t = m.group(2); - if( t != null ) - extra.put( "start", t ); - return parser.success(rtn); - } - m = find(bitchutePtn,url); - if( m != null ) { - extra.put( "site", "bitchute" ); - extra.put( "id", m.group(1) ); - return parser.success(rtn); - } + Element rtn = new Element("video",null,url); return parser.success(rtn); }