From d40ccc5208a4afede2713473b721bb6ba08a50ce Mon Sep 17 00:00:00 2001 From: low012 Date: Sun, 7 May 2006 22:53:17 +0000 Subject: [PATCH] *) Partly undoing last commit\n*) Fixed bug that caused attributes of cells in tables not to be recognized as such. git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@2066 6c8d7289-2bf4-0310-a012-ef5d649a1542 --- source/de/anomic/data/wikiCode.java | 65 +++++++++++++++++++---------- 1 file changed, 42 insertions(+), 23 deletions(-) diff --git a/source/de/anomic/data/wikiCode.java b/source/de/anomic/data/wikiCode.java index 33e8d39b7..7e34669ee 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: 17.04.2006 +// last major change: 08.05.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 @@ -188,11 +188,13 @@ public class wikiCode { //patterns that will be replaced. To add new codes or patterns, just put them at the end //of the list. Codes or patterns in this list can not be escaped with [= or
     public static String[] characters={
-        "\u005E","^",
+        "\u005E","^",  // Caret
 
-        "\u0060","`",
-
-        "\u007E","~",
+        "\u0060","`",  // Accent Grave `
+        "\u007B","{",  // {
+        "\u007C","|",  // |
+        "\u007D","}",  // }
+        "\u007E","~",  // ~
 
         "\u0082","‚",
         "\u0083","ƒ",
@@ -328,18 +330,29 @@ public class wikiCode {
       */
       //[FB], changes by [MN]
     private String processTable(String result, plasmaSwitchboard switchboard){
-        String line="";
-        if ((result.startsWith("{|")) && (!table)) {
+        //some variables that make it easier to change codes for the table
+        String line = "";
+        String tableStart = "{|";                 // {|
+        String newLine = "|-";                         // |-
+        String cellDivider = "||";                // ||
+        String tableEnd = "|}";                   // |}
+        String attribDivider = "|";                    // |
+        int lenTableStart = tableStart.length();
+        int lenCellDivider = cellDivider.length();
+        int lenTableEnd = tableEnd.length();
+        int lenAttribDivider = attribDivider.length();
+
+        if ((result.startsWith(tableStart)) && (!table)) {
             table=true;
             newrowstart=true;
             line="2) {
-                line+=parseTableProperties(result.substring(2).trim());
+            if (result.trim().length()>lenTableStart) {
+                line+=parseTableProperties(result.substring(lenTableStart).trim());
             }
             line+=">";
             result=line;
         }
-        else if (result.startsWith("|-") && (table)) {          // new row
+        else if (result.startsWith(newLine) && (table)) {          // new row
             if (!newrowstart) {
                 line+="\t\n";
             } else {
@@ -348,36 +361,42 @@ public class wikiCode {
             line=line+"\t";
             result=line;
         }
-        else if ((result.startsWith("||")) && (table)) {
+        else if ((result.startsWith(cellDivider)) && (table)) {
             line+="\t\t0)?(result.indexOf("||",2)):(result.length());
-            int propEnd = 0;
+            int cellEnd=(result.indexOf(cellDivider,lenCellDivider)>0)?(result.indexOf(cellDivider,lenCellDivider)):(result.length());
+            int propEnd = result.indexOf(attribDivider,lenCellDivider);
+            int occImage = result.indexOf("[[Image:",lenCellDivider);
+            int occEscape = result.indexOf("[=",lenCellDivider);
             //If resultOf("[[Image:") is less than propEnd, that means that there is no
             //property for this cell, only an image. Without this, YaCy could get confused
             //by a | in [[Image:picture.png|alt-text]] or [[Image:picture.png|alt-text]]
-            if(((propEnd = result.indexOf("|",2)) > 0)&&(!(result.indexOf("[[Image:",2) < propEnd))){
-                propEnd = result.indexOf("|",2);
+            //Same for [= (part of [= =])
+            if((propEnd > lenCellDivider)
+            &&((occImage > propEnd)||( occImage < 0))
+            &&((occEscape> propEnd)||( occEscape < 0))
+            ){
+                propEnd = result.indexOf(attribDivider,lenCellDivider)+lenAttribDivider;
             }
             else {
                 propEnd = cellEnd;
             }
             // both point at same place => new line
             if (propEnd==cellEnd) {
-                propEnd=1;
+                propEnd=lenCellDivider;
             } else {
-                line+=parseTableProperties(result.substring(2,propEnd).trim());
+                line+=parseTableProperties(result.substring(lenCellDivider,propEnd-lenAttribDivider).trim());
             }
             table=false; cellprocessing=true;
-            line+=">"+processTable(result.substring(propEnd+1,cellEnd).trim(), switchboard)+"";
+            line+=">"+processTable(result.substring(propEnd,cellEnd).trim(), switchboard)+"";
             table=true; cellprocessing=false;
             if (cellEnd 0) {
+                if ((p = kl.indexOf("|")) > 0) {
                     kv = kl.substring(p + 1);
                     kl = kl.substring(0, p);
                     // if there are 2 arguments, write them into ALIGN and ALT
-                    if ((p = kv.indexOf("|")) > 0) {
+                    if ((p = kv.indexOf("|")) > 0) {
                         align = kv.substring(0, p);
                         //checking validity of value for align. Only non browser specific
                         //values get supported. Not supported: absmiddle, baseline, texttop
@@ -710,7 +729,7 @@ public class wikiCode {
 
             // if it's no image, it might be an internal link
             else {
-                if ((p = kl.indexOf("|")) > 0) {
+                if ((p = kl.indexOf("|")) > 0) {
                     kv = kl.substring(p + 1);
                     kl = kl.substring(0, p);
                 } else {