Merge pull request #2070 from ajaxorg/static-highlight

accept mode options object in static highlight extension
This commit is contained in:
Lennart Kats 2014-08-10 10:50:32 +02:00
commit 4b5409c5cb

View file

@ -98,7 +98,6 @@ var highlight = function(el, opts, callback) {
* and `css`. * and `css`.
* @returns {object} An object containing the properties `html` and `css`. * @returns {object} An object containing the properties `html` and `css`.
*/ */
highlight.render = function(input, mode, theme, lineStart, disableGutter, callback) { highlight.render = function(input, mode, theme, lineStart, disableGutter, callback) {
var waiting = 1; var waiting = 1;
var modeCache = EditSession.prototype.$modes; var modeCache = EditSession.prototype.$modes;
@ -112,11 +111,17 @@ highlight.render = function(input, mode, theme, lineStart, disableGutter, callba
--waiting || done(); --waiting || done();
}); });
} }
// allow setting mode options e.h {path: "ace/mode/php", inline:true}
var modeOptions;
if (mode && typeof mode === "object" && !mode.getTokenizer) {
modeOptions = mode;
mode = modeOptions.path;
}
if (typeof mode == "string") { if (typeof mode == "string") {
waiting++; waiting++;
config.loadModule(['mode', mode], function(m) { config.loadModule(['mode', mode], function(m) {
if (!modeCache[mode]) modeCache[mode] = new m.Mode(); if (!modeCache[mode] || modeOptions)
modeCache[mode] = new m.Mode(modeOptions);
mode = modeCache[mode]; mode = modeCache[mode];
--waiting || done(); --waiting || done();
}); });
@ -130,14 +135,13 @@ highlight.render = function(input, mode, theme, lineStart, disableGutter, callba
return --waiting || done(); return --waiting || done();
}; };
/* /**
* Transforms a given input code snippet into HTML using the given mode * Transforms a given input code snippet into HTML using the given mode
* @param {string} input Code snippet * @param {string} input Code snippet
* @param {mode} mode Mode loaded from /ace/mode (use 'ServerSideHiglighter.getMode') * @param {mode} mode Mode loaded from /ace/mode (use 'ServerSideHiglighter.getMode')
* @param {string} r Code snippet * @param {string} r Code snippet
* @returns {object} An object containing: html, css * @returns {object} An object containing: html, css
*/ */
highlight.renderSync = function(input, mode, theme, lineStart, disableGutter) { highlight.renderSync = function(input, mode, theme, lineStart, disableGutter) {
lineStart = parseInt(lineStart || 1, 10); lineStart = parseInt(lineStart || 1, 10);