Skip to content

Commit 0908a26

Browse files
committed
Reduced dependency on jQuery slightly, improved performance.
1 parent ca73b91 commit 0908a26

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

source/jquery.syntax.core.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -301,21 +301,22 @@ Syntax.Match.defaultReduceCallback = function (node, container) {
301301
// Using jQuery jQuery.fn.append() can reduce performance by as much as 1/3rd.
302302
if (typeof(node) === 'string') {
303303
node = document.createTextNode(node);
304-
} else {
305-
node = node[0];
306304
}
307305

308-
container[0].appendChild(node);
306+
container.appendChild(node);
309307
};
310308

311309
Syntax.Match.prototype.reduce = function (append, process) {
312310
var start = this.offset;
313-
var container = jQuery('<span></span>');
311+
var container = document.createElement('span');
314312

315313
append = append || Syntax.Match.defaultReduceCallback;
316314

317315
if (this.expression && this.expression.klass) {
318-
container.addClass(this.expression.klass);
316+
if (container.className.length > 0)
317+
container.className += ' ';
318+
319+
container.className += this.expression.klass;
319320
}
320321

321322
for (var i = 0; i < this.children.length; i += 1) {
@@ -968,7 +969,8 @@ Syntax.Brush.prototype.process = function(text, matches) {
968969

969970
var lines = top.split(/\n/g);
970971

971-
var html = jQuery('<pre class="syntax"></pre>');
972+
var html = document.createElement('pre');
973+
html.className = 'syntax';
972974

973975
for (var i = 0; i < lines.length; i += 1) {
974976
var line = lines[i].reduce(null, function (container, match) {
@@ -987,7 +989,7 @@ Syntax.Brush.prototype.process = function(text, matches) {
987989
return container;
988990
});
989991

990-
html.append(line);
992+
html.appendChild(line);
991993
}
992994

993995
return html;
@@ -1065,7 +1067,7 @@ Syntax.highlight = function (elements, options, callback) {
10651067

10661068
Syntax.highlightText(text, options, function(html, brush/*, text, options*/) {
10671069
Syntax.layouts.get(options.layout, function(layout) {
1068-
html = layout(options, html, container);
1070+
html = layout(options, $(html), $(container));
10691071

10701072
// If there is a theme specified, ensure it is added to the top level class.
10711073
if (options.theme) {

0 commit comments

Comments
 (0)