fix formatting bugs related to optional replacements

This commit is contained in:
rolux 2012-05-29 12:14:58 +02:00
parent 8cd27bca2f
commit b151a0c9a8

View file

@ -45,7 +45,7 @@ Ox.SourceViewer = function(options, self) {
if (!/^\/\//.test(token.value)) {
if (type == 'comment') {
i && sections.push({comment: '', code: ''});
token.value = token.value.slice(2, -2);
token.value = expand(trim(token.value.slice(2, -2)));
self.options.replaceComment.forEach(function(replace) {
token.value = token.value.replace(
replace[0], replace[1]
@ -60,7 +60,7 @@ Ox.SourceViewer = function(options, self) {
.appendTo(self.$table),
$comment = $('<td>')
.addClass('OxComment OxSerif')
.html(quote(trim(section.comment)))
.html(Ox.addLinks(section.comment, true))
.appendTo($section),
$code = $('<td>')
.addClass('OxCode')
@ -74,8 +74,10 @@ Ox.SourceViewer = function(options, self) {
});
});
function quote(str) {
return str.replace(/\s`(.*?)`/g, ' <code>$1</code>')
function expand(str) {
return str.replace(/(\W)`([\s\S]+?)`/g, function(match, outer, inner) {
return outer + '<code>' + Ox.encodeHTMLEntities(inner) + '</code>';
})
}
function trim(str) {