X-Git-Url: http://git.phpeclipse.com diff --git a/archive/org.plog4u.wiki/src/org/plog4u/wiki/filter/WikipediaParser.java b/archive/org.plog4u.wiki/src/org/plog4u/wiki/filter/WikipediaParser.java index 5383fb7..f0a4790 100644 --- a/archive/org.plog4u.wiki/src/org/plog4u/wiki/filter/WikipediaParser.java +++ b/archive/org.plog4u.wiki/src/org/plog4u/wiki/filter/WikipediaParser.java @@ -103,7 +103,6 @@ public class WikipediaParser { // private String fSrcPath; // private String fBinPath; - public WikipediaParser(MacroRepository macros, String stringSource, StringBuffer result, FilterContext context, int recursionLevel) { fContext = context; fWikiEngine = context.getRenderContext().getRenderEngine(); @@ -182,7 +181,7 @@ public class WikipediaParser { } else { lastIndex++; } - fResultBuffer.append("<"); + fResultBuffer.append("<"); break; case '>': // special html escape character if (lastIndex < (currentIndex - 1)) { @@ -191,7 +190,7 @@ public class WikipediaParser { } else { lastIndex++; } - fResultBuffer.append(">"); + fResultBuffer.append(">"); break; case '&': // special html escape character if (lastIndex < (currentIndex - 1)) { @@ -370,6 +369,7 @@ public class WikipediaParser { char closeCharacter; char nextCharacter; if (getNextChar('/')) { + // end tag detected currentHtmlPosition++; // closing tag int r = readUntilCharOrEOL('>'); @@ -405,24 +405,26 @@ public class WikipediaParser { } } else { - // opening tag + // start tag String tokenString; int tagNameStart = fCurrentPosition; int tokenLength = 0; - while (Character.isJavaIdentifierStart(fSource[fCurrentPosition++])) { + while (Character.isJavaIdentifierStart(fSource[fCurrentPosition])) { + fCurrentPosition++; tokenLength++; } try { - tokenString = new String(fSource, tagNameStart, fCurrentPosition - tagNameStart - 1); //tagTokenizer.nextToken(); + tokenString = new String(fSource, tagNameStart, fCurrentPosition - tagNameStart); //tagTokenizer.nextToken(); + OpenTagToken token = (OpenTagToken) WikipediaFilter.OPEN_TAGS.get(tokenString); if (token == null) { return WikipediaFilter.TokenNotFound; } copyWhite(fWhiteStart, fWhiteStartPosition, (fCurrentPosition - tagNameStart) + 1); fWhiteStart = false; - if (token instanceof SpecialTagToken) { - fResultBuffer.append(token.getOpenTag()); + // for




