Skip to content

Commit 4a3c745

Browse files
committed
Remove support for layouts, tab -> space conversion, as CSS now handles everything required to display code correctly.
1 parent 55e45d0 commit 4a3c745

35 files changed

+141
-644
lines changed

examples/wrapping.html

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<style>
5+
pre {
6+
-white-space: pre-wrap;
7+
}
8+
9+
.line {
10+
background-color: blue;
11+
overflow: hidden;
12+
display: block;
13+
}
14+
15+
.indent {
16+
background-color: lightblue;
17+
display: block;
18+
float: left;
19+
}
20+
21+
.text {
22+
background-color: #cfc;
23+
white-space: normal;
24+
display: block;
25+
overflow: hidden;
26+
27+
padding-left: 2em;
28+
text-indent: -2em;
29+
}
30+
</style>
31+
</head>
32+
<body>
33+
<pre><span class="line"><span class="indent"> </span><span class="text">foo = bar foo = bar foo = bar foo = bar foo = bar foo = bar foo = bar foo = bar foo = bar foo = bar foo = bar</span></span>
34+
</pre>
35+
</body>
36+
</html>

install.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ prefix: "dist"
33
# The options for the stylesheet generation
44
themes:
55
- base
6-
- grey
7-
- modern
86
- bright
97
- paper
108
# Enable minification

source/jquery.syntax.core.js

Lines changed: 52 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -79,73 +79,6 @@ Syntax.extractElementMatches = function (elems, offset) {
7979
return matches;
8080
}
8181

82-
// Basic layout doesn't do anything e.g. identity layout.
83-
Syntax.layouts.preformatted = function (options, html, container) {
84-
return html;
85-
};
86-
87-
88-
// This function converts from a compressed set of offsets of the form:
89-
// [
90-
// [offset, width, totalOffset],
91-
// ...
92-
// ]
93-
// This means that at a $offset, a tab (single character) was expanded to $width
94-
// single space characters.
95-
// This function produces a lookup table of offsets, where a given character offset
96-
// is mapped to how far the character has been offset.
97-
Syntax.convertToLinearOffsets = function (offsets, length) {
98-
var current = 0, changes = [];
99-
100-
// Anything with offset after offset[current][0] but smaller than offset[current+1][0]
101-
// has been shifted right by offset[current][2]
102-
for (var i = 0; i < length; i++) {
103-
if (offsets[current] && i > offsets[current][0]) {
104-
// Is there a next offset?
105-
if (offsets[current+1]) {
106-
// Is the index less than the start of the next offset?
107-
if (i <= offsets[current+1][0]) {
108-
changes.push(offsets[current][2]);
109-
} else {
110-
// If so, move to the next offset.
111-
current += 1;
112-
i -= 1;
113-
}
114-
} else {
115-
// If there is no next offset we assume this one to the end.
116-
changes.push(offsets[current][2]);
117-
}
118-
} else {
119-
changes.push(changes[changes.length-1] || 0);
120-
}
121-
}
122-
123-
return changes;
124-
}
125-
126-
// Used for tab expansion process, by shifting matches when tab charaters were converted to
127-
// spaces.
128-
Syntax.updateMatchesWithOffsets = function (matches, linearOffsets, text) {
129-
(function (matches) {
130-
for (var i = 0; i < matches.length; i++) {
131-
var match = matches[i];
132-
133-
// Calculate the new start and end points
134-
var offset = match.offset + linearOffsets[match.offset];
135-
var end = match.offset + match.length;
136-
end += linearOffsets[end];
137-
138-
// Start, Length, Text
139-
match.adjust(linearOffsets[match.offset], end - offset, text);
140-
141-
if (match.children.length > 0)
142-
arguments.callee(match.children);
143-
}
144-
})(matches);
145-
146-
return matches;
147-
};
148-
14982
// A helper function which automatically matches expressions with capture groups from the regular expression match.
15083
// Each argument position corresponds to the same index regular expression group.
15184
// Or, override by providing rule.index
@@ -314,6 +247,11 @@ Syntax.Match.prototype.reduce = function (append, process) {
314247
container.className += this.expression.klass;
315248
}
316249

250+
if (this.className) {
251+
container.className += ' ';
252+
container.className += this.className;
253+
}
254+
317255
for (var i = 0; i < this.children.length; i += 1) {
318256
var child = this.children[i], end = child.offset;
319257

@@ -773,6 +711,31 @@ Syntax.Match.prototype.split = function(pattern) {
773711
});
774712
};
775713

