diff --git a/source/de/anomic/data/wikiCode.java b/source/de/anomic/data/wikiCode.java index f742e613f..43095f183 100644 --- a/source/de/anomic/data/wikiCode.java +++ b/source/de/anomic/data/wikiCode.java @@ -6,7 +6,7 @@ // Frankfurt, Germany, 2004 // // This file ist contributed by Alexander Schier -// last major change: 08.03.2006 +// last major change: 17.04.2006 // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -57,27 +57,30 @@ import de.anomic.plasma.plasmaSwitchboard; import de.anomic.server.serverCore; import de.anomic.yacy.yacyCore; -/** This class provides methods to handle texts that have been posted in the yacyWiki. */ +/** This class provides methods to handle texts that have been posted in the yacyWiki or other + * parts of YaCy that use this class, like the blog or the profile. + */ public class wikiCode { private String numListLevel=""; private String ListLevel=""; private String defListLevel=""; private plasmaSwitchboard sb; - private boolean cellprocessing=false; // needed for prevention of double-execution of replaceHTML + private boolean cellprocessing=false; //needed for prevention of double-execution of replaceHTML private boolean defList = false; //needed for definition lists private boolean escape = false; //needed for escape private boolean escaped = false; //needed for
not getting in the way private boolean escapeSpan = false; //needed for escape symbols [= and =] spanning over several lines - private boolean newrowstart=false; // needed for the first row not to be empty + private boolean newrowstart=false; //needed for the first row not to be empty + private boolean nolist = false; //needed for handling of [= andin lists private boolean preformatted = false; //needed for preformatted text private boolean preformattedSpan = false; //needed forandspanning over several lines private boolean replacedHTML = false; //indicates if method replaceHTML has been used with line already private boolean replacedCharacters = false; //indicates if method replaceCharachters has been used with line - private boolean table=false; // needed for tables, because they reach over several lines + private boolean table=false; //needed for tables, because they reach over several lines private int preindented = 0; //needed for indenteds private int escindented = 0; //needed for indented [=s private int headlines = 0; //number of headlines in page - private ArrayList dirElements = new ArrayList(); //List of headlines used to create diectory of page + private ArrayList dirElements = new ArrayList(); //list of headlines used to create diectory of page /** Constructor of the class wikiCode */ public wikiCode(plasmaSwitchboard switchboard){ @@ -453,46 +456,48 @@ public class wikiCode { /** This method processes ordered lists. */ private String orderedList(String result){ - int p0 = 0; - int p1 = 0; - //# sorted Lists contributed by [AS] - //## Sublist - if(result.startsWith(numListLevel + "#")){ //more # - p0 = result.indexOf(numListLevel); - p1 = result.length(); - result = "" + serverCore.crlfString + - "
"; - i--; - } - numListLevel = numListLevel.substring(0,i); - p0 = numListLevel.length(); - p1 = result.length(); - - if(numListLevel.length() > 0){ - result = tmp + - "- " + - result.substring(numListLevel.length() + 1, p1) + - "
"; - numListLevel += "#"; - }else if(numListLevel.length() > 0 && result.startsWith(numListLevel)){ //equal number of # - p0 = result.indexOf(numListLevel); - p1 = result.length(); - result = "- " + - result.substring(numListLevel.length(), p1) + - "
"; - }else if(numListLevel.length() > 0){ //less # - int i = numListLevel.length(); - String tmp = ""; - - while(! result.startsWith(numListLevel.substring(0,i)) ){ - tmp += "
). [MN] + int p0 = 0; + int p1 = 0; + //# sorted Lists contributed by [AS] + //## Sublist + if(result.startsWith(numListLevel + "#")){ //more # + p0 = result.indexOf(numListLevel); + p1 = result.length(); + result = "" + serverCore.crlfString + + "
"; + i--; + } + numListLevel = numListLevel.substring(0,i); + p0 = numListLevel.length(); + p1 = result.length(); + + if(numListLevel.length() > 0){ + result = tmp + + "- " + + result.substring(numListLevel.length() + 1, p1) + + "
"; + numListLevel += "#"; + }else if(numListLevel.length() > 0 && result.startsWith(numListLevel)){ //equal number of # + p0 = result.indexOf(numListLevel); + p1 = result.length(); + result = "- " + + result.substring(numListLevel.length(), p1) + + "
"; + }else if(numListLevel.length() > 0){ //less # + int i = numListLevel.length(); + String tmp = ""; + + while(! result.startsWith(numListLevel.substring(0,i)) ){ + tmp += "
). [MN] + int p0 = 0; + int p1 = 0; + //contributed by [AS] + if(result.startsWith(ListLevel + "*")){ //more stars + p0 = result.indexOf(ListLevel); + p1 = result.length(); + result = "
). [MN] + int p0 = 0; + int p1 = 0; + if(result.startsWith(defListLevel + ";")){ //more semicolons + String dt = ""; + String dd = ""; + p0 = result.indexOf(defListLevel); + p1 = result.length(); + String resultCopy = result.substring(defListLevel.length() + 1, p1); if((p0 = resultCopy.indexOf(":")) > 0){ dt = resultCopy.substring(0,p0); dd = resultCopy.substring(p0+1); - result = tmp + "
being parsed + String bq = ""; //gets filled with"; + result = transformLine(result.substring(0,p0).replaceAll("!pre!", "!pre!!")+"!pre!txt!"+result.substring(p1+12).replaceAll("!pre!", "!pre!!"), switchboard); + result = result.replaceAll("!pre!txt!", preformattedText); + result = result.replaceAll("!pre!!", "!pre!"); + } + //handles cases likes as needed + String escapeText = result.substring(p0+2); + //taking care of indented lines + while(result.substring(escindented,p0).startsWith(":")){ + escindented++; + bq = bq + ""; + escindented--; + } + result = transformLine("!esc!txt!"+result.substring(p0+2).replaceAll("!esc!", "!esc!!"), switchboard); + result = result.replaceAll("!esc!txt!", escapeText) + bq; + escaped = false; + } + //Getting rid of surplus =] + else if (((p0 = result.indexOf("=]"))>=0)&&(!escapeSpan)&&(!preformatted)){ + while((p0 = result.indexOf("=]"))>=0){ + result = result.substring(0,p0)+result.substring(p0+2); + } + result = transformLine(result, switchboard); + } + return result; + } + + /** This method handles the preformatted tags"; + } + result = transformLine(result.substring(escindented,p0).replaceAll("!esc!", "!esc!!")+"!esc!txt!", switchboard); + result = bq + result.replaceAll("!esc!txt!", escapeText); + escape = false; + escapeSpan = true; + } + + //end =] + else if(((p0 = result.indexOf("=]"))>=0)&&(escapeSpan)&&(!preformatted)){ + escapeSpan = false; + String bq = ""; //gets filled withs as neede + String escapeText = result.substring(0,p0); + //taking care of indented lines + while(escindented > 0){ + bq = bq + "*/ + //contributed by [MN] + private String preformattedTag(String result, plasmaSwitchboard switchboard){ + int p0 = 0; + int p1 = 0; + //implementation very similar to escape code (see above) + //bothandin the same line + if(((p0=result.indexOf("<pre>"))>=0)&&((p1=result.indexOf("</pre>"))>0)&&(!(escaped))){ + if(p0"+result.substring(p0+11,p1)+"
that would cause an exception otherwise + else{ + preformatted = true; + String temp1 = transformLine(result.substring(0,p0-1).replaceAll("!tmp!","!tmp!!")+"!tmp!txt!", switchboard); + nolist = true; + String temp2 = transformLine(result.substring(p0), switchboard); + nolist = false; + result = temp1.replaceAll("!tmp!txt!",temp2); + result = result.replaceAll("!tmp!!", "!tmp!"); + preformatted = false; + } + } + + //start
+ else if(((p0 = result.indexOf("<pre>"))>=0)&&(!preformattedSpan)&&(!escaped)){ + preformatted = true; //prevent surplus line breaks + String bq =""; //gets filled with"; + //taking care of indented lines + while (preindented > 0){ + bq = bq + ""; + preindented--; + } + result = transformLine("!pre!txt!"+result.substring(p0+12).replaceAll("!pre!", "!pre!!"), switchboard); + result = result.replaceAll("!pre!txt!", preformattedText) + bq; + result = result.replaceAll("!pre!!", "!pre!"); + preformatted = false; + } + //Getting rid of surplus + else if (((p0 = result.indexOf("</pre>"))>=0)&&(!preformattedSpan)&&(!escaped)){ + while((p0 = result.indexOf("</pre>"))>=0){ + result = result.substring(0,p0)+result.substring(p0+12); + } + result = transformLine(result, switchboard); + } + return result; + } + /** This method creates a directory for a wiki page. * @return directory of the wiki */ @@ -832,24 +976,27 @@ public class wikiCode { * @return the line of text with HTML tags instead of wiki tags */ public String transformLine(String result, plasmaSwitchboard switchboard) { - // transform page - int p0, p1; - + //If HTML has not bee replaced yet (can happen if method gets called in recursion), replace now! if (!replacedHTML){ result = replaceHTMLonly(result); replacedHTML = true; } + //If special characters have not bee replaced yet, replace now! if (!replacedCharacters){ result = replaceCharacters(result); replacedCharacters = true; } - //check if line contains any escape symbol or tag for preformatted text - //or if we are in an esacpe sequence already or if we are in a preformated text - //if that's the case the program will continue further below - //(see code for [= and =] ands as needed + String preformattedText = "s as needed + String preformattedText = result.substring(0,p0)+""+result.substring(p0+11); + //taking care of indented lines + while(result.substring(preindented,p0).startsWith(":")){ + preindented++; + bq = bq + "+ else if(((p0 = result.indexOf("</pre>"))>=0)&&(preformattedSpan)&&(!escaped)){ + preformattedSpan = false; + String bq = ""; //gets filled with"; + } + result = transformLine(result.substring(preindented,p0).replaceAll("!pre!", "!pre!!")+"!pre!txt!", switchboard); + result = bq + result.replaceAll("!pre!txt!", preformattedText); + result = result.replaceAll("!pre!!", "!pre!"); + preformattedSpan = true; + } + + //end
and) [MN] - if((result.indexOf("[=")<0)&&(result.indexOf("=]")<0)&&(!escapeSpan)&& - (result.indexOf("<pre>")<0)&&(result.indexOf("</pre>")<0)&&(!preformattedSpan)){ + //check if line contains escape symbols([= =]) or if we are in an escape sequence already. + if ((result.indexOf("[=")>=0)||(result.indexOf("=]")>=0)||(escapeSpan)){ + result = escapeTag(result, switchboard); + } + //check if line contains preformatted symbols or if we are in a preformatted sequence already. + else if ((result.indexOf("<pre>")>=0)||(result.indexOf("</pre>")>=0)||(preformattedSpan)){ + result = preformattedTag(result, switchboard); + } + //transform page as usual + else { //tables first -> wiki-tags in cells can be treated after that result = processTable(result, switchboard); @@ -888,114 +1035,7 @@ public class wikiCode { } - //escape code ([=...=]) contributed by [MN] - //both [= and =] in the same line - else if(((p0 = result.indexOf("[="))>=0)&&((p1 = result.indexOf("=]"))>0)&&(!(preformatted))){ - String escapeText = result.substring(p0+2,p1); - - //BUGS TO BE FIXED: [=[=text=]=] does not work properly: - //[=[= undx=]x=] should resolve as [= undx=]x, but resolves as [= undxx=] - //ALSO [=[= und =]=] [= und =] leads to an exception - // - //handlicg cases where the text inside [= and =] also contains - //[= and =]. Example: [=[=...=]=] - - result = transformLine(result.substring(0,p0).replaceAll("!esc!", "!esc!!")+"!esc!txt!"+result.substring(p1+2).replaceAll("!esc!", "!esc!!"), switchboard); - result = result.replaceAll("!esc!txt!", escapeText); - result = result.replaceAll("!esc!!", "!esc!"); - } - - //start [= - else if(((p0 = result.indexOf("[="))>=0)&&(!escapeSpan)&&(!preformatted)){ - escape = true; //prevent surplus line breaks - escaped = true; //prevents
being parsed - String bq = ""; //gets filled with- else if (((p0 = result.indexOf("</pre>"))>=0)&&(!preformattedSpan)&&(!escaped)){ - while((p0 = result.indexOf("</pre>"))>=0){ - result = result.substring(0,p0)+result.substring(p0+12); - } - result = transformLine(result, switchboard); - } - //end contrib [MN] - - replacedHTML = false; + if (!preformatted) replacedHTML = false; replacedCharacters = false; if ((result.endsWith(""))||(defList)||(escape)||(preformatted)||(table)||(cellprocessing)) return result; return result + "s as needed - String escapeText = result.substring(p0+2); - //taking care of indented lines - while(result.substring(escindented,p0).startsWith(":")){ - escindented++; - bq = bq + ""; - escindented--; - } - result = transformLine("!esc!txt!"+result.substring(p0+2).replaceAll("!esc!", "!esc!!"), switchboard); - result = result.replaceAll("!esc!txt!", escapeText) + bq; - escaped = false; - } - //Getting rid of surplus =] - else if (((p0 = result.indexOf("=]"))>=0)&&(!escapeSpan)&&(!preformatted)){ - while((p0 = result.indexOf("=]"))>=0){ - result = result.substring(0,p0)+result.substring(p0+2); - } - result = transformLine(result, switchboard); - } - //end contrib [MN] - - //preformatted code ("; - } - result = transformLine(result.substring(escindented,p0).replaceAll("!esc!", "!esc!!")+"!esc!txt!", switchboard); - result = bq + result.replaceAll("!esc!txt!", escapeText); - escape = false; - escapeSpan = true; - } - - //end =] - else if(((p0 = result.indexOf("=]"))>=0)&&(escapeSpan)&&(!preformatted)){ - escapeSpan = false; - String bq = ""; //gets filled withs as neede - String escapeText = result.substring(0,p0); - //taking care of indented lines - while(escindented > 0){ - bq = bq + "...) contributed by [MN] - //implementation very similar to escape code (see above) - //bothandin the same line - else if(((p0 = result.indexOf("<pre>"))>=0)&&((p1 = result.indexOf("</pre>"))>0)&&(!(escaped))){ - String preformattedText = ""+result.substring(p0+11,p1)+""; - result = transformLine(result.substring(0,p0).replaceAll("!pre!", "!pre!!")+"!pre!txt!"+result.substring(p1+12).replaceAll("!pre!", "!pre!!"), switchboard); - result = result.replaceAll("!pre!txt!", preformattedText); - result = result.replaceAll("!pre!!", "!pre!"); - } - - //start- else if(((p0 = result.indexOf("<pre>"))>=0)&&(!preformattedSpan)&&(!escaped)){ - preformatted = true; //prevent surplus line breaks - String bq =""; //gets filled with"; - //taking care of indented lines - while (preindented > 0){ - bq = bq + ""; - preindented--; - } - result = transformLine("!pre!txt!"+result.substring(p0+12).replaceAll("!pre!", "!pre!!"), switchboard); - result = result.replaceAll("!pre!txt!", preformattedText) + bq; - result = result.replaceAll("!pre!!", "!pre!"); - preformatted = false; - } - //Getting rid of surpluss as needed - String preformattedText = "s as needed - String preformattedText = result.substring(0,p0)+""+result.substring(p0+11); - //taking care of indented lines - while(result.substring(preindented,p0).startsWith(":")){ - preindented++; - bq = bq + "- else if(((p0 = result.indexOf("</pre>"))>=0)&&(preformattedSpan)&&(!escaped)){ - preformattedSpan = false; - String bq = ""; //gets filled with"; - } - result = transformLine(result.substring(preindented,p0).replaceAll("!pre!", "!pre!!")+"!pre!txt!", switchboard); - result = bq + result.replaceAll("!pre!txt!", preformattedText); - result = result.replaceAll("!pre!!", "!pre!"); - preformattedSpan = true; - } - - //end