and change syntax highlighter API once more

This commit is contained in:
rolux 2011-05-08 23:14:56 +02:00
parent bec9222cf2
commit 7c3a40368f
2 changed files with 9 additions and 14 deletions

View file

@ -19,7 +19,7 @@ Ox.load('UI', {
.append( .append(
Ox.FormElementGroup({ Ox.FormElementGroup({
elements: [ elements: [
'showLineNumbers', 'showPage', 'showReturns', 'showSpaces', 'showTabs', 'stripComments' 'showLineNumbers', 'showPage', 'showLinebreaks', 'showTabs', 'showWhitespace', 'stripComments'
].map(function(v, i) { ].map(function(v, i) {
return Ox.Checkbox({ return Ox.Checkbox({
overlap: 'right', overlap: 'right',

View file

@ -6,14 +6,14 @@ Ox.SyntaxHighlighter <function> Syntax Highlighter
options <o> Options options <o> Options
lineLength <n|0> If larger than zero, show edge of page lineLength <n|0> If larger than zero, show edge of page
offset <n|1> First line number offset <n|1> First line number
showLinebreaks <b|false> If true, show linebreaks
showLineNumbers <b|false> If true, show line numbers showLineNumbers <b|false> If true, show line numbers
showReturns <b|false> If true, show linebreaks showWhitespace <b|false> If true, show whitespace
showSpaces <b|false> If true, show whitespace
showTabs <b|false> If true, show tabs showTabs <b|false> If true, show tabs
source <s|''> JavaScript source source <s|''> JavaScript source
stripComments <b|false> If true, strip comments stripComments <b|false> If true, strip comments
tabSize <n|4> Number of spaces per tab tabSize <n|4> Number of spaces per tab
self <o> Shared private self <o> Shared private variable
@*/ @*/
Ox.SyntaxHighlighter = function(options, self) { Ox.SyntaxHighlighter = function(options, self) {
@ -23,10 +23,10 @@ Ox.SyntaxHighlighter = function(options, self) {
.defaults({ .defaults({
lineLength: 0, lineLength: 0,
offset: 1, offset: 1,
showLinebreaks: false,
showLineNumbers: false, showLineNumbers: false,
showReturns: false,
showSpaces: false,
showTabs: false, showTabs: false,
showWhitespace: false,
source: '', source: '',
stripComments: false, stripComments: false,
tabSize: 4, tabSize: 4,
@ -40,14 +40,14 @@ Ox.SyntaxHighlighter = function(options, self) {
var $lineNumbers, $line, $source, width, var $lineNumbers, $line, $source, width,
lines, source = '', tokens, lines, source = '', tokens,
linebreak = ( linebreak = (
self.options.showReturns ? self.options.showLinebreaks ?
'<span class="OxLinebreak">\u21A9</span>' : '' '<span class="OxLinebreak">\u21A9</span>' : ''
) + '<br/>', ) + '<br/>',
tab = ( tab = (
self.options.showTabs ? self.options.showTabs ?
'<span class="OxTab">\u2192</span>' : '' '<span class="OxTab">\u2192</span>' : ''
) + Ox.repeat('&nbsp;', self.options.tabSize - self.options.showTabs), ) + Ox.repeat('&nbsp;', self.options.tabSize - self.options.showTabs),
whitespace = self.options.showSpaces ? '\u00B7' : '&nbsp;'; whitespace = self.options.showWhitespace ? '\u00B7' : '&nbsp;';
self.options.source = self.options.source self.options.source = self.options.source
.replace(/\r\n/g, '\n') .replace(/\r\n/g, '\n')
.replace(/\r/g, '\n'); .replace(/\r/g, '\n');
@ -59,7 +59,7 @@ Ox.SyntaxHighlighter = function(options, self) {
!(self.options.stripComments && token.type == 'comment') !(self.options.stripComments && token.type == 'comment')
) { ) {
classNames = 'Ox' + Ox.toTitleCase(token.type); classNames = 'Ox' + Ox.toTitleCase(token.type);
if (self.options.showSpaces && token.type == 'whitespace') { if (self.options.showWhitespace && token.type == 'whitespace') {
if (isAfterLinebreak() && hasIrregularSpaces()) { if (isAfterLinebreak() && hasIrregularSpaces()) {
classNames += ' OxLeading' classNames += ' OxLeading'
} else if (isBeforeLinebreak()) { } else if (isBeforeLinebreak()) {
@ -100,11 +100,6 @@ Ox.SyntaxHighlighter = function(options, self) {
} }
$source = new Ox.Element() $source = new Ox.Element()
.addClass('OxSourceCode') .addClass('OxSourceCode')
.css({
background: '-webkit-linear-gradient(left, rgb(255, 255, 255) ' +
width + 'px, rgb(192, 192, 192) ' + width + 'px, rgb(255, 255, 255) ' +
(width + 1) + 'px)'
})
.html(source) .html(source)
.appendTo(that); .appendTo(that);
if (self.options.lineLength) { if (self.options.lineLength) {