'use strict'; Ox.SourceViewer = function(options, self) { self = self || {}; var that = Ox.Container({}, self) .defaults({ file: '', replace: [] }) .options(options) .addClass('OxSourceViewer'); self.replace = Ox.merge( [[ // removes indentation inside
tags
/([\s\S]+)<\/pre>/g,
function(pre, text) {
var lines = trim(text).split('\n'),
indent = Ox.min(lines.map(function(line) {
var match = line.match(/^\s+/);
return match ? match[0].length : 0;
}));
return '' + lines.map(function(line) {
return line.substr(indent);
}).join('\n') + '';
}
]],
self.options.replace
);
Ox.print('RE', self.replace)
self.$table = $('| ') .addClass('OxComment') .html(trim(section.comment)), $code = $(' | ') .addClass('OxCode') .append( Ox.SyntaxHighlighter({ source: trim(section.code) }) ) $section .append($comment) .append($code) .appendTo(self.$table); }); }); function trim(str) { // removes leading or trailing empty line return str.replace(/^\s*\n/, '').replace(/\n\s*$/, ''); } return that; }; |