+ while (Character.isWhitespace(fSource[fCurrentPosition])) { fCurrentPosition++; } @@ -431,17 +433,21 @@ public class WikipediaParser { } if (fSource[fCurrentPosition] == '>') { fCurrentPosition++; + fWhiteStartPosition = fCurrentPosition; + // insert the special tag : + fResultBuffer.append(token.getOpenTag()); + return WikipediaFilter.TokenIgnore; } + } else if (token instanceof OpenTagToken) { fResultBuffer.append("<"); fResultBuffer.append(token.getTagName()); fTokenStack.push(token); - fCurrentPosition = token.scan(fResultBuffer, fSource, fCurrentPosition - 1); + fCurrentPosition = token.scan(fResultBuffer, fSource, fCurrentPosition); fResultBuffer.append(">"); + return WikipediaFilter.TokenIgnore; } - - // System.out.println(fResultBuffer); - return WikipediaFilter.TokenIgnore; + return WikipediaFilter.TokenNotFound; } catch (NoSuchElementException e) { return WikipediaFilter.TokenNotFound; } @@ -701,9 +707,9 @@ public class WikipediaParser { int index = head.indexOf(": "); if (index > 0) { fResultBuffer.append("
"); - fResultBuffer.append(head.substring(0,index)); + fResultBuffer.append(head.substring(0, index)); fResultBuffer.append("
"); - fResultBuffer.append(head.substring(index+2)); + fResultBuffer.append(head.substring(index + 2)); fResultBuffer.append("
"); } else { fResultBuffer.append("
"); @@ -716,79 +722,6 @@ public class WikipediaParser { continue; } break; - // case '\\': // special characters follow - // copyWhite(fWhiteStart, fWhiteStartPosition, 1); - // fWhiteStart = false; - // try { - // fCurrentCharacter = fSource[fCurrentPosition++]; - // switch (fCurrentCharacter) { - // case '\\': // newline - // if ((fCurrentCharacter = fSource[fCurrentPosition++]) == '\\') { - // fResultBuffer.append(Encoder - // .toEntity(fCurrentCharacter)); - // break; - // } else { - // fResultBuffer.append("
"); - // break; - // } - // default: - // fResultBuffer.append(Encoder - // .toEntity(fCurrentCharacter)); - // } - // } catch (IndexOutOfBoundsException e) { - // - // } - // continue; - // case '$' : // detect tex math - // copyWhite(fWhiteStart, fWhiteStartPosition, 1); - // fWhiteStart = false; - // startOfIndent = false; - // int startMathPosition = fCurrentPosition; - // if (getNextChar('$')) { - // startMathPosition = fCurrentPosition; - // copyWhite(fWhiteStart, fWhiteStartPosition, 2); - // fWhiteStart = false; - // if (readUntilString("$$")) { - // String mathContent = new String(fSource, startMathPosition, - // fCurrentPosition - startMathPosition - 2); - // if (mathContent != null) { - // handleTeXMath(mathContent, false); - // continue; - // } - // } - // } else { - // if (readUntilChar('$')) { - // String mathContent = new String(fSource, startMathPosition, - // fCurrentPosition - startMathPosition - 1); - // if (mathContent != null) { - // handleTeXMath(mathContent, true); - // continue; - // } - // } - // } - // break; - case '{': - // detect macros - copyWhite(fWhiteStart, fWhiteStartPosition, 1); - fWhiteStart = false; - // boolean scanBody = true; - int startMacroPosition = fCurrentPosition; - if (getNextChar('|') && handleWikipediaTable()) { // Wikipedia - // table - // syntax - continue; - } else { - if (readUntilChar('}')) { - String macroStartTag; - - macroStartTag = new String(fSource, startMacroPosition, fCurrentPosition - startMacroPosition - 1); - if (macroStartTag != null) { - createMacro(startMacroPosition, macroStartTag); - continue; - } - } - } - break; case '[': int startLinkPosition = fCurrentPosition; if (getNextChar('[')) { // wikipedia link style @@ -830,56 +763,6 @@ public class WikipediaParser { } } break; - // case '1': // heading filter ? - // int temp1Position = checkWhitespaces(fWhiteStartPosition, - // fCurrentPosition - 2); - // if (temp1Position >= 0) { - // copyWhite(fWhiteStart, fWhiteStartPosition, 1); - // fWhiteStart = false; - // int simpleHeader = getNextChar(' ', '.'); - // if (simpleHeader < 0) { - // if (getNextChar('1')) { - // fCurrentPosition--; - // if (getList('1', "
    ", "
")) { - // continue; - // } - // } - // break; - // } - // if (simpleHeader == 1 && !getNextChar('1')) { - // fCurrentPosition--; - // if (getList('1', "
    ", "
")) { - // continue; - // } - // break; - // } - // temp1Position = fCurrentPosition; - // if (simpleHeader >= 0 && readUntilChar('\n')) { - // String heading = new String(fSource, temp1Position, - // fCurrentPosition - temp1Position - 1); - // if (heading != null) { - // fResultBuffer.append("

"); - // // System.out.println(heading); - // fResultBuffer - // .append(WikipediaFilter - // .filterParser( - // heading, - // fContext, - // WikipediaFilter.DUMMY_CACHED_PAGE, - // fMacros, - // fRecursionLevel)); - // fResultBuffer.append("

"); - // continue; - // } - // } - // } - // break; case '*': //