Code Contribution Program #2
⏎ Return to Code Contribution Project
This code has not yet been used, but might be implemented sometime in the future.
Code author: James Kanjo
Attribution text: James Kanjo
Programming language: JavaScript
Description:
This is a JavaScript function that converts Wikidot Syntax into it's HTML equivalent.
For example:
alert(WikidotToHTML('**STE**'));
Will return:
<p><strong>STE</strong></p>
If you use its optional “attributes” tag, it will generate more accurate HTML based on the page's metadata. Attributes are:
- site: http://whatever.com;
- fullname: category:name;
- tags: tag1,tag2,tag3;
As the attributes are read as a string, you need to surround the attributes with quotations. For example:
WikidotToHTML(wiki-syntax,'site: http://james.wikidot.com; fullname: blog:74;');
First submitted: 1307699628|%O ago, %e %B %Y
Last updated: 1309595396|%O ago, %e %B %Y
function WikidotToHTML(body,attributes) { <!-- Wikidot Syntax to HTML Converter --> <!-- © James Kanjo 2011 --> <!-- Revision 575 --> <!-- Establish Page Attributes --> var str_fullname = 'fullname'; if (/fullname *: *([^; ]((?! *;).)*) *;/.test(attributes)) { str_fullname = /fullname *: *([^; ]((?! *;).)*) *;/i.exec(attributes)[1];} var str_site = 'http:�parsed2slash�www.wikidot.com'; if (/site *: *([^; ]((?! *;).)*) *;/.test(attributes)) { str_site = /site *: *([^; ]((?! *;).)*) *;/i.exec(attributes)[1].replace(/([^:\* \[]+):\/\//gi,'$1:�parsed2slash�');} var str_tags = ''; if (/tags *: *([^; ]((?! *;).)*) *;/.test(attributes)) { str_tags = /tags *: *([^; ]((?! *;).)*) *;/i.exec(attributes)[1];} body = body.replace(/&/gi,'&'); <!-- Ensures HTML entities are interpreted literally --> body = body.replace(/</gi,'<'); body = body.replace(/>/gi,'>'); body = body.replace(/�/gi,'�'); <!-- Code Block Extractor --> var arr_code = new Array(); while (/\[\[code(| ((?!]]).)*)]]((?!\n\[\[\/code]])(.|\n))+\n\[\[\/code]]/i.test(body)) { body = body.replace(/(\[\[code(| ((?!]]).)*)]]((?!\n\[\[\/code]])(.|\n))+\n\[\[\/code]])/i,'�code' + arr_code.push(/(\[\[code(| ((?!]]).)*)]]((?!\n\[\[\/code]])(.|\n))+\n\[\[\/code]])/i.exec(body)[1]) + '�'); } <!-- Embed Block Extractor --> var arr_embed = new Array(); while (/\[\[embed]]((?!\[\[\/embed]])(.|\n))+\[\[\/embed]]/i.test(body)) { body = body.replace(/(\[\[embed]]((?!\[\[\/embed]])(.|\n))+\[\[\/embed]])/i,'�embed' + arr_embed.push(/(\[\[embed]]((?!\[\[\/embed]])(.|\n))+\[\[\/embed]])/i.exec(body)[1]) + '�'); } <!-- Escaped Text Extractor --> var arr_escape = new Array(); while (/@<((?!>@).)+>@/i.test(body)) { body = body.replace(/(@<((?!>@).)+>@)/i,'�escape' + arr_escape.push(/(@<((?!>@).)+>@)/i.exec(body)[1]) + '�'); } <!-- Literal Text Extractor --> var arr_literal = new Array(); while (/@@((?!@@).)+@@/i.test(body)) { body = body.replace(/(@@((?!@@).)+@@)/i,'�literal' + arr_literal.push(/(@@((?!@@).)+@@)/i.exec(body)[1]) + '�'); } <!-- Typography Syntax --> body = body.replace(/``(((?!'').)+)''/gi,'“$1”'); body = body.replace(/`([^']+)'/gi,'‘$1’'); body = body.replace(/,,(((?!'').)+)''/gi,'„$1”'); body = body.replace(/<<(((?!>>).)+)>>/gi,'«$1»'); body = body.replace(/>>(((?!<<).)+)<</gi,'»$1«'); body = body.replace(/\.\.\./gi,'…'); body = body.replace(/\s--\s/gi,' — '); <!-- User Link --> body = body.replace(/\[\[\*?user (((?!]]).)+)]]/gi,'<span class="printuser"><a href="http://www.wikidot.com/user:info/$1" onclick="WIKIDOT.page.listeners.userInfo(1); return false;">$1</a></span>'); <!-- iframe Element --> body = body.replace(/\[\[iframe (((?!( |]])).)+)( ((?!]]).)+)? *]]/gi,'<iframe src="$1"$5></iframe>'); <!-- Image Element --> body = body.replace(/\[\[(=|<|>)?image (((?!( |]])).)+)( ((?!]]).)+)? *]]/gi,'<img$1 src="$2"$6 />'); body = body.replace(/<img</gi,'<img style="text-align: left;"'); body = body.replace(/<img>/gi,'<img style="text-align: right;"'); body = body.replace(/<img=/gi,'<img style="text-align: center;"'); <!-- Horizontal Rule Element --> body = body.replace(/(^|\n)----(\n|$)/gi,'<hr />'); <!-- Heading Elements --> body = body.replace(/(^|\n)(\++)\*? ([^\n]+)(\n|$)/gi,'<h$2>$3</h$2>'); while (/<h\++>/i.test(body)) { body = body.replace(/<h\++>/i,'<h'+(/<h\++>/i.exec(body)[0].length-3)+'>'); } while (/<\/h\++>/i.test(body)) { body = body.replace(/<\/h\++>/i,'</h'+(/<\/h\++>/i.exec(body)[0].length-3)+'>'); } <!-- Ignore New Line --> body = body.replace(/\\\n/gi,''); <!-- Blockquote Element --> while (/((^|\n)>((>)*) (.+)|<blockquote>>((>)*) (.+)|<\/blockquote>\n<blockquote>)/i.test(body)) { body = body.replace(/(^|\n)>((>)*) (.+)/i,'$1<blockquote>$2 $4</blockquote>'); body = body.replace(/<blockquote>>((>)*) (.+)/i,'<blockquote><blockquote>$1 $3</blockquote>'); body = body.replace(/<\/blockquote>\n<blockquote>/i,'\n'); } body = body.replace(/<\/blockquote>\n/gi,'</blockquote>'); body = body.replace(/\n<blockquote>/gi,'<blockquote>'); <!-- Paragraph Formatter Partial --> body = body.replace(/\n\n\n+/gi,'\n\n'); body = body.replace(/[ ]_\n/gi,'<br />'); <!-- List Extractor --> var arr_list = new Array(); while (/(^|\n)[#\*] .+(\n *[#\*] .+)*/i.test(body)) { body = body.replace(/((^|\n)[#\*] .+(\n *[#\*] .+)*)/i,'\n�list' + arr_list.push(/((^|\n)[#\*] .+(\n *[#\*] .+)*)/i.exec(body)[1]) + '�'); } <!-- List Restorer --> for (index=arr_list.length-1;index>=0;index=index-1) { body = body.replace('�list'+ (index + 1) +'�',arr_list.splice(index,1)); } <!-- List Elements --> while (/((^|\n)# (.+)|(^|\n)\* (.+)|<\/(ol|ul)>\n (| +)# (.+)|<\/(ol|ul)>\n (| +)\* (.+)|<li><(ol|ul)>)/i.test(body)) { body = body.replace(/(^|\n)# (.+)/i,'$1<ol><li>$2</li></ol>'); body = body.replace(/(^|\n)\* (.+)/i,'$1<ul><li>$2</li></ul>'); body = body.replace(/<\/(ol|ul)>\n (| +)# (.+)/i,'</$1>\n$2# <ol><li>$3</li></ol>'); body = body.replace(/<\/(ol|ul)>\n (| +)\* (.+)/i,'</$1>\n$2* <ul><li>$3</li></ul>'); body = body.replace(/<li><(ol|ul)>/i,'<li style="list-style: none; display: inline;"><$1>'); } while (/(<\/ol>\n<ol>|<\/ul>\n<ul>)/i.test(body)) { body = body.replace(/<\/ol>\n<ol>/i,''); body = body.replace(/<\/ul>\n<ul>/i,''); } body = body.replace(/<\/(ol|ul)>\n/gi,'</$1>'); body = body.replace(/\n<(ol|ul)>/gi,'<$1>'); <!-- Simple Table Extractor --> var arr_simple = new Array(); while (/((^|\n)((\|\|)+).+)+/i.test(body)) { body = body.replace(/(((^|\n)((\|\|)+).+)+)/i,'\n�simple' + arr_simple.push(/(((^|\n)((\|\|)+).+)+)/i.exec(body)[1]) + '�\n'); } for (index=0;index<arr_simple.length;index=index+1) { arr_simple[index] = arr_simple[index].replace(/(^|\n)(.+)/gi,'\n<tr>$2</tr>'); while (/(\|\|)+/i.test(arr_simple[index])) { arr_simple[index] = arr_simple[index].replace(/(\|\|)+/i,'</td><td colspan="'+(/(\|\|)+/i.exec(arr_simple[index])[0].length/2)+'">'); } arr_simple[index] = arr_simple[index].replace(/<td((?!(<\/td>|<\/tr>)).)+<\/tr>/gi,'</tr>'); arr_simple[index] = arr_simple[index].replace(/<tr><\/td>/gi,'<tr>'); arr_simple[index] = arr_simple[index].replace(/<td([^>]+)>(([~=])|<|>)/gi,'<td s="$2"$1>'); arr_simple[index] = arr_simple[index].replace(/<td s="~"/gi,'<th'); arr_simple[index] = arr_simple[index].replace(/<td s="</gi,'<td style="text-align: left;'); arr_simple[index] = arr_simple[index].replace(/<td s=">/gi,'<td style="text-align: right;'); arr_simple[index] = arr_simple[index].replace(/<td s="=/gi,'<td style="text-align: center;'); arr_simple[index] = arr_simple[index].replace(/<th(((?!<\/td>).)+)<\/td>/gi,'<th$1</th>'); arr_simple[index] = arr_simple[index].replace(/ colspan="1">/gi,'>'); arr_simple[index] = '<table class="wiki-content-table"><tbody>' + arr_simple[index].substr(1) + '</tbody></table>'; } <!-- Simple Table Restorer --> for (index=arr_simple.length-1;index>=0;index=index-1) { body = body.replace('�simple'+ (index + 1) +'�',arr_simple.splice(index,1)); } <!-- Paragraph Formatter Complete --> body = body.replace(/^\n+|\n+$/gi,''); body = '<p>' + body + '</p>' body = body.replace(/\n\n/gi,'</p><p>'); body = body.replace(/\n/gi,'<br />'); body = body.replace(/<p>= /gi,'<p style="text-align: center;">'); <!-- Clear Floats Element --> body = body.replace(/~~~~/gi,'<div style="clear:both; height: 0px; font-size: 1px"></div>'); <!-- Date Element --> body = body.replace(/\[\[date ([^\] ]+)]]/gi,'<span class="odate">$1</span>'); body = body.replace(/\[\[date ([^\] ]+) format\="([^"]+)"]]/gi,'<span class="odate">$1|$2</span>'); <!-- Text Aligning Elements --> body = body.replace(/\[\[\=]]/gi,'<div style="text-align: center;">'); body = body.replace(/\[\[\=\=]]/gi,'<div style="text-align: justify;">'); body = body.replace(/\[\[<]]/gi,'<div style="text-align: left;">'); body = body.replace(/\[\[>]]/gi,'<div style="text-align: right;">'); body = body.replace(/\[\[\/(\=|\=\=|<|>)]]/gi,'</div>'); <!-- Note Element --> body = body.replace(/\[\[note]]/gi,'<div class="wiki-note">'); body = body.replace(/\[\[\/note]]/gi,'</div>'); <!-- Size Element --> body = body.replace(/\[\[size ([^\]"]+)]]/gi,'<span style="font-size: $1;">'); body = body.replace(/\[\[\/size]]/gi,'</span>'); <!-- Table Elements --> body = body.replace(/\[\[table(| [^\]]*)]]/gi,'<table$1><tbody>'); body = body.replace(/\[\[row(| [^\]]*)]]/gi,'<tr$1>'); body = body.replace(/\[\[hcell(| [^\]]*)]]/gi,'<th$1>'); body = body.replace(/\[\[cell(| [^\]]*)]]/gi,'<td$1>'); body = body.replace(/\[\[\/cell]]/gi,'</td>'); body = body.replace(/\[\[\/hcell]]/gi,'</th>'); body = body.replace(/\[\[\/row]]/gi,'</tr>') body = body.replace(/\[\[\/table]]/gi,'</tbody></table>'); <!-- Basic Elements --> body = body.replace(/\[\[(div|span)(| [^\]]*)]]/gi,'<$1$2>'); body = body.replace(/\[\[\/(div|span)]]/gi,'</$1>'); body = body.replace(/\[\[iframe ([^\] ]+)( ((?!]]).)+)*]]/gi,'<iframe src="$1"$2></iframe>'); body = body.replace(/\[\[calculate]](((?!\[\[\/calculate]]).)*)\[\[\/calculate]]/gi,'<span class="wd-calculate">$1</span>'); <!-- Inline Formatting Partial --> body = body.replace(/\*\*(((?!\*\*).)+)\*\*/gi,'<strong>$1</strong>'); body = body.replace(/__(((?!__).)+)__/gi,'<span style="text-decoration: underline;">$1</span>'); body = body.replace(/\[\!--/gi,'[!__'); <!-- Comment Markers Partial --> body = body.replace(/--]/gi,'__]'); <!-- Comment Markers Partial --> body = body.replace(/--(((?!--).)+)--/gi,'<span style="text-decoration: line-through;">$1</span>'); body = body.replace(/\[\!__/gi,'<!--'); <!-- Comment Markers Complete --> body = body.replace(/__]/gi,'-->'); <!-- Comment Markers Complete --> body = body.replace(/{{(((?!}}).)+)}}/gi,'<tt>$1</tt>'); body = body.replace(/\^\^(((?!\^\^).)+)\^\^/gi,'<sup>$1</sup>'); body = body.replace(/,,(((?!,,).)+),,/gi,'<sub>$1</sub>'); body = body.replace(/##([^\|]+)\|(((?!##).)+)##/gi,'<span style="color: $1;">$2</span>'); <!-- Links --> <!-- [[# Anchor]] --> body = body.replace(/\[\[# +(((?!]]).)+)]]/gi,'<a name="$1"></a>'); <!-- [#Anchor Link] --> body = body.replace(/([^\[])\[#([^ ]+) +([^\]]+)]/gi,'$1<a href="#$2">$3</a>'); <!-- [# Empty Link] --> body = body.replace(/\[# +([^\]]+)]/gi,'<a href="javascript:;">$1</a>'); <!-- Links Partial --> body = body.replace(/([^:\* \[]+):\/\//gi,'$1:�2slash�'); <!-- Ignore Parsed Links --> while (/(<[^>]+[^>:\* \[\/]+:)�2slash�([^>]*>)/i.test(body)) { body = body.replace(/(<[^>]+[^>:\* \[\/]+:)�2slash�([^>]*>)/i,'$1�parsed2slash�$2'); } <!-- http://raw.link --> body = body.replace(/(<\/?[^>]+>| |\/\/)([^:\* \[\/]+:�2slash�)(((?!( |\. |<|\/\/)).)+)/gi,'$1<a href="$2$3">$2$3</a>'); <!-- *http://raw.link New Window --> body = body.replace(/(<\/?[^>]+>| |\/\/)\*([^:\* \[]+:�2slash�)(((?!( |\. |<|\/\/)).)+)/gi,'$1<a href="$2$3" target="_blank">$2$3</a>'); <!-- [[[External]]] --> body = body.replace(/\[\[\[(\*)?([^:\* \[]+:�2slash�[^ \|\]]+) *]]]/gi,'[[[$1$2|$2]]]'); <!-- [[[*External|Custom]]] New Window --> body = body.replace(/\[\[\[\*([^:\* \[]+:�2slash�)(((?! *\|).)+) *\| *(((?!]]]).)+)]]]/gi,'<a href="$1$2" target="_blank">$4</a>'); <!-- [[[External|Custom]]] --> body = body.replace(/\[\[\[([^:\* \[]+:�2slash�)(((?! *\|).)+) *\| *(((?!]]]).)+)]]]/gi,'<a href="$1$2">$4</a>'); <!-- [[[Internal|Custom]]] --> body = body.replace(/\[\[\[(?![^:\* \[]+:�2slash�)\/?(((?!(@| *\|)).)+) *\| *(((?!]]]).)+)]]]/gi,'<a href="' + str_site + '/$1">$3</a>'); <!-- [[[Internal]]] --> body = body.replace(/\[\[\[\/?(((?!(@|]]])).)+) *\|? *]]]/gi,'<a href="' + str_site + '/$1">$1</a>'); <!-- [External] --> body = body.replace(/([^\[])\[(\*)?([^:\* \[]+:�2slash�[^ \]]+) *]/gi,'$1[$2$3 $3]'); <!-- [External Custom] New Window --> body = body.replace(/([^\[])\[\*([^:\* \[]+:�2slash�)([^ ]+) +([^\]]+)]/gi,'$1<a href="$2$3" target="_blank">$4</a>'); <!-- [InterWiki:topic] --> body = body.replace(/([^\[])\[(google|wikipedia|wikipedia\.pl|pl\.wikipedia|dictionary):([^ \]]+) *]/gi,'$1[$2:$3 $3]'); <!-- [InterWiki:topic Custom] --> body = body.replace(/([^\[])\[google:([^ \]]+ *[^\]]+)]/gi,'$1[http:�2slash�www.google.com/search?q=$2]'); body = body.replace(/([^\[])\[wikipedia:([^ \]]+ *[^\]]+)]/gi,'$1[http:�2slash�en.wikipedia.org/wiki/$2]'); body = body.replace(/([^\[])\[(wikipedia\.pl|pl\.wikipedia):([^ \]]+ *[^\]]+)]/gi,'$1[http:�2slash�pl.wikipedia.org/wiki/$3]'); body = body.replace(/([^\[])\[dictionary:([^ \]]+ *[^\]]+)]/gi,'$1[http:�2slash�dictionary.reference.com/browse/$2]'); <!-- [External Custom] --> body = body.replace(/([^\[])\[([^:\* \[]+:�2slash�)([^ ]+) +([^\]]+)]/gi,'$1<a href="$2$3">$4</a>'); <!-- [Internal Custom] --> body = body.replace(/([^\[])\[\/([^\[ ][^ ]*) +([^\]]+)]/gi,'$1<a href="' + str_site + '/$2">$3</a>'); <!-- [email@address.com Custom] --> body = body.replace(/([^\[])\[([_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)+) +([^\]]+)]/gi,'$1<a href="mailto:$2">$5</a>'); <!-- email@address.com --> body = body.replace(/(<\/?[^>]+>| |\/\/|\[)([_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)+)/gi,'$1<a href="mailto:$2">$2</a>'); <!-- Button Link --> body = body.replace(/\[\[button ([^\] ]+) *(((?!text\="([^"]*)").)+)*]]/gi,'<a href="javascript:;" $2>$1</a>'); body = body.replace(/\[\[button [^\] ]+ *(((?!text\="([^"]*)").)+)* *(text\="([^"]*)")? *(((?!]]).)+)?]]/gi,'<a href="javascript:;" $1 $6>$5</a>'); <!-- File Syntax --> <!-- [[file /page/Link|Custom]] --> body = body.replace(/\[\[file +\/?(((?!(\/|]])).)+\/(((?! *\|).)+)) *\| *(((?! *]]).)+) *]]/gi,'<a href="' + str_site + '/local--files/$1">$5</a>'); <!-- [[file /page/Link]]] --> body = body.replace(/\[\[file +\/?(((?!(\/|]])).)+\/(((?! *]]).)+)) *]]/gi,'<a href="' + str_site + '/local--files/$1">$1</a>'); <!-- [[file Link|Custom]] --> body = body.replace(/\[\[file +\/(((?! *\|).)+) *\| *(((?! *]]).)+) *]]/gi,'<a href="' + str_site + '/local--files/$1">$3</a>'); <!-- [[file Link|Custom]] --> body = body.replace(/\[\[file +(((?! *\|).)+) *\| *(((?! *]]).)+) *]]/gi,'<a href="' + str_site + '/local--files/' + str_fullname + '/$1">$3</a>'); <!-- [[file Link]]] --> body = body.replace(/\[\[file +\/(((?! *]]).)+) *]]/gi,'<a href="' + str_site + '/local--files/$1">$1</a>'); <!-- [[file Link]]] --> body = body.replace(/\[\[file +(((?! *]]).)+) *]]/gi,'<a href="' + str_site + '/local--files/' + str_fullname + '/$1">$1</a>'); <!-- Inline Formatting Complete --> body = body.replace(/\/\/(((?!(\n|\/\/)).)+)\/\//gi,'<em>$1</em>'); body = body.replace(/�(parsed)?2slash�/gi,'//'); <!-- Complete --> <!-- Code Block Extractor --> for (index=arr_code.length-1;index>=0;index=index-1) { arr_code[index] = arr_code[index].replace(/^\[\[code(|((?!]]).)+)]]\n?/i,'<div class="code"><!--$1 --><pre><code>'); arr_code[index] = arr_code[index].substr(0,arr_code[index].length-9); body = body.replace('�code'+ (index + 1) +'�',arr_code.splice(index,1)+'</code></pre></div>'); } <!-- Embed Block Extractor --> for (index=arr_embed.length-1;index>=0;index=index-1) { arr_embed[index] = arr_embed[index].substr(9,arr_embed[index].length-19); arr_embed[index] = arr_embed[index].replace(/&/gi,'&'); arr_embed[index] = arr_embed[index].replace(/</gi,'<'); arr_embed[index] = arr_embed[index].replace(/>/gi,'>'); arr_embed[index] = arr_embed[index].replace(/�/gi,'�'); body = body.replace('�embed'+ (index + 1) +'�',arr_embed.splice(index,1)); } <!-- Escaped Text Extractor --> for (index=arr_escape.length-1;index>=0;index=index-1) { arr_escape[index] = arr_escape[index].substr(5,arr_escape[index].length-10); arr_escape[index] = arr_escape[index].replace(/&/gi,'&'); <!-- Ensures HTML entities function --> body = body.replace('�escape'+ (index + 1) +'�',arr_escape.splice(index,1)); } <!-- Literal Text Restorer --> for (index=arr_literal.length-1;index>=0;index=index-1) { arr_literal[index] = arr_literal[index].substr(2,arr_literal[index].length-4); body = body.replace('�literal'+ (index + 1) +'�',arr_literal.splice(index,1)); } <!-- Publish Converted HTML --> return body; } function ClientMathCalcuation() { <!-- © James Kanjo 2011 --> var body = document.getElementById('html-body').innerHTML; <!-- Client Math Extractor --> var exp_allowed = /<span class=\"wd-calculate\">(([\d\*\+\-\/\(\)=\!]|<|>|Math\.|E|LN2|LN10|LOG2E|LOG10E|PI|SQRT1_2|SQRT2|(abs|acos|asin|atan|atan2|ceil|cos|exp|floor|log|max|min|pow|random|round|sin|sqrt|tan)\()+)<\/span>/i; var arr_calc = new Array(); while (exp_allowed.test(body)) { body = body.replace(exp_allowed,'�calc' + arr_calc.push(exp_allowed.exec(body)[1]) + '�'); } <!-- Client Math Calculator --> for (index=arr_calc.length-1;index>=0;index=index-1) { str_tmp = arr_calc[index]; arr_calc[index] = arr_calc[index].replace(/</gi,'<'); arr_calc[index] = arr_calc[index].replace(/>/gi,'>'); arr_calc[index] = arr_calc[index].replace(/<>/gi,'!='); arr_calc[index] = arr_calc[index].replace(/=/gi,'=='); arr_calc[index] = arr_calc[index].replace(/====/gi,'=='); arr_calc[index] = arr_calc[index].replace(/(E|LN2|LN10|LOG2E|LOG10E|PI|SQRT1_2|SQRT2|abs|acos|asin|atan|atan2|ceil|cos|exp|floor|log|max|min|pow|random|round|sin|sqrt|tan)/g,'Math.$1'); arr_calc[index] = arr_calc[index].replace(/Math\.Math\.(E|LN2|LN10|LOG2E|LOG10E|PI|SQRT1_2|SQRT2|abs|acos|asin|atan|atan2|ceil|cos|exp|floor|log|max|min|pow|random|round|sin|sqrt|tan)/gi,'Math.$1'); try {arr_calc[index] = eval(arr_calc[index]);} catch(originalstring) {arr_calc[index] = str_tmp;} body = body.replace('�calc'+ (index + 1) +'�',arr_calc.splice(index,1)); } document.getElementById('html-body').innerHTML = body; }