714+
Syntax.Match.prototype.splitLines = function() {
715+
var lines = this.split(/\n/g);
716+
717+
for (var i = 0; i < lines.length; i += 1) {
718+
var line = lines[i];
719+
var indentOffset = line.value.search(/\S/);
720+
721+
var top = new Syntax.Match(line.offset, line.length, line.expression, line.value);
722+
723+
if (indentOffset > 0) {
724+
var parts = line.bisectAtOffsets([line.offset + indentOffset]);
725+
top.children = parts;
726+
parts[0].expression = {klass: 'indent'};
727+
parts[1].expression = {klass: 'text'};
728+
} else {
729+
line.expression = {klass: 'text'};
730+
top.children = [line];
731+
}
732+
733+
lines[i] = top;
734+
}
735+
736+
return lines;
737+
}
738+
776739
Syntax.Brush = function () {
777740
// The primary class of this brush. Must be unique.
778741
this.klass = null;
@@ -795,7 +758,7 @@ Syntax.Brush.prototype.derives = function (name) {
795758
return Syntax.brushes[name].getMatches(text);
796759
}
797760
});
798-
}
761+
};
799762

800763
// Return an array of all classes that the brush consists of.
801764
// A derivied brush is its own klass + the klass of any and all parents.
@@ -1003,7 +966,7 @@ Syntax.Brush.prototype.buildTree = function(text, offset, additionalMatches) {
1003966
Syntax.Brush.prototype.process = function(text, matches, options) {
1004967
var top = this.buildTree(text, 0, matches);
1005968

1006-
var lines = top.split(/\n/g);
969+
var lines = top.splitLines();
1007970

1008971
var html = document.createElement('code');
1009972
html.className = 'syntax';
@@ -1102,37 +1065,31 @@ Syntax.highlight = function (elements, options, callback) {
11021065
}
11031066

11041067
Syntax.highlightText(text, brush, matches, options, function(html, brush/*, text, options*/) {
1105-
Syntax.layouts.get(options.layout, function(layout) {
1106-
if (layout) {
1107-
html = layout(options, jQuery(html), container);
1108-
} else {
1109-
html = jQuery(html);
1110-
}
1111-
1112-
// If there is a theme specified, ensure it is added to the top level class.
1113-
if (options.theme) {
1114-
// Load dependencies
1115-
var themes = Syntax.themes[options.theme];
1116-
for (var i = 0; i < themes.length; i += 1) {
1117-
html.addClass("syntax-theme-" + themes[i]);
1118-
}
1068+
html = jQuery(html);
11191069

1120-
// Add the base theme
1121-
html.addClass("syntax-theme-" + options.theme);
1070+
// If there is a theme specified, ensure it is added to the top level class.
1071+
if (options.theme) {
1072+
// Load dependencies
1073+
var themes = Syntax.themes[options.theme];
1074+
for (var i = 0; i < themes.length; i += 1) {
1075+
html.addClass("syntax-theme-" + themes[i]);
11221076
}
11231077

1124-
if (brush.postprocess) {
1125-
html = brush.postprocess(options, html, container);
1126-
}
1078+
// Add the base theme
1079+
html.addClass("syntax-theme-" + options.theme);
1080+
}
11271081

1128-
if (callback) {
1129-
html = callback(options, html, container);
1130-
}
1082+
if (brush.postprocess) {
1083+
html = brush.postprocess(options, html, container);
1084+
}
11311085

1132-
if (html && options.replace === true) {
1133-
container.replaceWith(html);
1134-
}
1135-
});
1086+
if (callback) {
1087+
html = callback(options, html, container);
1088+
}
1089+
1090+
if (html && options.replace === true) {
1091+
container.replaceWith(html);
1092+
}
11361093
});
11371094
});
11381095
};

source/jquery.syntax.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,6 @@ var Syntax = {
129129
Syntax.getResource('jquery.syntax.brush', name, callback);
130130
}),
131131

132-
layouts: new ResourceLoader(function (name, callback) {
133-
Syntax.getResource('jquery.syntax.layout', name, callback);
134-
}),
135-
136132
loader: new ResourceLoader(function (name, callback) {
137133
Syntax.getResource('jquery.syntax', name, callback);
138134
}),

source/jquery.syntax.layout.fixed.js

Lines changed: 0 additions & 55 deletions
This file was deleted.

source/jquery.syntax.layout.inline.js

Lines changed: 0 additions & 13 deletions
This file was deleted.

source/jquery.syntax.layout.list.js

Lines changed: 0 additions & 54 deletions
This file was deleted.

source/jquery.syntax.layout.plain.js

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)