[Gd-chatter] r11184 - trunk/libraries/network/wiki

hannes at gwydiondylan.org hannes at gwydiondylan.org
Sun Feb 18 05:16:34 CET 2007


Author: hannes
Date: Sun Feb 18 05:16:33 2007
New Revision: 11184

Modified:
   trunk/libraries/network/wiki/monday-parser.dylan
   trunk/libraries/network/wiki/parser-test.dylan
Log:
Job: minor
*bold, italic and bold-italic support

Modified: trunk/libraries/network/wiki/monday-parser.dylan
==============================================================================
--- trunk/libraries/network/wiki/monday-parser.dylan	(original)
+++ trunk/libraries/network/wiki/monday-parser.dylan	Sun Feb 18 05:16:33 2007
@@ -31,6 +31,9 @@
         semantic-value-function: count-chars;
       token TILDES = "(~)+",
         semantic-value-function: count-chars;
+      token TICKS = "(')+",
+        semantic-value-function: count-chars;
+
       token AMPERSAND = "&";
 
       token HASHMARK = "#";
@@ -82,14 +85,13 @@
 
      production header :: xml$<element> => [EQUALS more-wiki-text EQUALS], action:
        method (p :: <simple-parser>, data, s, e)
-         let left = p[0];
-         let right = p[2];
-         unless (left = right)
+         let heading = max(p[0], p[2]);
+         unless (p[0] = p[2])
            format-out("Unbalanced number of '=' in header %s, left: %d right: %d, using %d\n",
-                      p[1], left, right, max(left, right));
+                      p[1], p[0], p[2], heading);
          end;
          make(xml$<element>,
-              name: concatenate("h", integer-to-string(max(left, right))),
+              name: concatenate("h", integer-to-string(heading)),
               children: p[1]);
        end;
 
@@ -116,6 +118,26 @@
        format-out("Hit list-element %=\n", wiki-text);
        make(xml$<element>, name: "li", children: wiki-text);
 
+     production simple-format :: xml$<xml> => [TICKS TEXT TICKS], action:
+       method (p :: <simple-parser>, data, s, e)
+         let ticks = max(p[0], p[2]);
+         unless (p[0] = p[2])
+           format-out("Unbalanced number of ' in TICKS %s, left: %d right: %d, using %d\n",
+                      p[1], p[0], p[2], ticks);
+         end;
+         let str = list(make(xml$<char-string>, text: p[1]));
+         if (ticks = 5)
+           make(xml$<element>, name: "b", children: list(make(xml$<element>, name: "i", children: str)));
+         else
+           let ele-name = if (ticks = 2) "i" elseif (ticks = 3) "b" end;
+           if (ele-name)
+             make(xml$<element>, name: ele-name, children: str);
+           else
+             str[0]
+           end;
+         end;
+       end;
+
      production wiki-text :: <collection> => [TEXT more-wiki-text] (data)
        add!(more-wiki-text, with-xml() text(TEXT) end);
 
@@ -125,6 +147,9 @@
      production wiki-text :: <collection> => [external-link more-wiki-text] (data)
        add!(more-wiki-text, external-link);
 
+     production wiki-text :: <collection> => [simple-format more-wiki-text] (data)
+       add!(more-wiki-text, simple-format);
+
      production more-wiki-text :: <collection> => [wiki-text] (data)
        wiki-text;
 
@@ -135,10 +160,10 @@
        with-xml() hr end;
 
      production preformat :: xml$<element> => [PREFORMATTED TEXT more-preformat] (data)
+        let pre-string = concatenate("\n ", TEXT, more-preformat);
         make(xml$<element>,
              name: "pre",
-             children: list(make(xml$<char-string>,
-                                 text: concatenate("\n ", TEXT, more-preformat))));
+             children: list(make(xml$<char-string>, text: pre-string)));
 
      production more-preformat :: <string> => [TEXT more-preformat] (data)
        concatenate(" ", TEXT, more-preformat);

Modified: trunk/libraries/network/wiki/parser-test.dylan
==============================================================================
--- trunk/libraries/network/wiki/parser-test.dylan	(original)
+++ trunk/libraries/network/wiki/parser-test.dylan	Sun Feb 18 05:16:33 2007
@@ -80,6 +80,28 @@
 
 end;
 
+define test bold ()
+  check-equal("Bold text",
+              "<b>foo</b>",
+              *markup-method*("'''foo'''"));
+end;
+define test bold-italic ()
+  check-equal("Bold-italic text",
+              "<b><i>foo</i></b>",
+              *markup-method*("'''''foo'''''"));
+end;
+define test italic ()
+  check-equal("Italic text",
+              "<i>foo</i>",
+              *markup-method*("''foo''"));
+end;
+define test unknown-ticks ()
+  check-equal("Unknown ticks",
+              "foo",
+              *markup-method*("''''foo'''"));
+end;
+
+
 define suite parser-suite ()
   test newline;
   test internal-link;
@@ -96,6 +118,10 @@
   test horizontal-line;
   //test nowiki-markup;
   test pre-formatted;
+  test bold;
+  test italic;
+  test bold-italic;
+  test unknown-ticks;
 end;
 
 begin



More information about the chatter mailing list