cleanup
This commit is contained in:
parent
978d32eca3
commit
8a75cdca13
2 changed files with 88 additions and 102 deletions
|
|
@ -32,32 +32,22 @@
|
||||||
function wobble (flam) {
|
function wobble (flam) {
|
||||||
return flam.wobbled = true;
|
return flam.wobbled = true;
|
||||||
}
|
}
|
||||||
// I'm not exactly sure how to
|
|
||||||
// turn on softwrap like effects.
|
|
||||||
var longString = 'this will not wrap ******************************************';
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// the scrollbars are from overflow auto on .ace_editor.
|
// the scrollbars are from overflow auto on .ace_editor.
|
||||||
|
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
<script src="../../build/src-noconflict/ace.js" type="text/javascript" charset="utf-8"></script>
|
<script src="../../build/src-noconflict/ace.js"></script>
|
||||||
<script src="../../build/src-noconflict/ext-static_highlight.js" type="text/javascript" charset="utf-8"></script>
|
<script src="../../build/src-noconflict/ext-static_highlight.js"></script>
|
||||||
|
|
||||||
<script type="text/javascript" charset="utf-8">
|
<script>
|
||||||
(function () {
|
var highlighter = ace.require("ace/ext/static_highlight")
|
||||||
|
var dom = ace.require("ace/lib/dom")
|
||||||
ace.require([
|
function qsa(sel) {
|
||||||
"ace/ext/static_highlight",
|
return [].slice.call(document.querySelectorAll(sel));
|
||||||
"ace/lib/dom"
|
}
|
||||||
], function(highlighter, dom) {
|
|
||||||
var codeEls = Array.prototype.slice.call(
|
|
||||||
document.getElementsByClassName('code')
|
|
||||||
);
|
|
||||||
codeEls.forEach(function (codeEl) {
|
|
||||||
|
|
||||||
|
qsa(".code").forEach(function (codeEl) {
|
||||||
var cs = getComputedStyle(codeEl);
|
var cs = getComputedStyle(codeEl);
|
||||||
codeEl.style.cssText = codeEl.style.cssText +
|
codeEl.style.cssText = codeEl.style.cssText +
|
||||||
'width: ' + cs.width + ';' +
|
'width: ' + cs.width + ';' +
|
||||||
|
|
@ -67,7 +57,6 @@ ace.require([
|
||||||
var data = codeEl.textContent.trim();
|
var data = codeEl.textContent.trim();
|
||||||
|
|
||||||
highlighter.render(data, mode, theme, 1, false, function (highlighted) {
|
highlighter.render(data, mode, theme, 1, false, function (highlighted) {
|
||||||
|
|
||||||
dom.importCssString(highlighted.css, "ace_highlight");
|
dom.importCssString(highlighted.css, "ace_highlight");
|
||||||
dom.importCssString('.ace_editor { overflow: auto; ' +
|
dom.importCssString('.ace_editor { overflow: auto; ' +
|
||||||
'position:absolute; top:0; bottom:0; right:0; left:0; }' +
|
'position:absolute; top:0; bottom:0; right:0; left:0; }' +
|
||||||
|
|
@ -75,10 +64,7 @@ ace.require([
|
||||||
'atropa_hial');
|
'atropa_hial');
|
||||||
codeEl.innerHTML = highlighted.html;
|
codeEl.innerHTML = highlighted.html;
|
||||||
});
|
});
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
}());
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
|
|
||||||
|
|
@ -56,48 +56,49 @@ var config = require("../config");
|
||||||
*/
|
*/
|
||||||
|
|
||||||
exports.render = function(input, mode, theme, lineStart, disableGutter, callback) {
|
exports.render = function(input, mode, theme, lineStart, disableGutter, callback) {
|
||||||
lineStart = parseInt(lineStart || 1, 10);
|
var waiting = 0
|
||||||
|
|
||||||
// if theme and mode are both objects return the expected object.
|
|
||||||
// preserves current behavior of giving mode and theme objects
|
|
||||||
if(typeof theme !== 'string' && typeof mode !== 'string') {
|
|
||||||
return renderer(mode, theme);
|
|
||||||
}
|
|
||||||
|
|
||||||
// if either the theme or the mode were specified as objects
|
// if either the theme or the mode were specified as objects
|
||||||
// then we need to lazily load them.
|
// then we need to lazily load them.
|
||||||
|
|
||||||
// loads or passes the specified theme module then loads the mode.
|
|
||||||
if (typeof theme == "string") {
|
if (typeof theme == "string") {
|
||||||
config.loadModule(['theme', theme], function (theme) {
|
waiting++;
|
||||||
checkMode(theme);
|
config.loadModule(['theme', theme], function (m) {
|
||||||
|
theme = m;
|
||||||
|
--waiting || done();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof mode == "string") {
|
||||||
|
waiting++;
|
||||||
|
config.loadModule(['mode', mode], function (m) {
|
||||||
|
mode = new m.Mode()
|
||||||
|
--waiting || done();
|
||||||
});
|
});
|
||||||
} else {
|
|
||||||
// if theme was given as an object pass it through.
|
|
||||||
checkMode(theme);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// loads or passes the specified mode module then calls renderer
|
// loads or passes the specified mode module then calls renderer
|
||||||
function checkMode (theme) {
|
function done() {
|
||||||
if (typeof mode == "string") {
|
var result = exports.renderSync(input, mode, theme, lineStart, disableGutter);
|
||||||
config.loadModule(['mode', mode], function (mode) {
|
return callback ? callback(result) : result;
|
||||||
callback(renderer(new mode.Mode(), theme));
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
// if mode was given as an object pass it through.
|
|
||||||
callback(renderer(mode, theme));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
return waiting || done();
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Transforms a given input code snippet into HTML using the given mode
|
||||||
|
*
|
||||||
|
* @param {string} input Code snippet
|
||||||
|
* @param {mode} mode Mode loaded from /ace/mode (use 'ServerSideHiglighter.getMode')
|
||||||
|
* @param {string} r Code snippet
|
||||||
|
* @returns {object} An object containing: html, css
|
||||||
|
*/
|
||||||
|
|
||||||
|
exports.renderSync = function(input, mode, theme, lineStart, disableGutter) {
|
||||||
|
lineStart = parseInt(lineStart || 1, 10);
|
||||||
|
|
||||||
// this was previously the body of exports.render
|
|
||||||
// exports.render does the same thing it did before but now
|
|
||||||
// if you give it mode or theme as strings you must specify a callback
|
|
||||||
// which will receive the return value of renderer.
|
|
||||||
// specifying the mode or theme as a string did not work before.
|
|
||||||
function renderer (mode, theme) {
|
|
||||||
var session = new EditSession("");
|
var session = new EditSession("");
|
||||||
session.setMode(mode);
|
|
||||||
session.setUseWorker(false);
|
session.setUseWorker(false);
|
||||||
|
session.setMode(mode);
|
||||||
|
|
||||||
var textLayer = new TextLayer(document.createElement("div"));
|
var textLayer = new TextLayer(document.createElement("div"));
|
||||||
textLayer.setSession(session);
|
textLayer.setSession(session);
|
||||||
textLayer.config = {
|
textLayer.config = {
|
||||||
|
|
@ -131,7 +132,6 @@ exports.render = function(input, mode, theme, lineStart, disableGutter, callback
|
||||||
css: baseStyles + theme.cssText,
|
css: baseStyles + theme.cssText,
|
||||||
html: html
|
html: html
|
||||||
};
|
};
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue