preliminary experiments with a wiki tag
authoradam <adam@megacz.com>
Fri, 25 Mar 2005 06:29:20 +0000 (06:29 +0000)
committeradam <adam@megacz.com>
Fri, 25 Mar 2005 06:29:20 +0000 (06:29 +0000)
darcs-hash:20050325062920-5007d-2a06b1410d305dbcccb2ca1820f071afafdf099c.gz

src/org/ibex/xt/Form.java
src/org/ibex/xt/Template.java

index c315f92..3d71d79 100644 (file)
@@ -49,6 +49,9 @@ public abstract class Form extends HttpServlet {
         System.out.println(sample.emit());
     }
 
         System.out.println(sample.emit());
     }
 
+    //public void sendRedirect(HttpServletResponse response) throws IOException {
+    //response.sendRedirect(uri);
+    //}
     public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException { doGet(request, response); }
     public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
         Field[] fields = this.getClass().getFields();
     public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException { doGet(request, response); }
     public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
         Field[] fields = this.getClass().getFields();
index f8c4e8d..36611cc 100644 (file)
@@ -109,6 +109,7 @@ public class Template extends Node.Stream.Filter implements Node.Stream.Functor
                 transform(n, scope);
                 return graft((Node.Stream.Functor)("true".equals(n.attr("if"))?new DropTag():new DropAll()), n).upstreamRead(n);
             case "js":       return graft(new JsTag(scope), n).upstreamRead(n);
                 transform(n, scope);
                 return graft((Node.Stream.Functor)("true".equals(n.attr("if"))?new DropTag():new DropAll()), n).upstreamRead(n);
             case "js":       return graft(new JsTag(scope), n).upstreamRead(n);
+            case "wiki":     return graft(new WikiTag(n, scope), n).upstreamRead(n);
             case "foreach":  return graft(new ForEach(n, scope), n).upstreamRead(n);
             case "children":
                 if (children == null) return true;
             case "foreach":  return graft(new ForEach(n, scope), n).upstreamRead(n);
             case "children":
                 if (children == null) return true;
@@ -164,6 +165,28 @@ public class Template extends Node.Stream.Filter implements Node.Stream.Functor
         }
     }
 
         }
     }
 
+    private class WikiTag implements Node.Stream.Functor {
+        public WikiTag(Node n, Scope s) { }
+        public Node.Stream wrap(final Node.Stream kids) {
+            return new Node.Stream() {
+                    public boolean _read(Node n) {
+                        if (!kids.read(n)) return false;
+                        System.out.println("kids.cdata == " + n.cdata);
+                        if (n.cdata == null) return true;
+
+                        // FIXME: links, code, and math
+                        n.cdata = n.cdata.replaceAll("__([^_]+)__", "<u>$1</u>");
+                        n.cdata = n.cdata.replaceAll("\\~\\~([^\\~]+)\\~\\~", "<i>$1</i>");
+                        n.cdata = n.cdata.replaceAll("\\*\\*([^\\*]+)\\*\\*", "<b>$1</b>");
+                        n.cdata = n.cdata.replaceAll("==([^=]+)==", "<h2>$1</h2>");
+                        n.cdata = n.cdata.replaceAll("=<h2>([^=]+)</h2>=", "<h3>$1</h3>");
+                        n.cdata = n.cdata.replaceAll("=<h3>([^=]+)</h3>=", "<h4>$1</h4>");
+                        n.cdata = n.cdata.replaceAll("(\n|\r\n)[ ]*(\n|\r\n)", "\n<br/><br/>\n");
+                        return true;
+                    } };
+        }
+    }
+
     private class InputTag implements Node.Stream.Functor {
         final String fieldName;
         public InputTag(String fieldName) { this.fieldName = fieldName; }
     private class InputTag implements Node.Stream.Functor {
         final String fieldName;
         public InputTag(String fieldName) { this.fieldName = fieldName; }