[hmath-commits] org.hmath.server/WEB-INF/src/org/hartmath/server/filter WikipediaFilter.java,1.4,1.5
Status: Pre-Alpha
Brought to you by:
jsurfer
|
From: Klaus H. <js...@us...> - 2004-03-28 17:35:46
|
Update of /cvsroot/hmath/org.hmath.server/WEB-INF/src/org/hartmath/server/filter In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25883/WEB-INF/src/org/hartmath/server/filter Modified Files: WikipediaFilter.java Log Message: parser changes Index: WikipediaFilter.java =================================================================== RCS file: /cvsroot/hmath/org.hmath.server/WEB-INF/src/org/hartmath/server/filter/WikipediaFilter.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** WikipediaFilter.java 21 Mar 2004 17:18:08 -0000 1.4 --- WikipediaFilter.java 28 Mar 2004 17:24:26 -0000 1.5 *************** *** 59,63 **** */ ! public class WikipediaFilter extends FilterSupport implements CacheFilter { private FilterContext fContext; private RenderEngine fWikiEngine; --- 59,63 ---- */ ! public class WikipediaFilter extends FilterSupport implements CacheFilter, IWikipediaFilterConstants { private FilterContext fContext; private RenderEngine fWikiEngine; *************** *** 804,807 **** --- 804,812 ---- continue; } + } + if (levelMinus==2) { + copyWhite(fWhiteStart, fWhiteStartPosition, 2); + fWhiteStart = false; + return TokenSTRIKETHROUGH; } break; *************** *** 837,850 **** String urlString = new String(fSource, urlStartPosition - 1, fCurrentPosition - urlStartPosition); fCurrentPosition--; ! // Does our engine know images? ! if (fWikiEngine instanceof ImageRenderEngine) { ! fResult.append(((ImageRenderEngine) fWikiEngine).getExternalImageLink()); ! } ! fResult.append("<span class=\"nobr\">"); ! fResult.append("<a href=\""); ! fResult.append(Encoder.escape(urlString)); ! fResult.append("\">"); ! fResult.append(Encoder.toEntity(urlString.charAt(0)) + urlString.substring(1)); ! fResult.append("</a></span>"); continue; } --- 842,846 ---- String urlString = new String(fSource, urlStartPosition - 1, fCurrentPosition - urlStartPosition); fCurrentPosition--; ! createExternalLink(urlString); continue; } *************** *** 970,973 **** --- 966,983 ---- } + private void createExternalLink(String urlString) { + + // Does our engine know images? + if (fWikiEngine instanceof ImageRenderEngine) { + fResult.append(((ImageRenderEngine) fWikiEngine).getExternalImageLink()); + } + fResult.append("<span class=\"nobr\">"); + fResult.append("<a href=\""); + fResult.append(Encoder.escape(urlString)); + fResult.append("\">"); + fResult.append(Encoder.toEntity(urlString.charAt(0)) + urlString.substring(1)); + fResult.append("</a></span>"); + } + private void handleTeXMath(String mathContent, boolean inlineExpression) { // TODO clean this up *************** *** 1005,1016 **** break; default : ! fResult.append(fResult); } } private void handleSnipLink(String name) { if (name != null) { // User probably wrote [http://radeox.org] instead of http://radeox.org ! if (name.indexOf("http://") != -1) { ! fResult.append("<div class=\"error\">Do not surround URLs with [...].</div>"); } else { // trim the name and unescape it --- 1015,1030 ---- break; default : ! copyWhite(mathContent); ! } } private void handleSnipLink(String name) { if (name != null) { + int index = name.indexOf("http://"); // User probably wrote [http://radeox.org] instead of http://radeox.org ! if (index != -1) { ! createExternalLink(name.substring(index)); ! // show error ! // fResult.append("<div class=\"error\">Do not surround URLs with [...].</div>"); } else { // trim the name and unescape it *************** *** 1697,1700 **** --- 1711,1719 ---- final static int TokenHTML_STRONG_OPEN = 242; + final static int TokenHTML_VAR_OPEN = 245; + final static int TokenHTML_VAR_CLOSE = 246; + final static int TokenHTML_CODE_OPEN = 247; + final static int TokenHTML_CODE_CLOSE = 248; + final static int TokenHTML_MATH_OPEN = 400; final static int TokenHTML_MATH_CLOSE = 401; *************** *** 1756,1760 **** final static Token HTML_SUP_OPEN = new OpenTagToken(TokenHTML_SUP_OPEN, "sup", "<sup class=\"sup\">"); ! final static Token HTML_MATH_OPEN = new OpenTagToken(TokenHTML_MATH_CLOSE, "math", "<math class=\"math\">"); final static Token HTML_MATH_CLOSE = new CloseTagToken(TokenHTML_MATH_OPEN, "math", "</math>"); --- 1775,1779 ---- final static Token HTML_SUP_OPEN = new OpenTagToken(TokenHTML_SUP_OPEN, "sup", "<sup class=\"sup\">"); ! final static Token HTML_MATH_OPEN = new OpenTagToken(TokenHTML_MATH_CLOSE, "math", "<math>"); final static Token HTML_MATH_CLOSE = new CloseTagToken(TokenHTML_MATH_OPEN, "math", "</math>"); *************** *** 1762,1893 **** final static Token LIST_UL_START = new Token(TokenLIST_UL_START); final static HashMap OPEN_TAGS = new HashMap(); final static HashMap CLOSE_TAGS = new HashMap(); final static HashSet ENTITY_SET = new HashSet(); - final static String[] ENTITY_STRINGS = - { - "amp", - "lt", - "gt", - "quot", - "nbsp", - "iexcl", - "cent", - "pound", - "curren", - "yen", - "trade", - "copy", - "reg", - "euro", - "brvbar", - "brkbar", - "sect", - "uml", - "die", - "ordf", - "laquo", - "not", - "shy", - "reg", - "macr", - "hibar", - "deg", - "plusmn", - "sup2", - "sup3", - "acute", - "micro", - "para", - "middot", - "cedil", - "sup1", - "ordm", - "raquo", - "frac14", - "frac12", - "frac34", - "iquest", - "Agrave", - "Aacute", - "Acirc", - "Atilde", - "Auml", - "Aring", - "AElig", - "Ccedil", - "Egrave", - "Eacute", - "Ecirc", - "Euml", - "lgrave", - "lacute", - "lcirc", - "luml", - "ETH", - "Ntilde", - "Ograve", - "Oacute", - "Ocirc", - "Otilde", - "Ouml", - "times", - "Oslash", - "Ugrave", - "Uacute", - "Ucirc", - "Uuml", - "Yacute", - "THORN", - "szlig", - "agrave", - "aacute", - "acirc", - "atilde", - "auml", - "aring", - "aelig", - "ccedil", - "egrave", - "eacute", - "ecirc", - "euml", - "igrave", - "iacute", - "icirc", - "iuml", - "eth", - "ntilde", - "ograve", - "oacute", - "ocirc", - "otilde", - "ouml", - "divide", - "oslash", - "ugrave", - "uacute", - "ucirc", - "uuml", - "yacute", - "thorn", - "yuml", - "iquest", - "iexcl", - "sect", - "para", - "dagger", - "Dagger", - "bull", - "mdash", - "lsaquo", - "rsaquo", - "laquo", - "raquo", - "lsquo", - "rsquo", - "ldquo", - "rdquo" }; private static Log log = LogFactory.getLog(WikipediaFilter.class); --- 1781,1793 ---- final static Token LIST_UL_START = new Token(TokenLIST_UL_START); + final static Token HTML_VAR_CLOSE = new CloseTagToken(TokenHTML_VAR_CLOSE, "var", "</var>"); + final static Token HTML_VAR_OPEN = new OpenTagToken(TokenHTML_VAR_OPEN, "var", "<var>"); + final static Token HTML_CODE_CLOSE = new CloseTagToken(TokenHTML_CODE_CLOSE, "code", "</code>"); + final static Token HTML_CODE_OPEN = new OpenTagToken(TokenHTML_CODE_OPEN, "code", "<code>"); + final static HashMap OPEN_TAGS = new HashMap(); final static HashMap CLOSE_TAGS = new HashMap(); final static HashSet ENTITY_SET = new HashSet(); private static Log log = LogFactory.getLog(WikipediaFilter.class); *************** *** 1932,1935 **** --- 1832,1840 ---- CLOSE_TAGS.put("blockquote", HTML_BLOCKQUOTE_CLOSE); + OPEN_TAGS.put("var", HTML_PRE_OPEN); + CLOSE_TAGS.put("var", HTML_PRE_CLOSE); + OPEN_TAGS.put("code", HTML_CODE_OPEN); + CLOSE_TAGS.put("code", HTML_CODE_CLOSE); + OPEN_TAGS.put("sub", HTML_SUB_OPEN); CLOSE_TAGS.put("sub", HTML_SUB_CLOSE); *************** *** 1986,1991 **** --- 1891,1900 ---- fContext = context; fWikiEngine = context.getRenderContext().getRenderEngine(); + try { SnipMacroParameter params = (SnipMacroParameter) fContext.getMacroParameter(); fSnip = params.getSnipRenderContext().getSnip(); + } catch (ClassCastException e) { + e.printStackTrace(); + } return filter(input, 0); } |