Commit defffc9d authored by RobertPlummer's avatar RobertPlummer

[FIX] Moved dom elements to their own functions in both the php and js version...

[FIX] Moved dom elements to their own functions in both the php and js version of each other, next will be the update of the php counterpart.
parent f48f4825
......@@ -2339,6 +2339,7 @@ lib/parser/WikiParser.jison -text
lib/parser/WikiParser.js -text
lib/parser/WikiParser.php -text
lib/parser/WikiParserTester.html -text
lib/parser/parserlib.js -text
lib/parser/parserlib.php -text
lib/payment/behavior/cancel_cart_order.php -text
lib/payment/behavior/cart_exchange_product.php -text
......
......@@ -26,8 +26,8 @@ SMILE [a-z]+
"{"{INLINE_PLUGIN_ID}.*?"}"
%{
var pluginName = yytext.match(/^\{([a-z]+)/)[1];
var pluginParams = yytext.match(/[ ].*?[}]|[/}]/);
var pluginName = yy.cmd.match(/^\{([a-z]+)/, yytext)[1];
var pluginParams = yy.cmd.match(/[ ].*?[}]|[/}]/, yytext);
yytext = {
name: pluginName,
params: pluginParams,
......@@ -38,13 +38,14 @@ SMILE [a-z]+
"{"{PLUGIN_ID}"(".*?")}"
%{
var pluginName = yytext.match(/^\{([A-Z]+)/)[1];
var pluginParams = yytext.match(/[(].*?[)]/);
var pluginName = yy.cmd.match(/^\{([A-Z]+)/, yytext)[1];
var pluginParams = yy.cmd.match(/[(].*?[)]/, yytext);
if (!yy.pluginStack) yy.pluginStack = [];
yy.pluginStack.push({
name: pluginName,
params: pluginParams
params: pluginParams,
body: ''
});
if (yy.pluginStack.length == 1) {
......@@ -59,7 +60,7 @@ SMILE [a-z]+
if (yy.pluginStack) {
if (
yy.pluginStack.length &&
yytext.match(yy.pluginStack[yy.pluginStack.length - 1].name)
yy.cmd.match(yy.pluginStack[yy.pluginStack.length - 1].name, yytext)
) {
var readyPlugin = yy.pluginStack.pop();
if (yy.pluginStack.length == 0) {
......@@ -93,21 +94,20 @@ SMILE [a-z]+
"---"
%{
yytext = "<hr />";
yytext = this.yy.cmd.make_hr();
return 'HORIZONTAL_BAR';
%}
"(:"{SMILE}":)"
%{
var smile = yytext.substring(2, yytext.length - 2);
yytext = "<img src='img/smiles/icon_" + smile + ".gif' alt='" + smile + "' />";
var smile = this.yy.cmd.substring(yytext, 2, -2);
yytext = this.yy.cmd.make_smile(smile);
return 'SMILE';
%}
"[[".*?
%{
var smile = yytext.substring(2, yytext.length - 2);
yytext = "<img src='img/smiles/icon_" + smile + ".gif' alt='" + smile + "' />";
yytext = this.yy.cmd.substring(yytext, 2, -1);
return 'CONTENT';
%}
......@@ -150,7 +150,7 @@ SMILE [a-z]+
(.) return 'CONTENT'
(\n)
%{
yytext = yytext.replace(/\n/g, '<br />');
yytext = this.yy.cmd.replace(/\n/g, '<br />', yytext);
return 'CONTENT';
%}
......@@ -177,11 +177,11 @@ wiki_contents
plugin
: INLINE_PLUGIN
{$$ = plugin($1);}
{$$ = yy.cmd.plugin($1);}
| PLUGIN_START wiki_contents PLUGIN_END
{
$3.body = $2;
$$ = plugin($3);
$$ = yy.cmd.plugin($3);
}
;
......@@ -196,84 +196,83 @@ content
: CONTENT
{$$ = $1;}
| HTML
{$$ = isHtmlPermissible($1);}
| LINK
{$$ = $1;}
{$$ = yy.cmd.html($1);}
| HORIZONTAL_BAR
{$$ = $1;}
| SMILE
{$$ = $1;}
| BOLD_START wiki_contents BOLD_END
{$$ = "<b>" + $2 + "</b>";}
{$$ = yy.cmd.make_bold($2);}
| BOX_START wiki_contents BOX_END
{$$ = "<div style='border: solid 1px black;'>" + $2 + "</div>";}
{$$ = yy.cmd.make_box($2);}
| CENTER_START wiki_contents CENTER_END
{$$ = "<center>" + $2 + "</center>";}
{$$ = yy.cmd.make_center($2);}
| COLORTEXT_START wiki_contents COLORTEXT_END
{
var text = $2.split(':');
$$ = "<span style='color: #" + text[0] + ";'>" +text[1] + "</span>";
$$ = yy.cmd.make_colortext(text[0], text[1]);
}
| ITALIC_START wiki_contents ITALIC_END
{$$ = "<i>" + $2 + "</i>";}
{$$ = yy.cmd.make_italics($2);}
| HEADER6_START wiki_contents HEADER6_END
{$$ = "<h6>" + $2 + "</h6>";}
{$$ = yy.cmd.make_header6($2);}
| HEADER5_START wiki_contents HEADER5_END
{$$ = "<h5>" + $2 + "</h5>";}
{$$ = yy.cmd.make_header5($2);}
| HEADER4_START wiki_contents HEADER4_END
{$$ = "<h4>" + $2 + "</h4>";}
{$$ = yy.cmd.make_header4($2);}
| HEADER3_START wiki_contents HEADER3_END
{$$ = "<h3>" + $2 + "</h3>";}
{$$ = yy.cmd.make_header3($2);}
| HEADER2_START wiki_contents HEADER2_END
{$$ = "<h2>" + $2 + "</h2>";}
{$$ = yy.cmd.make_header2($2);}
| HEADER1_START wiki_contents HEADER1_END
{$$ = "<h1>" + $2 + "</h1>";}
{$$ = yy.cmd.make_header1($2);}
| LINK_START wiki_contents LINK_END
{
var link = $2.split('|');
var href = $2;
var text = $2;
if ($2.match(/\|/)) {
if (yy.cmd.match(/\|/, $2)) {
href = link[0];
text = link[1];
}
$$ = "<a href='" + href + "'>" + text + "</a>";
$$ = yy.cmd.make_link(href, text);
}
| NP_START wiki_contents NP_END
{$$ = $2;}
| STRIKETHROUGH_START wiki_contents STRIKETHROUGH_END
{$$ = "<span style='text-decoration: line-through;'>" + $2 + "</span>";}
{$$ = yy.cmd.make_strikethrough($2);}
| TABLE_START wiki_contents TABLE_END
{
var tableContents = '';
var rows = $2.split('<br />');
var rows = yy.cmd.split('<br />', $2);
for(var i = 0; i < rows.length; i++) {
var cells = rows[i].split('|');
tableContents += "<tr>";
var row = '';
var cells = yy.cmd.split('|', rows[i]);
for(var j = 0; j < cells.length; j++) {
tableContents += "<td>" + cells[j] + "</td>";
row += yy.cmd.make_table_td(cells[j]);
}
tableContents += "</tr>";
tableContents += yy.cmd.make_table_tr(row);
}
$$ = "<table style='width: 100%;'>" + tableContents + "</table>";
$$ = yy.cmd.make_table(tableContents);
}
| TITLEBAR_START wiki_contents TITLEBAR_END
{$$ = "<div class='titlebar'>" + $2 + "</div>";}
{$$ = yy.cmd.make_titlebar($2);}
| UNDERSCORE_START wiki_contents UNDERSCORE_END
{$$ = "<u>" + $2 + "</u>";}
{$$ = yy.cmd.make_underscore($2);}
| WIKILINK_START wiki_contents WIKILINK_END
{
var wikilink = $2.split('|');
var href = $2;
var text = $2;
if ($2.match(/\|/)) {
if (yy.cmd.match(/\|/, $2)) {
href = wikilink[0];
text = wikilink[1];
}
$$ = "<a href='" + href + "'>" + text + "</a>";
$$ = yy.cmd.make_wikilink(href, text);
}
;
\ No newline at end of file
This diff is collapsed.
......@@ -11,6 +11,7 @@
<script src="../codemirror_tiki/codemirror_tiki.js"></script>
<script src="WikiParser.js"></script>
<script src="parserlib.js"></script>
<script style="text/javascript">
function wikiplugin_nobody() {
return "__This plugin has no body__";
......@@ -49,50 +50,12 @@
}
function isHtmlPermissible(tag) {
if ($('#HtmlOn').is(':checked')) {
if ($('#htmlOn').is(':checked')) {
return tag;
}
return "";
}
function plugin(plugin) {
if (!isPluginPermissible(plugin.name)) return "<div style='background-color: red; color: white;'>Plugin " + plugin.name + " Not Permissible</div>";
var wikiPluginName = "wikiplugin_" + plugin.name.toLowerCase();
if (window[wikiPluginName]) {
var thisOutput = window[wikiPluginName](plugin.body);
if (thisOutput) {
var newOutput = tryParse(thisOutput);
return (newOutput ? newOutput : thisOutput);
}
}
return plugin.body;
}
function tryParse(val) {
try {
function Lexer () {}
Lexer.prototype = WikiParser.lexer;
function Parser () {
this.lexer = new Lexer();
this.yy = {};
}
Parser.prototype = WikiParser;
var wikiParser = (new Parser);
return wikiParser.parse(val);
} catch (e) {
if ($('#errorsOn').is(':checked')) {
$('<pre />')
.html(e + '')
.dialog();
}
}
}
$(function(){
syntaxHighlighter.ready($('#wiki'), {readOnly: false, changeText: ''});
......@@ -100,14 +63,14 @@
$('#runParser')
.click(function() {
$('#output').html(tryParse(editor.getValue()));
$('#output').html(parserlib.parse(editor.getValue(), $('#errorsOn').is(':checked')));
});
$('#wiki')
.change(function() {
$('#output').html(tryParse(editor.getValue()));
$('#output').html(parserlib.parse(editor.getValue(), $('#errorsOn').is(':checked')));
})
.keyup(function() {
$('#output').html(tryParse(editor.getValue()));
$('#output').html(parserlib.parse(editor.getValue(), $('#errorsOn').is(':checked')));
})
.change();
});
......@@ -216,7 +179,7 @@ And now, just www.tiki.org (which should become a link)
I'm in the yellow!
{BGYELLOW}</textarea>
Show Errors? <input type="checkbox" value="true" id="errorsOn" /> <br />
Allow Html? <input type="checkbox" value="true" id="HtmlOn" /> <br />
Allow Html? <input type="checkbox" value="true" id="htmlOn" /> <br />
<input type="button" value="Submit" id="runParser"/>
</td>
<td style="width: 50%;">
......
var parserlib = {
parse: function(val, errors) {
try {
function Lexer () {}
Lexer.prototype = WikiParser.lexer;
function Parser () {
this.lexer = new Lexer();
this.yy = {cmd: parserlib};
}
Parser.prototype = WikiParser;
var wikiParser = (new Parser);
return wikiParser.parse(val);
} catch (e) {
if (errors) {
return e;
}
}
},
plugin: function(plugin) {
//needs a little ajax magic
if (plugin) {
if (plugin.name) {
var wikiPluginName = "wikiplugin_" + plugin.name.toLowerCase();
if (window[wikiPluginName]) {
var thisOutput = window[wikiPluginName](plugin.body);
if (thisOutput) {
var newOutput = parserlib.parse(thisOutput);
return (newOutput ? newOutput : thisOutput);
}
}
}
return (plugin.body ? plugin.body : '');
}
return '';
},
make_bold: function ($html) {
return "<strong>" + $html + "</strong>";
},
make_box: function ($html) {
return "<div style='border: solid 1px black;'>" + $html + "</div>";
},
make_center: function ($html) {
return "<center>" + $html + "</center>";
},
make_colortext: function ($color, $html) {
return "<span style='color: #" + $color + ";'>" + $html + "</span>";
},
make_italics: function ($html) {
return "<i>" + $html + "</i>";
},
make_header1: function ($html) {
return "<h1>" + $html + "</h1>";
},
make_header2: function ($html) {
return "<h2>" + $html + "</h2>";
},
make_header3: function ($html) {
return "<h3>" + $html + "</h3>";
},
make_header4: function ($html) {
return "<h4>" + $html + "</h4>";
},
make_header5: function ($html) {
return "<h5>" + $html + "</h5>";
},
make_header6: function ($html) {
return "<h6>" + $html + "</h6>";
},
make_hr: function () {
return "<hr />";
},
make_link: function ($href, $html) {
return "<a href='" + $href + "'>" + $html + "</a>";
},
make_smile: function ($smile) { //this needs more tlc too
return "<img src='img/smiles/icon_" + $smile + ".gif' alt='" + $smile + "' />";
},
make_strikethrough: function ($html) {
return "<span style='text-decoration: line-through;'>" + $html + "</span>";
},
make_table: function ($html) {
return "<table style='width: 100%;'>" + $html + "</table>";
},
make_table_tr: function ($html) {
return "<tr>" + $html + "</tr>";
},
make_table_td: function ($html) {
return "<td>" + $html + "</td>";
},
make_titlebar: function ($html) {
return "<div class='titlebar'>" + $html + "</div>";
},
make_underscore: function ($html) {
return "<u>" + $html + "</u>";
},
make_wikilink: function ($href, $html) {
return "<a href='" + $href + "'>" + $html + "</a>";
},
html: function ($html) { //this needs some ajax tlc
return $html;
},
substring: function($val, $left, $right) {
return $val.substring($left, $val.length + $right);
},
match: function($pattern, $subject) {
return $subject.match($pattern);
},
replace: function($search, $replace, $subject) {
return $subject.replace($search, $replace);
},
split: function ($delimiter, $string) {
return $string.split($delimiter);
}
};
\ No newline at end of file
......@@ -34,7 +34,7 @@ class ParserLib extends TikiDb_Bridge
$this->parser = new WikiParser;
//private methods
$this->parser->cmd = $this;
$this->parser->yy->cmd = $this;
}
function plugin($pluginDetails) {
......@@ -56,6 +56,113 @@ class ParserLib extends TikiDb_Bridge
return $this->parser->parse($data);
}
//Wiki Syntax Objects Parsing Start
function make_bold($html) {
return "<strong>" . $html . "</strong>";
}
function make_box($html) {
return "<div style='border: solid 1px black;'>" . $html . "</div>";
}
function make_center($html) {
return "<center>" . $html . "</center>";
}
function make_colortext($color, $html) {
return "<span style='color: #" . $color . ";'>" . $html . "</span>";
}
function make_italics($html) {
return "<i>" . $html . "</i>";
}
function make_header1($html) {
return "<h1>" . $html . "</h1>";
}
function make_header2($html) {
return "<h2>" . $html . "</h2>";
}
function make_header3($html) {
return "<h3>" . $html . "</h3>";
}
function make_header4($html) {
return "<h4>" . $html . "</h4>";
}
function make_header5($html) {
return "<h5>" . $html . "</h5>";
}
function make_header6($html) {
return "<h6>" . $html . "</h6>";
}
function make_hr() {
return "<hr />";
}
function make_link($href, $html) {
return "<a href='" . $href . "'>" . $html . "</a>";
}
function make_smile($smile) { //this needs more tlc too
return "<img src='img/smiles/icon_" . $smile . ".gif' alt='" . $smile . "' />";
}
function make_strikethrough($html) {
return "<span style='text-decoration: line-through;'>" . $html . "</span>";
}
function make_table($html) {
return "<table style='width: 100%;'>" . $html . "</table>";
}
function make_table_tr($html) {
return "<tr>" . $html . "</tr>";
}
function make_table_td($html) {
return "<td>" . $html . "</td>";
}
function make_titlebar($html) {
return "<div class='titlebar'>" . $html . "</div>";
}
function make_underscore($html) {
return "<u>" . $html . "</u>";
}
function make_wikilink($href, $html) {
return "<a href='" . $href . "'>" . $html . "</a>";
}
//Wiki Syntax Objects Parsing End
function html($html) {
return $html;
}
//unified functions used inside parser
function substring($val, $left, $right) {
return substr($val, $left, $right);
}
function match($pattern, $subject) {
return preg_match($pattern, $subject);
}
function replace($search, $replace, $subject) {
return str_replace($search, $replace, $subject);
}
function split($delimiter, $string) {
return explode($delimiter, $string);
}
//NEED MIGRATION
//Below here methods that need updating to new WikiParser.php that were integrated from tikilib
//*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment