forked from 0x2620/oxjs
make SyntaxHighlighter and SourceViewer more useful by allowing replacements; remove index.json and source/Ox/png; plus some other small and/or cosmetic changes
This commit is contained in:
parent
24eb4bdc64
commit
03f4f77ce6
16 changed files with 213 additions and 230 deletions
|
|
@ -6,14 +6,15 @@ Ox.SourceViewer = function(options, self) {
|
|||
var that = Ox.Container({}, self)
|
||||
.defaults({
|
||||
file: '',
|
||||
replace: []
|
||||
replaceCode: [],
|
||||
replaceComment: [],
|
||||
})
|
||||
.options(options)
|
||||
.addClass('OxSourceViewer');
|
||||
|
||||
self.replace = Ox.merge(
|
||||
[[
|
||||
// removes indentation inside <pre> tags
|
||||
self.options.replaceComment.unshift(
|
||||
// removes indentation inside <pre> tags
|
||||
[
|
||||
/<pre>([\s\S]+)<\/pre>/g,
|
||||
function(pre, text) {
|
||||
var lines = trim(text).split('\n'),
|
||||
|
|
@ -25,10 +26,8 @@ Ox.SourceViewer = function(options, self) {
|
|||
return line.substr(indent);
|
||||
}).join('\n') + '</pre>';
|
||||
}
|
||||
]],
|
||||
self.options.replace
|
||||
]
|
||||
);
|
||||
Ox.print('RE', self.replace)
|
||||
|
||||
self.$table = $('<table>').appendTo(that.$content);
|
||||
|
||||
|
|
@ -42,28 +41,28 @@ Ox.SourceViewer = function(options, self) {
|
|||
text = /^\/\*/.test(text)
|
||||
? Ox.sub(text, 2, -2)
|
||||
: Ox.sub(text, 2);
|
||||
self.replace.forEach(function(replace) {
|
||||
self.options.replaceComment.forEach(function(replace) {
|
||||
text = text.replace(replace[0], replace[1]);
|
||||
});
|
||||
}
|
||||
Ox.last(sections)[type] += text;
|
||||
});
|
||||
sections.forEach(function(section) {
|
||||
var $section = $('<tr>'),
|
||||
var $section = $('<tr>')
|
||||
.appendTo(self.$table),
|
||||
$comment = $('<td>')
|
||||
.addClass('OxComment')
|
||||
.html(trim(section.comment)),
|
||||
.addClass('OxComment OxSerif')
|
||||
.html(trim(section.comment))
|
||||
.appendTo($section),
|
||||
$code = $('<td>')
|
||||
.addClass('OxCode')
|
||||
.append(
|
||||
Ox.SyntaxHighlighter({
|
||||
replace: self.options.replaceCode,
|
||||
source: trim(section.code)
|
||||
})
|
||||
)
|
||||
$section
|
||||
.append($comment)
|
||||
.append($code)
|
||||
.appendTo(self.$table);
|
||||
.appendTo($section);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue