view release on metacpan or search on metacpan
cp/codepress/engines/gecko.js view on Meta::CPAN
for(var i=0;i<Language.shortcuts.length;i++)
if(Language.shortcuts[i].input == cCode)
this.insertCode(Language.shortcuts[i].output,false);
},
getRangeAndCaret : function() {
var range = window.getSelection().getRangeAt(0);
var range2 = range.cloneRange();
var node = range.endContainer;
var caret = range.endOffset;
range2.selectNode(node);
return [range2.toString(),caret];
},
insertCode : function(code,replaceCursorBefore) {
var range = window.getSelection().getRangeAt(0);
var node = window.document.createTextNode(code);
var selct = window.getSelection();
var range2 = range.cloneRange();
// Insert text at cursor position
selct.removeAllRanges();
range.deleteContents();
range.insertNode(node);
// Move the cursor to the end of text
range2.selectNode(node);
range2.collapse(replaceCursorBefore);
selct.removeAllRanges();
selct.addRange(range2);
},
// get code from editor
getCode : function() {
if(!document.getElementsByTagName('pre')[0] || editor.innerHTML == '')
editor = CodePress.getEditor();
var code = editor.innerHTML;
cp/codepress/engines/msie.js view on Meta::CPAN
// code = window.clipboardData.getData('Text');
}
},
// put cursor back to its original position after every parsing
findString : function() {
range = self.document.body.createTextRange();
if(range.findText(cc)){
range.select();
range.text = '';
}
},
// split big files, highlighting parts of it
split : function(code,flag) {
if(flag=='scroll') {
this.scrolling = true;
return code;
}
cp/codepress/engines/msie.js view on Meta::CPAN
if(mid-2000<0) {ini=0;end=4000;}
else if(mid+2000>code.length) {ini=code.length-4000;end=code.length;}
else {ini=mid-2000;end=mid+2000;}
code = code.substring(ini,end);
return code.substring(code.indexOf('<P>'),code.lastIndexOf('</P>')+4);
}
},
// syntax highlighting parser
syntaxHighlight : function(flag) {
if(flag!='init') document.selection.createRange().text = cc;
o = editor.innerHTML;
if(flag=='paste') { // fix pasted text
o = o.replace(/<BR>/g,'\r\n');
o = o.replace(/\u2008/g,'\t');
}
o = o.replace(/<P>/g,'\n');
o = o.replace(/<\/P>/g,'\r');
o = o.replace(/<.*?>/g,'');
o = o.replace(/ /g,'');
o = '<PRE><P>'+o+'</P></PRE>';
cp/codepress/engines/msie.js view on Meta::CPAN
},
getCompleteEndingChars : function() {
var cChars = '';
for(var i=0;i<Language.complete.length;i++)
cChars += '|'+Language.complete[i].output.charAt(Language.complete[i].output.length-1);
return cChars+'|';
},
completeEnding : function(trigger) {
var range = document.selection.createRange();
try {
range.moveEnd('character', 1)
}
catch(e) {
return false;
}
var next_character = range.text
range.moveEnd('character', -1)
if(next_character != trigger ) return false;
else {
cp/codepress/engines/msie.js view on Meta::CPAN
},
getLastWord : function() {
var rangeAndCaret = CodePress.getRangeAndCaret();
words = rangeAndCaret[0].substring(rangeAndCaret[1]-40,rangeAndCaret[1]);
words = words.replace(/[\s\n\r\);\W]/g,'\n').split('\n');
return words[words.length-1].replace(/[\W]/gi,'').toLowerCase();
},
getRangeAndCaret : function() {
var range = document.selection.createRange();
var caret = Math.abs(range.moveStart('character', -1000000)+1);
range = this.getCode();
range = range.replace(/\n\r/gi,' ');
range = range.replace(/\n/gi,'');
return [range.toString(),caret];
},
insertCode : function(code,replaceCursorBefore) {
var repdeb = '';
var repfin = '';
if(replaceCursorBefore) { repfin = code; }
else { repdeb = code; }
if(typeof document.selection != 'undefined') {
var range = document.selection.createRange();
range.text = repdeb + repfin;
range = document.selection.createRange();
range.move('character', -repfin.length);
range.select();
}
},
// get code from editor
getCode : function() {
var code = editor.innerHTML;
code = code.replace(/<br>/g,'\n');
code = code.replace(/<\/p>/gi,'\r');
code = code.replace(/<p>/i,''); // IE first line fix
code = code.replace(/<p>/gi,'\n');
cp/codepress/engines/msie.js view on Meta::CPAN
},
// undo and redo methods
actions : {
pos : -1, // actual history position
history : [], // history vector
undo : function() {
if(editor.innerHTML.indexOf(cc)==-1){
document.selection.createRange().text = cc;
this.history[this.pos] = editor.innerHTML;
}
this.pos--;
if(typeof(this.history[this.pos])=='undefined') this.pos++;
editor.innerHTML = this.history[this.pos];
CodePress.findString();
},
redo : function() {
this.pos++;
cp/codepress/engines/opera.js view on Meta::CPAN
// TODO: pasted text should be parsed and highlighted
}
},
// put cursor back to its original position after every parsing
findString : function() {
var sel = window.getSelection();
var range = window.document.createRange();
var span = window.document.getElementsByTagName('span')[0];
range.selectNode(span);
sel.removeAllRanges();
sel.addRange(range);
span.parentNode.removeChild(span);
//if(self.find(cc))
//window.getSelection().getRangeAt(0).deleteContents();
},
// split big files, highlighting parts of it
split : function(code,flag) {
if(flag=='scroll') {
cp/codepress/engines/opera.js view on Meta::CPAN
for(var i=0;i<Language.shortcuts.length;i++)
if(Language.shortcuts[i].input == cCode)
this.insertCode(Language.shortcuts[i].output,false);
},
getRangeAndCaret : function() {
var range = window.getSelection().getRangeAt(0);
var range2 = range.cloneRange();
var node = range.endContainer;
var caret = range.endOffset;
range2.selectNode(node);
return [range2.toString(),caret];
},
insertCode : function(code,replaceCursorBefore) {
var range = window.getSelection().getRangeAt(0);
var node = window.document.createTextNode(code);
var selct = window.getSelection();
var range2 = range.cloneRange();
// Insert text at cursor position
selct.removeAllRanges();
range.deleteContents();
range.insertNode(node);
// Move the cursor to the end of text
range2.selectNode(node);
range2.collapse(replaceCursorBefore);
selct.removeAllRanges();
selct.addRange(range2);
},
// get code from editor
getCode : function() {
var code = editor.innerHTML;
code = code.replace(/<br>/g,'\n');
code = code.replace(/\u2009/g,'');
cp/codepress/index.html view on Meta::CPAN
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>CodePress - Real Time Syntax Highlighting Editor written in JavaScript</title>
<style>
body {color:#000;background-color:white;font:15px georgia, "Lucida Grande", "Lucida Sans Unicode", Arial, Helvetica, sans-serif; letter-spacing:0.01em;margin:15px;}
p {margin:0 0 15px 0;}
a,a:visited {color:#7f0055;}
select {background:#ffffe1;}
button {margin-top:5px;}
button.actions {width:171px;font-family:arial;}
h1 {color:#7f0055;margin:0;padding:0;font-size:42px;font-weight:normal;}
h1 a {text-decoration:none;}
h2 {margin:0;}
h2 a {text-decoration:none;font-weight:normal;font-size:22px;color:black !important;}
h3 {font-size:20px;font-weight:normal;padding:0;margin:25px 0 5px 0;color:#7f0055;font-weight:bold;border-bottom:2px dotted #d8d8d8;}
h4 {font-size:18px;font-weight:normal;z-index:0;}
code {color:#0080c0;font-size:13px;font-weight:bold;}
ol, ul {padding:5px 0 5px 25px;margin:0;}
cp/codepress/index.html view on Meta::CPAN
print $var1;
# Subroutine
sub test() {
print "ok";
}
</textarea>
<textarea id="cp-sql" class="hidden-code">
--
-- simple select example
--
SELECT * FROM books
WHERE price > 100.00 and price < 150.00
ORDER BY title
SELECT books.title, count(*) AS Authors
FROM books
JOIN book_authors
ON books.book_number = book_authors.book_number
GROUP BY books.title
cp/codepress/index.html view on Meta::CPAN
}
p {
margin:0 0 15px 0;
}
a,a:visited {
color:#7f0055;
}
select {
background:#ffffe1;
}
h1 {
color:#7f0055;
margin:0;
padding:0;
font-size:42px;
}
</textarea>
cp/codepress/languages/html.js view on Meta::CPAN
/*
* CodePress regular expressions for HTML syntax highlighting
*/
// HTML
Language.syntax = [
{ input : /(<[^!]*?>)/g, output : '<b>$1</b>' }, // all tags
{ input : /(<a .*?>|<\/a>)/g, output : '<a>$1</a>' }, // links
{ input : /(<img .*?>)/g, output : '<big>$1</big>' }, // images
{ input : /(<\/?(button|textarea|form|input|select|option|label).*?>)/g, output : '<u>$1</u>' }, // forms
{ input : /(<style.*?>)(.*?)(<\/style>)/g, output : '<em>$1</em><em>$2</em><em>$3</em>' }, // style tags
{ input : /(<script.*?>)(.*?)(<\/script>)/g, output : '<strong>$1</strong><tt>$2</tt><strong>$3</strong>' }, // script tags
{ input : /=(".*?")/g, output : '=<s>$1</s>' }, // atributes double quote
{ input : /=('.*?')/g, output : '=<s>$1</s>' }, // atributes single quote
{ input : /(<!--.*?-->.)/g, output : '<ins>$1</ins>' }, // comments
{ input : /\b(alert|window|document|break|continue|do|for|new|this|void|case|default|else|function|return|typeof|while|if|label|switch|var|with|catch|boolean|int|try|false|throws|null|true|goto)\b/g, output : '<i>$1</i>' } // script reserved words
]
Language.snippets = [
{ input : 'aref', output : '<a href="$0"></a>' },
cp/codepress/languages/perl.js view on Meta::CPAN
* CodePress regular expressions for Perl syntax highlighting
* By J. Nick Koston
*/
// Perl
Language.syntax = [
{ input : /\"(.*?)(\"|<br>|<\/P>)/g, output : '<s>"$1$2</s>' }, // strings double quote
{ input : /\'(.*?)(\'|<br>|<\/P>)/g, output : '<s>\'$1$2</s>' }, // strings single quote
{ input : /([\$\@\%][\w\.]*)/g, output : '<a>$1</a>' }, // vars
{ input : /(sub\s+)([\w\.]*)/g, output : '$1<em>$2</em>' }, // functions
{ input : /\b(abs|accept|alarm|atan2|bind|binmode|bless|caller|chdir|chmod|chomp|chop|chown|chr|chroot|close|closedir|connect|continue|cos|crypt|dbmclose|dbmopen|defined|delete|die|do|dump|each|else|elsif|endgrent|endhostent|endnetent|endprotoent|e...
{ input : /([\(\){}])/g, output : '<u>$1</u>' }, // special chars
{ input : /#(.*?)(<br>|<\/P>)/g, output : '<i>#$1</i>$2' } // comments
]
Language.snippets = []
Language.complete = [
{ input : '\'',output : '\'$0\'' },
{ input : '"', output : '"$0"' },
{ input : '(', output : '\($0\)' },
cp/codepress/languages/sql.js view on Meta::CPAN
/*
* CodePress regular expressions for SQL syntax highlighting
* By Merlin Moncure
*/
// SQL
Language.syntax = [
{ input : /\'(.*?)(\')/g, output : '<s>\'$1$2</s>' }, // strings single quote
{ input : /\b(add|after|aggregate|alias|all|and|as|authorization|between|by|cascade|cache|cache|called|case|check|column|comment|constraint|createdb|createuser|cycle|database|default|deferrable|deferred|diagnostics|distinct|domain|each|else|elseif|e...
{ input : /\b(bigint|bigserial|bit|boolean|box|bytea|char|character|cidr|circle|date|decimal|double|float4|float8|inet|int2|int4|int8|integer|interval|line|lseg|macaddr|money|numeric|oid|path|point|polygon|precision|real|refcursor|serial|serial4|ser...
{ input : /\b(abort|alter|analyze|begin|checkpoint|close|cluster|comment|commit|copy|create|deallocate|declare|delete|drop|end|execute|explain|fetch|grant|insert|listen|load|lock|move|notify|prepare|reindex|reset|restart|revoke|rollback|select|set|s...
{ input : /([^:]|^)\-\-(.*?)(<br|<\/P)/g, output: '$1<i>--$2</i>$3' } // comments //
]
Language.snippets = [
{ input : 'select', output : 'select $0 from where ' }
]
Language.complete = [
{ input : '\'', output : '\'$0\'' },
{ input : '"', output : '"$0"' },
{ input : '(', output : '\($0\)' },
{ input : '[', output : '\[$0\]' },
{ input : '{', output : '{\n\t$0\n}' }
]
cp/codepress/languages/xsl.js view on Meta::CPAN
{
input : /(<[^!]*?>)/g,
output : '<b>$1</b>' // all tags
},{
input : /(<a.*?>|<\/a>)/g,
output : '<a>$1</a>' // links
},{
input : /(<img .*?>)/g,
output : '<big>$1</big>' // images
},{
input : /(<\/?(button|textarea|form|input|select|option|label).*?>)/g,
output : '<u>$1</u>' // forms
},{
input : /(<style.*?>)(.*?)(<\/style>)/g,
output : '<em>$1</em><em>$2</em><em>$3</em>' // style tags
},{
input : /(<script.*?>)(.*?)(<\/script>)/g,
output : '<strong>$1</strong><tt>$2</tt><strong>$3</strong>' // script tags
},{
input : /(<xsl.*?>|<\/xsl.*?>)/g,
output : '<xsl>$1</xsl>' // xsl
cp/codepress/languages/xsl.js view on Meta::CPAN
{input : 'ol', output : '<ol>$0</ol>' },
{input : 'strong', output : '<strong>$0</strong>' },
{input : 'br', output : '<br />' },
{input : 'script', output : '<script type="text/javascript" language="javascript" charset="utf-8">\n\t$0\t\n</script>' },
{input : 'scriptsrc', output : '<script src="$0" type="text/javascript" language="javascript" charset="utf-8"></script>' },
{input : 'span', output : '<span>$0</span>' },
{input : 'table', output : '<table border="$0" cellspacing="" cellpadding="">\n\t<tr><th></th></tr>\n\t<tr><td></td></tr>\n</table>' },
{input : 'style', output : '<style type="text/css" media="screen">\n\t$0\n</style>' },
{input : 'xsl:stylesheet', output : '<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">' },
{input : 'xsl:template', output : '<xsl:template>$0</xsl:template>' },
{input : 'xsl:for-each', output : '<xsl:for-each select="$0"></xsl:for-each>' },
{input : 'xsl:choose', output : '<xsl:choose>$0<\xsl:choose>' },
{input : 'xsl:param', output : '<xsl:param name="$0" />' },
{input : 'xsl:variable', output : '<xsl:variable name="$0"></xsl:variable>' },
{input : 'xsl:if', output : '<xsl:if test="$0"></xsl:if>' },
{input : 'xsl:when', output : '<xsl:when test="$0"></xsl:when>' },
{input : 'xsl:otherwise', output : '<xsl:otherwise>$0</xsl:otherwise>' },
{input : 'xsl:attribute', output : '<xsl:attribute name="$0"></xsl:attribute>' },
{input : 'xsl:value-of', output : '<xsl:value-of select="$0"/>' },
{input : 'xsl:with-param', output : '<xsl:with-param name="$0" select="" />' },
{input : 'xsl:call-template', output : '<xsl:call-template name="$0">' }
];
Language.complete = [ // Auto complete only for 1 character
{input : '\'',output : '\'$0\'' },
{input : '"', output : '"$0"' },
{input : '(', output : '\($0\)' },
{input : '[', output : '\[$0\]' },
{input : '{', output : '{\n\t$0\n}' }