diff --git a/modules/wiky.css b/modules/wiky.css new file mode 100755 index 0000000..062f34e --- /dev/null +++ b/modules/wiky.css @@ -0,0 +1,15 @@ +/* == wiky == */ +*.wiki blockquote { background:#ddd; border:solid 1px #999; margin-left:1em; padding:0.5em;} +*.wiki table { + border-collapse: collapse; + empty-cells: show; +} + +*.wiki table td { + border: solid 1px black; + padding: 0.25em 0.5em 0.25em 0.5em; + text-align: center; +} + +/*pre { font-size:100%; background: #eed; border:1px dotted #999; padding:0 0.5em; overflow:auto; }*/ +pre { font-family:courier new, monospace; overflow:auto; } diff --git a/modules/wiky.js b/modules/wiky.js new file mode 100755 index 0000000..71e46ff --- /dev/null +++ b/modules/wiky.js @@ -0,0 +1,373 @@ +/* This work is licensed under Creative Commons GNU LGPL License. + + License: http://creativecommons.org/licenses/LGPL/2.1/ + + Author: Stefan Goessner/2005-06 + Web: http://goessner.net/ +*/ +var Wiky = { + version: 0.95, + blocks: null, + rules: { + all: [ + "Wiky.rules.pre", + "Wiky.rules.nonwikiblocks", + "Wiky.rules.wikiblocks", + "Wiky.rules.post", + ], + pre: [ + { rex:/(\r?\n)/g, tmplt:"\xB6" }, // replace line breaks with '¶' .. + ], + post: [ + { rex:/(^\xB6)|(\xB6$)/g, tmplt:"" }, // .. remove linebreaks at BOS and EOS .. + { rex:/@([0-9]+)@/g, tmplt:function($0,$1){return Wiky.restore($1);} }, // resolve blocks .. + { rex:/\xB6/g, tmplt:"\n" } // replace '¶' with line breaks .. + ], + nonwikiblocks: [ + { rex:/\\([%])/g, tmplt:function($0,$1){return Wiky.store($1);} }, + { rex:/\[(?:\{([^}]*)\})?(?:\(([^)]*)\))?%(.*?)%\]/g, tmplt:function($0,$1,$2,$3){return ":p]"+Wiky.store("" + Wiky.apply($3, $2?Wiky.rules.lang[Wiky.attr($2)]:Wiky.rules.code) + "")+"[p:";} } //programm code block + ], + wikiblocks: [ + "Wiky.rules.nonwikiinlines", + "Wiky.rules.escapes", + { rex:/(?:^|\xB6)(={1,6})(.*?)[=]*(?=\xB6|$)/g, tmplt:function($0,$1,$2){ var h=$1.length; return ":p]\xB6"+$2+"\xB6[p:";} }, //

..

+ { rex:/(?:^|\xB6)[-]{4}(?:\xB6|$)/g, tmplt:"\xB6
\xB6" }, // horizontal ruler .. + { rex:/\\\\([ \xB6])/g, tmplt:"
$1" }, // forced line break .. + { rex:/(^|\xB6)([*01aAiIg]*[\.*])[ ]/g, tmplt:function($0,$1,$2){var state=$2.replace(/([*])/g,"u").replace(/([\.])/,"");return ":"+state+"]"+$1+"["+state+":";}}, + { rex:/(?:^|\xB6);[ ](.*?):[ ]/g, tmplt:"\xB6:l][l:$1:d][d:"}, // ; term : definition + { rex:/\[(?:\{([^}]*)\})?(?:\(([^)]*)\))?\"/g, tmplt:function($0,$1,$2){return ":p][p:"; } }, // block quotation start + { rex:/\"\]/g, tmplt:":p][p:" }, // block quotation end + { rex:/\[(\{[^}]*\})?\|/g, tmplt:":t]$1[r:" }, // .. start table .. + { rex:/\|\]/g, tmplt:":r][t:" }, // .. end table .. + { rex:/\|\xB6[ ]?\|/g, tmplt:":r]\xB6[r:" }, // .. end/start table row .. + { rex:/\|/g, tmplt:":c][c:" }, // .. end/start table cell .. + { rex:/^(.*)$/g, tmplt:"[p:$1:p]" }, // start paragraph '[p:' at BOS .. end paragraph ':p]' at EOS .. + { rex:/(([\xB6])([ \t\f\v\xB6]*?)){2,}/g, tmplt:":p]$1[p:" }, // .. separate paragraphs at blank lines .. + { rex:/\[([01AIacdgilprtu]+)[:](.*?)[:]([01AIacdgilprtu]+)\]/g, tmplt:function($0,$1,$2,$3){return Wiky.sectionRule($1==undefined?"":$1,"",Wiky.apply($2,Wiky.rules.wikiinlines),!$3?"":$3);} }, + { rex:/\[[01AIacdgilprtu]+[:]|[:][01AIacdgilprtu]+\]/g, tmplt:"" }, // .. remove singular section delimiters (they frequently exist with incomplete documents while typing) .. + { rex:/(?:([0-9]*)[>])?([ ]?)(.*?)([ ]?)<\/td>/g, tmplt:function($0,$1,$2,$3,$4){return ""+$2+$3+$4+"";} }, + { rex:/<(p|table)>(?:\xB6)?(?:\{(.*?)\})/g, tmplt:function($0,$1,$2){return "<"+$1+Wiky.style($2)+">";} }, + { rex:/

([ \t\f\v\xB6]*?)<\/p>/g, tmplt:"$1" }, // .. remove empty paragraphs .. + "Wiky.rules.shortcuts" + ], + nonwikiinlines: [ + { rex:/%(?:\{([^}]*)\})?(?:\(([^)]*)\))?(.*?)%/g, tmplt:function($0,$1,$2,$3){return Wiky.store("" + Wiky.apply($3, $2?Wiky.rules.lang[Wiky.attr($2)]:Wiky.rules.code) + "");} }, // inline code + { rex:/%(.*?)%/g, tmplt:function($0,$1){return Wiky.store("" + Wiky.apply($2, Wiky.rules.code) + "");} } + ], + wikiinlines: [ + { rex:/\*([^*]+)\*/g, tmplt:"$1" }, // .. strong .. + { rex:/_([^_]+)_/g, tmplt:"$1" }, + { rex:/\^([^^]+)\^/g, tmplt:"$1" }, + { rex:/~([^~]+)~/g, tmplt:"$1" }, + { rex:/\(-(.+?)-\)/g, tmplt:"$1" }, + { rex:/\?([^ \t\f\v\xB6]+)\((.+)\)\?/g, tmplt:"$1" }, // .. abbreviation .. + { rex:/\[(?:\{([^}]*)\})?[Ii]ma?ge?\:([^ ,\]]*)(?:[, ]([^\]]*))?\]/g, tmplt:function($0,$1,$2,$3){return Wiky.store("");} }, // wikimedia image style .. + { rex:/\[([^ ,]+)[, ]([^\]]*)\]/g, tmplt:function($0,$1,$2){return Wiky.store(""+$2+"");}}, // wiki block style uri's .. + { rex:/(((http(s?))\:\/\/)?[A-Za-z0-9\._\/~\-:]+\.(?:png|jpg|jpeg|gif|bmp))/g, tmplt:function($0,$1,$2){return Wiky.store("\""+$1+"\"/");} }, // simple images .. + { rex:/((mailto\:|javascript\:|(news|file|(ht|f)tp(s?))\:\/\/)[A-Za-z0-9\.:_\/~%\-+&#?!=()@\x80-\xB5\xB7\xFF]+)/g, tmplt:"$1" } // simple uri's .. + ], + escapes: [ + { rex:/\\([|*_~\^])/g, tmplt:function($0,$1){return Wiky.store($1);} }, + { rex:/\\&/g, tmplt:"&" }, + { rex:/\\>/g, tmplt:">" }, + { rex:/\\/g, tmplt:"↔"}, // $harr; + { rex:/<-/g, tmplt:"←"}, // ← + { rex:/->/g, tmplt:"→"}, //→ + ], + code: [ + { rex:/&/g, tmplt:"&"}, + { rex://g, tmplt:">"} + ], + lang: {} + }, + + inverse: { + all: [ + "Wiky.inverse.pre", + "Wiky.inverse.nonwikiblocks", + "Wiky.inverse.wikiblocks", + "Wiky.inverse.post" + ], + pre: [ + { rex:/(\r?\n)/g, tmplt:"\xB6" } // replace line breaks with '¶' .. + ], + post: [ + { rex:/@([0-9]+)@/g, tmplt:function($0,$1){return Wiky.restore($1);} }, // resolve blocks .. + { rex:/\xB6/g, tmplt:"\n" } // replace '¶' with line breaks .. + ], + nonwikiblocks: [ + { rex:/]*)>(.*?)<\/pre>/mgi, tmplt:function($0,$1,$2){return Wiky.store("["+Wiky.invStyle($1)+Wiky.invAttr($1,["lang"]).replace(/x\-/,"")+"%"+Wiky.apply($2, Wiky.hasAttr($1,"lang")?Wiky.inverse.lang[Wiky.attrVal($1,"lang").substr(2)]:Wiky.inverse.code)+"%]");} } //code block + ], + wikiblocks: [ + "Wiky.inverse.nonwikiinlines", + "Wiky.inverse.escapes", + "Wiky.inverse.wikiinlines", + { rex:/

(.*?)<\/h1>/mgi, tmplt:"=$1=" }, + { rex:/

(.*?)<\/h2>/mgi, tmplt:"==$1==" }, + { rex:/

(.*?)<\/h3>/mgi, tmplt:"===$1===" }, + { rex:/

(.*?)<\/h4>/mgi, tmplt:"====$1====" }, + { rex:/

(.*?)<\/h5>/mgi, tmplt:"=====$1=====" }, + { rex:/
(.*?)<\/h6>/mgi, tmplt:"======$1======" }, + { rex:/<(p|table)[^>]+(style=\"[^\"]*\")[^>]*>/mgi, tmplt:function($0,$1,$2){return "<"+$1+">"+Wiky.invStyle($2);} }, + { rex:/\xB6{2}
  • \"]*)\"?[^>]*?>([^<]*)/mgi, tmplt:function($0,$1,$2){return $1.replace(/u/g,"*").replace(/([01aAiIg])$/,"$1.")+" "+$2;}}, // list items .. + { rex:/(^|\xB6)<(u|o)l[^>]*?>\xB6/mgi, tmplt:"$1" }, // only outer level list start at BOL ... + { rex:/(<\/(?:dl|ol|ul|p)>[ \xB6]*<(?:p)>)/gi, tmplt:"\xB6\xB6" }, + { rex:/
    (.*?)<\/dt>[ \f\n\r\t\v]*
    /mgi, tmplt:"; $1: " }, + { rex:/]*)>/mgi, tmplt:function($0,$1){return Wiky.store("["+Wiky.invStyle($1)+Wiky.invAttr($1,["cite","title"])+"\"");} }, + { rex:/<\/blockquote>/mgi, tmplt:"\"]" }, + { rex:/\xB6*[ ]?|<\/tr>/mgi, tmplt:"|" }, // ie6 only .. + { rex:/\xB6]*?)>/mgi, tmplt:"\xB6" }, + { rex:/]*?)>/mgi, tmplt:"|$1>" }, + { rex:/]*?)>/mgi, tmplt:"|" }, + { rex://mgi, tmplt:"[" }, + { rex:/<\/table>/mgi, tmplt:"]" }, + { rex:/]*?)>\xB6*|<\/td>\xB6*|\xB6*|<\/tbody>/mgi, tmplt:"" }, + { rex://mgi, tmplt:"----" }, + { rex://mgi, tmplt:"\\\\" }, + { rex:/(

    |<(d|o|u)l[^>]*>|<\/(dl|ol|ul|p)>|<\/(li|dd)>)/mgi, tmplt:"" }, + "Wiky.inverse.shortcuts" + ], + nonwikiinlines: [ + { rex:/(.*?)<\/code>/g, tmplt:function($0,$1){return Wiky.store("%"+Wiky.apply($1, Wiky.inverse["code"])+"%");} } + ], + wikiinlines: [ + { rex:/]*?>(.*?)<\/strong>/mgi, tmplt:"*$1*" }, + { rex:/]*?>(.*?)<\/b>/mgi, tmplt:"*$1*" }, + { rex:/]*?>(.*?)<\/em>/mgi, tmplt:"_$1_" }, + { rex:/]*?>(.*?)<\/i>/mgi, tmplt:"_$1_" }, + { rex:/]*?>(.*?)<\/sup>/mgi, tmplt:"^$1^" }, + { rex:/]*?>(.*?)<\/sub>/mgi, tmplt:"~$1~" }, + { rex:/]*?>(.*?)<\/del>/mgi, tmplt:"(-$1-)" }, + { rex:/(.*?)<\/abbr>/mgi, tmplt:"?$2($1)?" }, + { rex:/]*?>(.*?)<\/a>/mgi, tmplt:function($0,$1,$2){return $1==$2?$1:"["+$1+","+$2+"]";}}, + { rex:/]*)\/>/mgi, tmplt:function($0,$1){var a=Wiky.attrVal($1,"alt"),h=Wiky.attrVal($1,"src"),t=Wiky.attrVal($1,"title"),s=Wiky.attrVal($1,"style");return s||(t&&h!=t)?("["+Wiky.invStyle($1)+"img:"+h+(t&&(","+t))+"]"):h;}}, + ], + escapes: [ + { rex:/([|*_~%\^])/g, tmplt:"\\$1" }, + { rex:/&/g, tmplt:"\\&" }, + { rex:/>/g, tmplt:"\\>" }, + { rex:/</g, tmplt:"\\<" } + ], + shortcuts: [ + { rex:/–|\u2013/g, tmplt:"--"}, + { rex:/—|\u2014/g, tmplt:"---"}, + { rex:/…|\u2026/g, tmplt:"..."}, + { rex:/↔|\u2194/g, tmplt:"<->"}, + { rex:/←|\u2190/g, tmplt:"<-"}, + { rex:/→|\u2192/g, tmplt:"->"} + ], + code: [ + { rex:/&/g, tmplt:"&"}, + { rex:/</g, tmplt:"<"}, + { rex:/>/g, tmplt:">"} + ], + lang: {} + }, + + toHtml: function(str) { + Wiky.blocks = []; + return Wiky.apply(str, Wiky.rules.all); + }, + + toWiki: function(str) { + Wiky.blocks = []; + return Wiky.apply(str, Wiky.inverse.all); + }, + + apply: function(str, rules) { + if (str && rules) + for (var i in rules) { + if (typeof(rules[i]) == "string") + str = Wiky.apply(str, eval(rules[i])); + else + str = str.replace(rules[i].rex, rules[i].tmplt); + } + return str; + }, + store: function(str, unresolved) { + return unresolved ? "@" + (Wiky.blocks.push(str)-1) + "@" + : "@" + (Wiky.blocks.push(str.replace(/@([0-9]+)@/g, function($0,$1){return Wiky.restore($1);}))-1) + "@"; + }, + restore: function(idx) { + return Wiky.blocks[idx]; + }, + attr: function(str, name, idx) { + var a = str && str.split(",")[idx||0]; + return a ? (name ? (" "+name+"=\""+a+"\"") : a) : ""; + }, + hasAttr: function(str, name) { + return new RegExp(name+"=").test(str); + }, + attrVal: function(str, name) { + return str.replace(new RegExp("^.*?"+name+"=\"(.*?)\".*?$"), "$1"); + }, + invAttr: function(str, names) { + var a=[], x; + for (var i in names) + if (str.indexOf(names[i]+"=")>=0) + a.push(str.replace(new RegExp("^.*?"+names[i]+"=\"(.*?)\".*?$"), "$1")); + return a.length ? ("("+a.join(",")+")") : ""; + }, + style: function(str) { + var s = str && str.split(/,|;/), p, style = ""; + for (var i in s) { + p = s[i].split(":"); + if (p[0] == ">") style += "margin-left:4em;"; + else if (p[0] == "<") style += "margin-right:4em;"; + else if (p[0] == ">>") style += "float:right;"; + else if (p[0] == "<<") style += "float:left;"; + else if (p[0] == "=") style += "display:block;margin:0 auto;"; + else if (p[0] == "_") style += "text-decoration:underline;"; + else if (p[0] == "b") style += "border:solid 1px;"; + else if (p[0] == "c") style += "color:"+p[1]+";"; + else if (p[0] == "C") style += "background:"+p[1]+";"; + else if (p[0] == "w") style += "width:"+p[1]+";"; + else style += p[0]+":"+p[1]+";"; + } + return style ? " style=\""+style+"\"" : ""; + }, + invStyle: function(str) { + var s = /style=/.test(str) ? str.replace(/^.*?style=\"(.*?)\".*?$/, "$1") : "", + p = s && s.split(";"), pi, prop = []; + for (var i in p) { + pi = p[i].split(":"); + if (pi[0] == "margin-left" && pi[1]=="4em") prop.push(">"); + else if (pi[0] == "margin-right" && pi[1]=="4em") prop.push("<"); + else if (pi[0] == "float" && pi[1]=="right") prop.push(">>"); + else if (pi[0] == "float" && pi[1]=="left") prop.push("<<"); + else if (pi[0] == "margin" && pi[1]=="0 auto") prop.push("="); + else if (pi[0] == "display" && pi[1]=="block") ; + else if (pi[0] == "text-decoration" && pi[1]=="underline") prop.push("_"); + else if (pi[0] == "border" && pi[1]=="solid 1px") prop.push("b"); + else if (pi[0] == "color") prop.push("c:"+pi[1]); + else if (pi[0] == "background") prop.push("C:"+pi[1]); + else if (pi[0] == "width") prop.push("w:"+pi[1]); + else if (pi[0]) prop.push(pi[0]+":"+pi[1]); + } + return prop.length ? ("{" + prop.join(",") + "}") : ""; + }, + sectionRule: function(fromLevel, style, content, toLevel) { + var trf = { p_p: "

    $1

    ", + p_u: "

    $1

    ", + p_o: "

    $1

    ", + // p - ul + // ul - p + u_p: "$1", + u_c: "$1", + u_r: "$1", + uu_p: "$1", + uo_p: "$1", + uuu_p: "$1", + uou_p: "$1", + uuo_p: "$1", + uoo_p: "$1", + // ul - ul + u_u: "$1", + uu_u: "$1", + uo_u: "$1", + uuu_u: "$1", + uou_u: "$1", + uuo_u: "$1", + uoo_u: "$1", + u_uu: "$1", + // ul - ol + u_o: "$1", + uu_o: "$1", + uo_o: "$1", + uuu_o: "$1", + uou_o: "$1", + uuo_o: "$1", + uoo_o: "$1", + u_uo: "$1", + // ol - p + o_p: "$1", + oo_p: "$1", + ou_p: "$1", + ooo_p: "$1", + ouo_p: "$1", + oou_p: "$1", + ouu_p: "$1", + // ol - ul + o_u: "$1", + oo_u: "$1", + ou_u: "$1", + ooo_u: "$1", + ouo_u: "$1", + oou_u: "$1", + ouu_u: "$1", + o_ou: "$1", + // -- ol - ol -- + o_o: "$1", + oo_o: "$1", + ou_o: "$1", + ooo_o: "$1", + ouo_o: "$1", + oou_o: "$1", + ouu_o: "$1", + o_oo: "$1", + // -- dl -- + l_d: "
    $1
    ", + d_l: "
    $1
    ", + d_u: "
    $1
      ", + d_o: "
      $1
        ", + p_l: "

        $1

        ", + u_l: "$1
    ", + o_l: "$1
    ", + uu_l: "$1
    ", + uo_l: "$1
    ", + ou_l: "$1
    ", + oo_l: "$1
    ", + d_p: "
    $1
    ", + // -- table -- + p_t: "

    $1

    ", + p_r: "

    $1

    ", + p_c: "

    $1

    ", + t_p: "

    $1

    ", + r_r: "$1", + r_p: "

    $1

    ", + r_c: "$1", + r_u: "$1