Mercurial Hosting > luan
view src/luan/modules/HtmlLuan.java @ 1849:9f2680fe532b
better proc handling
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Fri, 21 Feb 2025 12:23:56 -0700 |
parents | 31a82b0d0a87 |
children |
line wrap: on
line source
package luan.modules; import java.util.List; import java.util.ArrayList; import java.util.Set; import java.util.HashSet; import goodjava.html.Html; import luan.LuanTable; import luan.LuanException; public final class HtmlLuan { public static String encode(String s) throws LuanException { Utils.checkNotNull(s); return Html.encode(s); } public static String decode(String s) { return Html.decode(s); } private static LuanTable tag(Html.Tag tag) throws LuanException { LuanTable tbl = new LuanTable(); tbl.rawPut("type","tag"); tbl.rawPut("name",tag.name); tbl.rawPut("attributes",new LuanTable(tag.attributes)); tbl.rawPut("is_empty",tag.isEmpty); tbl.rawPut("raw",tag.raw); if( tag.style != null ) tbl.rawPut("style",new LuanTable(tag.style)); return tbl; } public static LuanTable parse(String text,LuanTable containerTagsTbl) { try { Set<String> containerTags = new HashSet(); for( Object s : containerTagsTbl.asList() ) { containerTags.add((String)s); } List list = Html.parse(text,containerTags); List rtn = new ArrayList(); for( Object el : list ) { if( el instanceof String ) { rtn.add(el); } else if( el instanceof Html.Tag ) { Html.Tag tag = (Html.Tag)el; rtn.add(tag(tag)); } else if( el instanceof Html.Comment ) { Html.Comment comment = (Html.Comment)el; LuanTable tbl = new LuanTable(); tbl.rawPut("type","comment"); tbl.rawPut("text",comment.text); rtn.add(tbl); } else if( el instanceof Html.CData ) { Html.CData cdata = (Html.CData)el; LuanTable tbl = new LuanTable(); tbl.rawPut("type","cdata"); tbl.rawPut("text",cdata.text); rtn.add(tbl); } else if( el instanceof Html.Container ) { Html.Container container = (Html.Container)el; LuanTable tbl = new LuanTable(); tbl.rawPut("type","container"); tbl.rawPut("tag",tag(container.tag)); tbl.rawPut("text",container.text); rtn.add(tbl); } else { throw new RuntimeException("invalid el "+el); } } return new LuanTable(rtn); } catch(LuanException e) { throw new RuntimeException(e); } } }