// create toggle for wiki feature // document.writeln('
$1'); // paragraph //****** reinclude protected areas text = include_all(text); //*** insert info as html comment (version and so on) text = info.inject(text); textarea.value=text; } // return false; } /* replace words surrounded by wikitags with pm markup eg " *words* " -> " words " */ function around_words ( doc, monk_tag, wiki_tag, inner_re) { var empty = '(^|\\s|$)'; var marker = '(\\' + wiki_tag + ')'; var inner_grp = '(' + inner_re + ')'; var regex = new RegExp( empty + marker + inner_grp + marker + empty, 'g'); var pre_tag = '<' + monk_tag + '>'; var post_tag = '' + monk_tag + '>'; var substitute = '$1' + pre_tag + '$3' + post_tag + '$5'; // console.log(doc,regex,substitute); text=text.replace( regex, substitute); } function around_paragraph ( doc, monk_tag, wiki_tag, inner_re) { //stub } /* transform headlines (both ways) eg "^=== text" <->
text=text.replace(/
/g,'');
// no quote
text=text.replace(/(^|\n\n)(> )([^]*?)<\/I>(?=\n\n|$)/g,'$1> $3');
// revert around word markup
text=text.replace(/<\/?I>/g,'/');
text=text.replace(/<\/?B>/g,'*');
text=text.replace(/<\/?U>/g,'_');
// revert listitems
text=text.replace(/ $1'); // paragraph
//****** reinclude protected areas
text = include_all(text);
textarea.value=text;
}
}
/*
replace words surrounded by wikitags with pm markup
eg " *words* " -> " words "
*/
function around_words ( doc, monk_tag, wiki_tag, inner_re) {
var empty = '(^|\\s|$)';
var marker = '(\\' + wiki_tag + ')';
var inner_grp = '(' + inner_re + ')';
var regex = new RegExp( empty + marker + inner_grp + marker + empty, 'g');
var pre_tag = '<' + monk_tag + '>';
var post_tag = '' + monk_tag + '>';
var substitute = '$1' + pre_tag + '$3' + post_tag + '$5';
// console.log(doc,regex,substitute);
text=text.replace( regex, substitute);
}
function around_paragraph ( doc, monk_tag, wiki_tag, inner_re) {
//stub
}
/*
transform headlines (both ways)
eg "^=== text" <->
text=text.replace(/ /g,'');
// no quote
text=text.replace(/(^|\n\n)(> )([^]*?)<\/I>(?=\n\n|$)/g,'$1> $3');
// revert around word markup
text=text.replace(/<\/?I>/g,'/');
text=text.replace(/<\/?B>/g,'*');
text=text.replace(/<\/?U>/g,'_');
// revert listitems
text=text.replace(/..
text = heading(text,1);
// reinclude protected areas
text = include_all(text);
// revert ' (was protected)
text=text.replace(/<\/?C>/g,"'");
textarea.value=text;
}
}
function link_module(match, pre, name, post, offset, string) {
var core_modules = {
'B::Deparse' : 1,
};
var protokoll= core_modules[name] ? 'doc' : 'metamod';
return pre+'['+protokoll.toUpperCase()+'://'+name+']'+post;
}
(function (){
var DBG=false;
var counter=0;
// var matches = [];
var exclusions = [];
var delim="\0";
var delim0=delim+"<<";
var delim1=">>"+delim;
init_exclusions =function (text) {
exclusions = [];
counter=0;
text = exclude(text,new RegExp(delim+"+","g"),"delim");
return text;
}
exclude_all = function (text){
text = exclude(text,/<(c|code)>[^]*?<\/\1>/gi, "code" );
text = exclude(text,/<(blockquote)>[^]*?<\/\1>/gi, "blockquote" );
text = exclude(text,/<(pre)>[^]*?<\/\1>/gi, "pre" );
text = exclude(text,/\[(\w+):\/\/.*?\]/g, "link" );
// hide
##
// create toggle for wiki feature
document.writeln('
');
var textarea=get_textarea();
// obsolet
var allowed_nodes = {479:'perlquestion',480:'perlmeditation',1040:'monkdiscuss', 1597: 'obfuscated',1044:'CUFP'};
if ( textarea ) {
// activate wikifeature
document.forms.wiki.elements.on.checked=true;
// window.alert('wiki enabled!!!');
}
var text;
/*
expand wiki code to monk code with capital letters
*/
function wiki2monks () {
if ( textarea && document.forms.wiki.elements.on.checked) {
text=textarea.value;
// constants regex
var singleword = '\\S+' ;
var singleline = '\\S|\\S.*?\\S' ;
//******* protect special areas
text = init_exclusions(text);
text = exclude_all(text);
//******* Replace Inline Markup
//*** autolinks to modules, pragmas, cpan
text=text.replace(/(\s)(\w+::\w[\w:]*)(\s)/g,link_module);
//*** normalize newlines
text=text.replace(/\r\n/g,'\n'); // IE sucks!
//*** 'inline code' -> '...'
around_words('inline code', 'C', "'", singleline);
text = exclude_all(text); // protect new code areas
//*** ?documentation? -> [DOC://...]
text=text.replace(/(\s)\?(\S+)\?(\s)/g,'$1[DOC://$2|$2]$3');
text = exclude_all(text); // protect new doc areas
//*** emphasizer * / _ ->
around_words('bold', 'B', '*', singleword);
around_words('italic', 'I', '/', singleword);
around_words('underline', 'U', '_', singleword);
//****** complete lines (markup at start of line)
//*** > quotes -> > ...
text=text.replace(/(^|\n\n)(> )([^]*?)(?=\n\n|$)/g,'$1> $3'); // quote
//*** \n=== headlines -> ...
text = heading(text);
//*** - list items -> $2\n<\/UL\>\n'); // bullets unordered
text=text.replace(/(\n)(\n\+\s+[^]*?)(\n\n)/g,'$1
$2\n<\/OL\>\n'); // bullets ordered
text=text.replace(/^(\-|\+)(\s+.*?)$/gm,'
text
*/
function heading (text,revert) {
var maps =[
['===', 'H5'],
['==' , 'H4'],
['=' , 'H3'],
];
if (revert) {
for (var i=maps.length-1; i>=0 ;i--) {
var map=maps[i];
var tag0 = new RegExp( '<'+ map[1] + '>','g');
text=text.replace(tag0,map[0]);
var tag1 = new RegExp( ''+ map[1] + '>','g');
text=text.replace(tag1,'');
}
} else {
for (var i=0; i..
text = heading(text,1);
// reinclude protected areas
text = include_all(text);
// revert ' (was protected)
text=text.replace(/<\/?C>/g,"'");
textarea.value=text;
}
}
function link_module(match, pre, name, post, offset, string) {
var core_modules = {
'B::Deparse' : 1,
};
var protokoll= core_modules[name] ? 'doc' : 'metamod';
return pre+'['+protokoll.toUpperCase()+'://'+name+']'+post;
}
(function (){
var DBG=false;
var counter=0;
// var matches = [];
var exclusions = [];
var delim="\0";
var delim0=delim+"<<";
var delim1=">>"+delim;
init_exclusions =function (text) {
exclusions = [];
counter=0;
text = exclude(text,new RegExp(delim+"+","g"),"delim");
return text;
}
exclude_all = function (text){
text = exclude(text,/<(c|code)>[^]*?<\/\1>/g,"code");
text = exclude(text,/\[(\w+):\/\/.*?\]/g,"link");
text = exclude(text,/
##
no
paragraph
(no separating empty line)
auto paragraph after 2 newlines
= headline 1
== headline 2
=== Headline 3
*bold* /italic/ _underlined_
> paragraph with cited text
'inline code'
?doclink?
Module::Name