Allow <br> for linebreaks.
[cocanwiki.git] / scripts / wikilib.ml
index 251311e..b366ae2 100644 (file)
@@ -1,7 +1,7 @@
 (* COCANWIKI - a wiki written in Objective CAML.
  * Written by Richard W.M. Jones <rich@merjis.com>.
  * Copyright (C) 2004 Merjis Ltd.
- * $Id: wikilib.ml,v 1.5 2004/09/16 18:06:31 rich Exp $
+ * $Id: wikilib.ml,v 1.8 2004/09/30 14:58:14 rich Exp $
  *
  * 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
@@ -42,8 +42,9 @@ let nontrivial_re = Pcre.regexp ~flags:[`CASELESS] "[a-z0-9]"
 
 let generate_url_of_title (dbh : Dbi.connection) hostid title =
   (* Create a suitable URL from this title. *)
-  let url = String.map (function '\000' .. ' ' | '<' | '>' | '&' | '"' -> '_'
-                         | c -> Char.lowercase c) title in
+  let url =
+    String.map (function '\000' .. ' ' | '<' | '>' | '&' | '"' | '+' -> '_'
+                 | c -> Char.lowercase c) title in
 
   (* Check URL is not too trivial. *)
   if not (Pcre.pmatch ~rex:nontrivial_re url) then
@@ -90,7 +91,7 @@ let obscure_mailto url =
 (* This matches any markup. *)
 let markup_re =
   let link = "\\[\\[\\s*(?:.+?)\\s*(?:\\|.+?\\s*)?\\]\\]" in
-  let tag = "</?(?:b|i|strong|em|code|sup|sub|nowiki)>" in
+  let tag = "</?(?:b|i|strong|em|code|sup|sub|nowiki|br)>" in
   Pcre.regexp ("(.*?)((?:" ^ link ^ ")|(?:" ^ tag ^ "))(.*)")
 
 (* This matches links only, and should be compatible with the link contained
@@ -320,6 +321,9 @@ let _markup_paragraph dbh hostid text =
           | FoundOpen (first, elem, rest) when elem = "nowiki" ->
               (* handle <nowiki> specially ... *)
               escape_html first :: loop (rest, elem :: [])
+          | FoundOpen (first, elem, rest) when elem = "br" ->
+              (* handle <br> specially ... *)
+              escape_html first :: "<br/>" :: loop (rest, [])
           | FoundOpen (first, elem, rest) ->
               (* open tag - push it onto the stack *)
               escape_html first :: "<" :: elem :: ">" :: loop (rest, [elem])
@@ -343,6 +347,9 @@ let _markup_paragraph dbh hostid text =
           | FoundOpen (first, elem, rest) when elem = "nowiki" ->
               (* handle <nowiki> specially ... *)
               escape_html first :: loop (rest, elem :: stack)
+          | FoundOpen (first, elem, rest) when elem = "br" ->
+              (* handle <br> specially ... *)
+              escape_html first :: "<br/>" :: loop (rest, stack)
           | FoundOpen (first, elem, rest) ->
               (* open tag - push it onto the stack *)
               escape_html first :: "<" :: elem :: ">" ::
@@ -413,6 +420,7 @@ let allowed_elements =
   let forms = [
     "form", [ "method"; "action"; "enctype" ];
     "input", [ "name"; "value"; "type"; "size"; "maxlength" ];
+    "textarea", [ "name"; "rows"; "cols" ];
   ] in
 
   let tables = [