*) cleaning up code (still not done)

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@7267 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
low012 15 years ago
parent e3e3b49d52
commit 65a0381f76

@ -35,13 +35,13 @@ import net.yacy.document.parser.html.CharacterCoding;
import de.anomic.server.serverCore; import de.anomic.server.serverCore;
/** This class provides methods to handle texts that have been posted in the yacyWiki or other /** 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. * parts of YaCy which use wiki code, like the blog or the profile.
* *
* @author Alexander Schier [AS], Franz Brausze [FB], Marc Nause [MN] * @author Alexander Schier [AS], Franz Brausze [FB], Marc Nause [MN]
*/ */
public class wikiCode extends abstractWikiParser implements wikiParser { public class wikiCode extends abstractWikiParser implements wikiParser {
private static final String ASTERISK = "*";
private static final String EMPTY = ""; private static final String EMPTY = "";
private static final String PIPE_ESCAPED = "|"; private static final String PIPE_ESCAPED = "|";
private static final String REGEX_NOT_CHAR_NUM_OR_UNDERSCORE = "[^a-zA-Z0-9_]"; private static final String REGEX_NOT_CHAR_NUM_OR_UNDERSCORE = "[^a-zA-Z0-9_]";
@ -64,6 +64,7 @@ public class wikiCode extends abstractWikiParser implements wikiParser {
private static final String WIKI_CLOSE_LINK = "]]"; private static final String WIKI_CLOSE_LINK = "]]";
private static final String WIKI_OPEN_LINK = "[["; private static final String WIKI_OPEN_LINK = "[[";
private static final String WIKI_CLOSE_EXTERNAL_LINK = "]"; private static final String WIKI_CLOSE_EXTERNAL_LINK = "]";
private static final String WIKI_OPEN_EXTERNAL_LINK = "[";
private static final String WIKI_CLOSE_PRE_ESCAPED = "</pre>"; private static final String WIKI_CLOSE_PRE_ESCAPED = "</pre>";
private static final String WIKI_OPEN_STRIKE = "<s>"; private static final String WIKI_OPEN_STRIKE = "<s>";
private static final String WIKI_CLOSE_STRIKE = "</s>"; private static final String WIKI_CLOSE_STRIKE = "</s>";
@ -78,9 +79,9 @@ public class wikiCode extends abstractWikiParser implements wikiParser {
private static final String WIKI_HEADLINE_TAG_6 = "======"; private static final String WIKI_HEADLINE_TAG_6 = "======";
private static final String WIKI_HR_LINE = "----"; private static final String WIKI_HR_LINE = "----";
private static final String WIKI_IMAGE = "Image:"; private static final String WIKI_IMAGE = "Image:";
private static final String WIKI_OPEN_EXTERNAL_LINK = "[";
private static final String WIKI_OPEN_PRE_ESCAPED = "<pre>"; private static final String WIKI_OPEN_PRE_ESCAPED = "<pre>";
private static final char ASTERISK = '*';
private static final char ONE = '1'; private static final char ONE = '1';
private static final char TWO = '2'; private static final char TWO = '2';
private static final char THREE = '3'; private static final char THREE = '3';
@ -97,6 +98,7 @@ public class wikiCode extends abstractWikiParser implements wikiParser {
private static final int LEN_WIKI_OPEN_EXTERNAL_LINK = WIKI_OPEN_EXTERNAL_LINK.length(); private static final int LEN_WIKI_OPEN_EXTERNAL_LINK = WIKI_OPEN_EXTERNAL_LINK.length();
private static final int LEN_WIKI_CLOSE_EXTERNAL_LINK = WIKI_CLOSE_EXTERNAL_LINK.length(); private static final int LEN_WIKI_CLOSE_EXTERNAL_LINK = WIKI_CLOSE_EXTERNAL_LINK.length();
private static final int LEN_WIKI_HR_LINE = WIKI_HR_LINE.length(); private static final int LEN_WIKI_HR_LINE = WIKI_HR_LINE.length();
private static final int LEN_PIPE_ESCAPED = PIPE_ESCAPED.length();
private final List<String> tableOfContentElements = new ArrayList<String>(); //list of headlines used to create table of content of page private final List<String> tableOfContentElements = new ArrayList<String>(); //list of headlines used to create table of content of page
@ -111,7 +113,7 @@ public class wikiCode extends abstractWikiParser implements wikiParser {
private final static char[] HEADLINE_LEVEL = new char[]{ONE, TWO, THREE, FOUR, FIVE, SIX}; private final static char[] HEADLINE_LEVEL = new char[]{ONE, TWO, THREE, FOUR, FIVE, SIX};
private String numberedListLevel = EMPTY; private String orderedListLevel = EMPTY;
private String unorderedListLevel = EMPTY; private String unorderedListLevel = EMPTY;
private String defListLevel = EMPTY; private String defListLevel = EMPTY;
private boolean processingCell = false; //needed for prevention of double-execution of replaceHTML private boolean processingCell = false; //needed for prevention of double-execution of replaceHTML
@ -144,6 +146,10 @@ public class wikiCode extends abstractWikiParser implements wikiParser {
PROPERTY_VALUES.put("align", array); PROPERTY_VALUES.put("align", array);
} }
private enum ListType {
ORDERED, UNORDERED;
}
/** /**
* Constructor * Constructor
* @param address * @param address
@ -188,7 +194,7 @@ public class wikiCode extends abstractWikiParser implements wikiParser {
final int lenTableEnd = tableEnd.length(); final int lenTableEnd = tableEnd.length();
final int lenAttribDivider = attribDivider.length(); final int lenAttribDivider = attribDivider.length();
if ((line.startsWith(tableStart)) && (!processingTable)) { if (line.startsWith(tableStart) && !processingTable) {
processingTable = true; processingTable = true;
newRowStart = true; newRowStart = true;
out.append("<table"); out.append("<table");
@ -196,14 +202,14 @@ public class wikiCode extends abstractWikiParser implements wikiParser {
out.append(filterTableProperties(line.substring(lenTableStart).trim())); out.append(filterTableProperties(line.substring(lenTableStart).trim()));
} }
out.append(">"); out.append(">");
} else if (line.startsWith(newLine) && (processingTable)) { // new row } else if (line.startsWith(newLine) && processingTable) { // new row
if (!newRowStart) { if (!newRowStart) {
out.append("\t</tr>\n"); out.append("\t</tr>\n");
} else { } else {
newRowStart = false; newRowStart = false;
} }
out.append("\t<tr>"); out.append("\t<tr>");
} else if ((line.startsWith(cellDivider)) && (processingTable)) { } else if (line.startsWith(cellDivider) && processingTable) {
out.append("\t\t<td"); out.append("\t\t<td");
final int cellEnd = (line.indexOf(cellDivider, lenCellDivider) > 0) ? (line.indexOf(cellDivider, lenCellDivider)) : (line.length()); final int cellEnd = (line.indexOf(cellDivider, lenCellDivider) > 0) ? (line.indexOf(cellDivider, lenCellDivider)) : (line.length());
int propEnd = line.indexOf(attribDivider, lenCellDivider); int propEnd = line.indexOf(attribDivider, lenCellDivider);
@ -250,7 +256,7 @@ public class wikiCode extends abstractWikiParser implements wikiParser {
} }
// contributed by [MN], changes by [FB] // contributed by [MN], changes by [FB]
/** This method takes possible table properties and tests if they are valid. /** Takes possible table properties and tests if they are valid.
* Valid in this case means if they are a property for the table, tr or td * Valid in this case means if they are a property for the table, tr or td
* tag as stated in the HTML Pocket Reference by Jennifer Niederst (1st edition) * tag as stated in the HTML Pocket Reference by Jennifer Niederst (1st edition)
* The method is important to avoid XSS attacks on the wiki via table properties. * The method is important to avoid XSS attacks on the wiki via table properties.
@ -265,13 +271,13 @@ public class wikiCode extends abstractWikiParser implements wikiParser {
final int numberOfValues = values.length; final int numberOfValues = values.length;
for (int i = 0; i < numberOfValues; i++) { for (int i = 0; i < numberOfValues; i++) {
key = values[i].trim(); key = values[i].trim();
if (key.equals("nowrap")) { if ("nowrap".equals(key)) {
appendKeyValuePair("nowrap", "nowrap", stringBuilder); appendKeyValuePair("nowrap", "nowrap", stringBuilder);
} else if (i + 1 < numberOfValues) { } else if (i + 1 < numberOfValues) {
value = values[++i].trim(); value = values[++i].trim();
if ((key.equals("summary")) if (("summary".equals(key))
|| (key.equals("bgcolor") && value.matches("#{0,1}[0-9a-fA-F]{1,6}|[a-zA-Z]{3,}")) || ("bgcolor".equals(key) && value.matches("#{0,1}[0-9a-fA-F]{1,6}|[a-zA-Z]{3,}"))
|| ((key.equals("width") || key.equals("height")) && value.matches("\\d+%{0,1}")) || (("width".equals(key) || "height".equals(key)) && value.matches("\\d+%{0,1}"))
|| ((posVals = PROPERTY_VALUES.get(key)) != null && Arrays.binarySearch(posVals, value) >= 0) || ((posVals = PROPERTY_VALUES.get(key)) != null && Arrays.binarySearch(posVals, value) >= 0)
|| (Arrays.binarySearch(TABLE_PROPERTIES, key) >= 0 && value.matches("\\d+"))) { || (Arrays.binarySearch(TABLE_PROPERTIES, key) >= 0 && value.matches("\\d+"))) {
appendKeyValuePair(key, value, stringBuilder); appendKeyValuePair(key, value, stringBuilder);
@ -297,141 +303,152 @@ public class wikiCode extends abstractWikiParser implements wikiParser {
* @param line line of text to be transformed from wiki code to HTML * @param line line of text to be transformed from wiki code to HTML
* @return HTML fragment * @return HTML fragment
*/ */
private String processOrderedList(String line) { private String processOrderedList(final String line) {
if (!noList) { //lists only get processed if not forbidden (see code for [= and <pre>). [MN] return processList(line, ListType.ORDERED);
//# sorted Lists contributed by [AS]
//## Sublist
if (line.startsWith(numberedListLevel + "#")) { //more #
line = HTML_OPEN_ORDERED_LIST + serverCore.CRLF_STRING
+ HTML_OPEN_LIST_ELEMENT
+ line.substring(numberedListLevel.length() + 1, line.length())
+ HTML_CLOSE_LIST_ELEMENT;
numberedListLevel += "#";
} else if (numberedListLevel.length() > 0 && line.startsWith(numberedListLevel)) { //equal number of #
line = HTML_OPEN_LIST_ELEMENT
+ line.substring(numberedListLevel.length(), line.length())
+ HTML_CLOSE_LIST_ELEMENT;
} else if (numberedListLevel.length() > 0) { //less #
int i = numberedListLevel.length();
String tmp = EMPTY;
while (!line.startsWith(numberedListLevel.substring(0, i))) {
tmp += HTML_CLOSE_ORDERED_LIST;
i--;
}
numberedListLevel = numberedListLevel.substring(0, i);
final int positionOfOpeningTag = numberedListLevel.length();
final int positionOfClosingTag = line.length();
if (numberedListLevel.length() > 0) {
line = tmp
+ HTML_OPEN_LIST_ELEMENT
+ line.substring(positionOfOpeningTag, positionOfClosingTag)
+ HTML_CLOSE_LIST_ELEMENT;
} else {
line = tmp + line.substring(positionOfOpeningTag, positionOfClosingTag);
}
}
// end contrib [AS]
}
return line;
} }
//contributed by [AS] put into it's own method by [MN]
/** /**
* Processes tags which are connected to unordered lists. * Processes tags which are connected to unordered lists.
* @param line line of text to be transformed from wiki code to HTML * @param line line of text to be transformed from wiki code to HTML
* @return HTML fragment * @return HTML fragment
*/ */
private String processUnorderedList(String line) { private String processUnorderedList(String line) {
if (!noList) { //lists only get processed if not forbidden (see code for [= and <pre>). [MN] return processList(line, ListType.UNORDERED);
//contributed by [AS] }
if (line.startsWith(unorderedListLevel + ASTERISK)) { //more stars
line = HTML_OPEN_UNORDERED_LIST + serverCore.CRLF_STRING /**
+ HTML_OPEN_LIST_ELEMENT * Processes tags which are connected to ordered or unordered lists.
+ line.substring(unorderedListLevel.length() + 1, line.length()) * @author contains code by [AS]
+ HTML_CLOSE_LIST_ELEMENT; * @param line line of text to be transformed from wiki code to HTML
unorderedListLevel += ASTERISK; * @param listType type of tags to be processed
} else if (unorderedListLevel.length() > 0 && line.startsWith(unorderedListLevel)) { //equal number of stars * @return HTML fragment
line = HTML_OPEN_LIST_ELEMENT */
+ line.substring(unorderedListLevel.length(), line.length()) private String processList(final String line, final ListType listType) {
+ HTML_CLOSE_LIST_ELEMENT;
} else if (unorderedListLevel.length() > 0) { //less stars final String ret;
int i = unorderedListLevel.length();
String tmp = EMPTY; if (!noList) { //lists only get processed if not forbidden (see code for [= and <pre>).
String listLevel;
final String htmlOpenList;
final String htmlCloseList;
final char symbol;
if (ListType.ORDERED.equals(listType)) {
listLevel = orderedListLevel;
symbol = '#';
htmlOpenList = HTML_OPEN_ORDERED_LIST;
htmlCloseList = HTML_CLOSE_ORDERED_LIST;
} else if (ListType.UNORDERED.equals(listType)) {
listLevel = unorderedListLevel;
symbol = ASTERISK;
htmlOpenList = HTML_OPEN_UNORDERED_LIST;
htmlCloseList = HTML_CLOSE_UNORDERED_LIST;
} else {
throw new IllegalArgumentException("Unknown list type " + listType);
}
while (unorderedListLevel.length() >= i && !line.startsWith(unorderedListLevel.substring(0, i))) { if (line.startsWith(listLevel + symbol)) { //more #
tmp += HTML_CLOSE_UNORDERED_LIST; final StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(htmlOpenList);
stringBuilder.append(serverCore.CRLF_STRING);
stringBuilder.append(HTML_OPEN_LIST_ELEMENT);
stringBuilder.append(line.substring(listLevel.length() + 1).trim());
stringBuilder.append(HTML_CLOSE_LIST_ELEMENT);
ret = stringBuilder.toString();
listLevel += symbol;
} else if (listLevel.length() > 0 &&
line.startsWith(listLevel)) { //equal number of #
final StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(HTML_OPEN_LIST_ELEMENT);
stringBuilder.append(line.substring(listLevel.length()).trim());
stringBuilder.append(HTML_CLOSE_LIST_ELEMENT);
ret = stringBuilder.toString();
} else if (listLevel.length() > 0) { //less #
final StringBuilder stringBuilder = new StringBuilder();
final StringBuilder tmp = new StringBuilder();
int i = listLevel.length();
while (!line.startsWith(listLevel.substring(0, i))) {
tmp.append(htmlCloseList);
i--; i--;
} }
int positionOfOpeningTag = unorderedListLevel.length(); listLevel = listLevel.substring(0, i);
if (i < positionOfOpeningTag) {
unorderedListLevel = unorderedListLevel.substring(0, i); final int startOfContent = listLevel.length();
positionOfOpeningTag = unorderedListLevel.length();
} if (startOfContent > 0) {
final int positionOfClosingTag = line.length(); stringBuilder.append(tmp);
stringBuilder.append(HTML_OPEN_LIST_ELEMENT);
if (unorderedListLevel.length() > 0) { stringBuilder.append(line.substring(startOfContent).trim());
line = tmp stringBuilder.append(HTML_CLOSE_LIST_ELEMENT);
+ HTML_OPEN_LIST_ELEMENT
+ line.substring(positionOfOpeningTag, positionOfClosingTag)
+ HTML_CLOSE_LIST_ELEMENT;
} else { } else {
line = tmp + line.substring(positionOfOpeningTag, positionOfClosingTag); stringBuilder.append(tmp);
stringBuilder.append(line.substring(startOfContent).trim());
} }
ret = stringBuilder.toString();
} else {
ret = line;
}
if (ListType.ORDERED.equals(listType)) {
orderedListLevel = listLevel;
} else if (ListType.UNORDERED.equals(listType)) {
unorderedListLevel = listLevel;
} }
//end contrib [AS] } else {
ret = line;
} }
return line; return ret;
} }
//contributed by [MN] based on unordered list code by [AS]
/** /**
* Processes tags which are connected to definition lists. * Processes tags which are connected to definition lists.
* @param line line of text to be transformed from wiki code to HTML * @param line line of text to be transformed from wiki code to HTML
* @return HTML fragment * @return HTML fragment
*/ */
private String processDefinitionList(String line) { private String processDefinitionList(final String line) {
final String ret;
if (!noList) { //lists only get processed if not forbidden (see code for [= and <pre>). [MN] if (!noList) { //lists only get processed if not forbidden (see code for [= and <pre>). [MN]
if (line.startsWith(defListLevel + ";")) { //more semicolons if (line.startsWith(defListLevel + ";")) { //more semicolons
String definitionItem = EMPTY; final String copyOfLine = line.substring(defListLevel.length() + 1);
String definitionDescription = EMPTY;
final int positionOfOpeningTag; final int positionOfOpeningTag;
final int positionOfClosingTag = line.length();
final String copyOfLine = line.substring(defListLevel.length() + 1, positionOfClosingTag);
if ((positionOfOpeningTag = copyOfLine.indexOf(":")) > 0) { if ((positionOfOpeningTag = copyOfLine.indexOf(":")) > 0) {
definitionItem = copyOfLine.substring(0, positionOfOpeningTag); final String definitionItem = copyOfLine.substring(0, positionOfOpeningTag);
definitionDescription = copyOfLine.substring(positionOfOpeningTag + 1); final String definitionDescription = copyOfLine.substring(positionOfOpeningTag + 1);
line = HTML_OPEN_DEFINITION_LIST + final StringBuilder stringBuilder = new StringBuilder();
HTML_OPEN_DEFINITION_ITEM + stringBuilder.append(HTML_OPEN_DEFINITION_LIST);
definitionItem + stringBuilder.append(HTML_OPEN_DEFINITION_ITEM);
HTML_CLOSE_DEFINITION_ITEM + stringBuilder.append(definitionItem);
HTML_OPEN_DEFINITION_DESCRIPTION + stringBuilder.append(HTML_CLOSE_DEFINITION_ITEM);
definitionDescription; stringBuilder.append(HTML_OPEN_DEFINITION_DESCRIPTION);
stringBuilder.append(definitionDescription);
processingDefList = true; processingDefList = true;
ret = stringBuilder.toString();
} else {
ret = line;
} }
defListLevel += ";"; defListLevel += ";";
} else if (defListLevel.length() > 0 && line.startsWith(defListLevel)) { //equal number of semicolons } else if (defListLevel.length() > 0 && line.startsWith(defListLevel)) { //equal number of semicolons
String definitionItem = EMPTY; final String copyOfLine = line.substring(defListLevel.length());
String definitionDescription = EMPTY;
final int positionOfOpeningTag; final int positionOfOpeningTag;
final int positionOfClosingTag = line.length();
final String copyOfLine = line.substring(defListLevel.length(), positionOfClosingTag);
if ((positionOfOpeningTag = copyOfLine.indexOf(":")) > 0) { if ((positionOfOpeningTag = copyOfLine.indexOf(":")) > 0) {
definitionItem = copyOfLine.substring(0, positionOfOpeningTag); final String definitionItem = copyOfLine.substring(0, positionOfOpeningTag);
definitionDescription = copyOfLine.substring(positionOfOpeningTag + 1); final String definitionDescription = copyOfLine.substring(positionOfOpeningTag + 1);
line = HTML_OPEN_DEFINITION_ITEM + final StringBuilder stringBuilder = new StringBuilder();
definitionItem + stringBuilder.append(HTML_OPEN_DEFINITION_ITEM);
HTML_CLOSE_DEFINITION_ITEM + stringBuilder.append(definitionItem);
HTML_OPEN_DEFINITION_DESCRIPTION + stringBuilder.append(HTML_CLOSE_DEFINITION_ITEM);
definitionDescription; stringBuilder.append(HTML_OPEN_DEFINITION_DESCRIPTION);
stringBuilder.append(definitionDescription);
processingDefList = true; processingDefList = true;
ret = stringBuilder.toString();
} else {
ret = line;
} }
} else if (defListLevel.length() > 0) { //less semicolons } else if (defListLevel.length() > 0) { //less semicolons
String definitionItem = EMPTY;
String definitionDescription = EMPTY;
int i = defListLevel.length(); int i = defListLevel.length();
String tmp = EMPTY; String tmp = EMPTY;
while (!line.startsWith(defListLevel.substring(0, i))) { while (!line.startsWith(defListLevel.substring(0, i))) {
@ -440,26 +457,41 @@ public class wikiCode extends abstractWikiParser implements wikiParser {
} }
defListLevel = defListLevel.substring(0, i); defListLevel = defListLevel.substring(0, i);
int positionOfOpeningTag = defListLevel.length(); int positionOfOpeningTag = defListLevel.length();
final int positionOfClosingTag = line.length();
if (defListLevel.length() > 0) { if (defListLevel.length() > 0) {
final String copyOfLine = line.substring(positionOfOpeningTag, positionOfClosingTag); final String copyOfLine = line.substring(positionOfOpeningTag);
if ((positionOfOpeningTag = copyOfLine.indexOf(":")) > 0) { if ((positionOfOpeningTag = copyOfLine.indexOf(":")) > 0) {
definitionItem = copyOfLine.substring(0, positionOfOpeningTag); final String definitionItem = copyOfLine.substring(0, positionOfOpeningTag);
definitionDescription = copyOfLine.substring(positionOfOpeningTag + 1); final String definitionDescription = copyOfLine.substring(positionOfOpeningTag + 1);
line = tmp + HTML_OPEN_DEFINITION_ITEM + definitionItem + HTML_CLOSE_DEFINITION_ITEM + HTML_OPEN_DEFINITION_DESCRIPTION + definitionDescription; final StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(tmp);
stringBuilder.append(HTML_OPEN_DEFINITION_ITEM);
stringBuilder.append(definitionItem);
stringBuilder.append(HTML_CLOSE_DEFINITION_ITEM);
stringBuilder.append(HTML_OPEN_DEFINITION_DESCRIPTION);
stringBuilder.append(definitionDescription);
processingDefList = true; processingDefList = true;
ret = stringBuilder.toString();
} else {
ret = line;
} }
} else { } else {
line = tmp + line.substring(positionOfOpeningTag, positionOfClosingTag); final StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(tmp);
stringBuilder.append(line.substring(positionOfOpeningTag));
ret = stringBuilder.toString();
} }
} else {
ret = line;
} }
} else {
ret = line;
} }
return line; return ret;
} }
//contributed by [AS] except where stated otherwise
/** /**
* Processes tags which are connected to links and images. * Processes tags which are connected to links and images.
* @author [AS], [MN]
* @param line line of text to be transformed from wiki code to HTML * @param line line of text to be transformed from wiki code to HTML
* @return HTML fragment * @return HTML fragment
*/ */
@ -495,12 +527,12 @@ public class wikiCode extends abstractWikiParser implements wikiParser {
align = kv.substring(0, p); align = kv.substring(0, p);
//checking validity of value for align. Only non browser specific //checking validity of value for align. Only non browser specific
//values get supported. Not supported: absmiddle, baseline, texttop //values get supported. Not supported: absmiddle, baseline, texttop
if ((align.equals("bottom")) if (("bottom".equals(align))
|| (align.equals("center")) || ("center".equals(align))
|| (align.equals("left")) || ("left".equals(align))
|| (align.equals("middle")) || ("middle".equals(align))
|| (align.equals("right")) || ("right".equals(align))
|| (align.equals("top"))) { || ("top".equals(align))) {
align = " align=\"" + align + "\""; align = " align=\"" + align + "\"";
} else { } else {
align = EMPTY; align = EMPTY;
@ -526,7 +558,7 @@ public class wikiCode extends abstractWikiParser implements wikiParser {
// if it's no image, it might be an internal link // if it's no image, it might be an internal link
else { else {
if ((p = kl.indexOf(PIPE_ESCAPED)) > 0) { if ((p = kl.indexOf(PIPE_ESCAPED)) > 0) {
kv = kl.substring(p + 6); kv = kl.substring(p + LEN_PIPE_ESCAPED);
kl = kl.substring(0, p); kl = kl.substring(0, p);
} else { } else {
kv = kl; kv = kl;
@ -562,7 +594,6 @@ public class wikiCode extends abstractWikiParser implements wikiParser {
return line; return line;
} }
//contributed by [MN]
/** /**
* Processes tags which are connected preformatted text (&lt;pre&gt; &lt;/pre&gt;). * Processes tags which are connected preformatted text (&lt;pre&gt; &lt;/pre&gt;).
* @param line line of text to be transformed from wiki code to HTML * @param line line of text to be transformed from wiki code to HTML
@ -574,10 +605,13 @@ public class wikiCode extends abstractWikiParser implements wikiParser {
//both <pre> and </pre> in the same line //both <pre> and </pre> in the same line
if ((positionOfOpeningTag >= 0) && (positionOfClosingTag > 0) && !escaped) { if ((positionOfOpeningTag >= 0) && (positionOfClosingTag > 0) && !escaped) {
if (positionOfOpeningTag < positionOfClosingTag) { if (positionOfOpeningTag < positionOfClosingTag) {
String preformattedText = "<pre style=\"border:dotted;border-width:thin;\">" + line.substring(positionOfOpeningTag + LEN_WIKI_OPEN_PRE_ESCAPED, positionOfClosingTag) + "</pre>"; final StringBuilder preformattedText = new StringBuilder();
preformattedText = preformattedText.replaceAll("!pre!", "!pre!!"); preformattedText.append("<pre style=\"border:dotted;border-width:thin;\">");
preformattedText.append(line.substring(positionOfOpeningTag + LEN_WIKI_OPEN_PRE_ESCAPED, positionOfClosingTag));
preformattedText.append("</pre>");
line = processLineOfWikiCode(line.substring(0, positionOfOpeningTag).replaceAll("!pre!", "!pre!!") + "!pre!txt!" + line.substring(positionOfClosingTag + LEN_WIKI_CLOSE_PRE_ESCAPED).replaceAll("!pre!", "!pre!!")); line = processLineOfWikiCode(line.substring(0, positionOfOpeningTag).replaceAll("!pre!", "!pre!!") + "!pre!txt!" + line.substring(positionOfClosingTag + LEN_WIKI_CLOSE_PRE_ESCAPED).replaceAll("!pre!", "!pre!!"));
line = line.replaceAll("!pre!txt!", preformattedText); line = line.replaceAll("!pre!txt!", preformattedText.toString().replaceAll("!pre!", "!pre!!"));
line = line.replaceAll("!pre!!", "!pre!"); line = line.replaceAll("!pre!!", "!pre!");
} //handles cases like <pre><pre> </pre></pre> <pre> </pre> that would cause an exception otherwise } //handles cases like <pre><pre> </pre></pre> <pre> </pre> that would cause an exception otherwise
else { else {
@ -632,7 +666,6 @@ public class wikiCode extends abstractWikiParser implements wikiParser {
return line; return line;
} }
//method contributed by [MN]
/** Creates table of contents for a wiki page. /** Creates table of contents for a wiki page.
* @return HTML fragment * @return HTML fragment
*/ */
@ -675,7 +708,7 @@ public class wikiCode extends abstractWikiParser implements wikiParser {
doubles++; doubles++;
} }
} }
//if there are doubles, create anchorextension //if there are doubles, create anchor sextension
if (doubles > 0) { if (doubles > 0) {
anchorext = "_" + (doubles + 1); anchorext = "_" + (doubles + 1);
} }
@ -921,4 +954,4 @@ public class wikiCode extends abstractWikiParser implements wikiParser {
} }
return line; return line;
} }
} }

Loading…
Cancel
Save