fix #2484 Hard-coded characterWidth in static_highlight.js
and remove dependence on mockdom
This commit is contained in:
parent
1514d5f374
commit
2249d06337
3 changed files with 21 additions and 14 deletions
|
|
@ -2,15 +2,13 @@
|
||||||
* Simple node.js server, which generates the synax highlighted version of itself
|
* Simple node.js server, which generates the synax highlighted version of itself
|
||||||
* using the Ace modes and themes on the server and serving a static web page.
|
* using the Ace modes and themes on the server and serving a static web page.
|
||||||
*/
|
*/
|
||||||
// $'
|
|
||||||
// include ace search path and modules
|
// include ace search path and modules
|
||||||
require("amd-loader");
|
require("amd-loader");
|
||||||
|
|
||||||
// load jsdom, which is required by Ace
|
|
||||||
require("../../lib/ace/test/mockdom");
|
|
||||||
|
|
||||||
var http = require("http");
|
var http = require("http");
|
||||||
var fs = require("fs");
|
var fs = require("fs");
|
||||||
|
var resolve = require("path").resolve;
|
||||||
|
|
||||||
// load the highlighter and the desired mode and theme
|
// load the highlighter and the desired mode and theme
|
||||||
var highlighter = require("../../lib/ace/ext/static_highlight");
|
var highlighter = require("../../lib/ace/ext/static_highlight");
|
||||||
|
|
@ -20,8 +18,15 @@ var theme = require("../../lib/ace/theme/twilight");
|
||||||
var port = process.env.PORT || 2222;
|
var port = process.env.PORT || 2222;
|
||||||
|
|
||||||
http.createServer(function(req, res) {
|
http.createServer(function(req, res) {
|
||||||
|
var url = req.url;
|
||||||
|
var path = /[^#?\x00]*/.exec(url)[0];
|
||||||
|
var root = resolve(__dirname + "/../../").replace(/\\/g, "/");
|
||||||
|
path = resolve(root + "/" + path).replace(/\\/g, "/");
|
||||||
|
if (path.indexOf(root + "/") != 0)
|
||||||
|
path = __filename;
|
||||||
res.writeHead(200, {"Content-Type": "text/html; charset=utf-8"});
|
res.writeHead(200, {"Content-Type": "text/html; charset=utf-8"});
|
||||||
fs.readFile(__dirname + "/../../build/src/ace.js", "utf8", function(err, data) {
|
fs.readFile(path, "utf8", function(err, data) {
|
||||||
|
if (err) data = err.message;
|
||||||
var highlighted = highlighter.render(data, new JavaScriptMode(), theme);
|
var highlighted = highlighter.render(data, new JavaScriptMode(), theme);
|
||||||
res.end(
|
res.end(
|
||||||
'<html><body>\n' +
|
'<html><body>\n' +
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,10 @@ var baseStyles = require("../requirejs/text!./static.css");
|
||||||
var config = require("../config");
|
var config = require("../config");
|
||||||
var dom = require("../lib/dom");
|
var dom = require("../lib/dom");
|
||||||
|
|
||||||
|
var SimpleTextLayer = function() {
|
||||||
|
this.config = {};
|
||||||
|
};
|
||||||
|
SimpleTextLayer.prototype = TextLayer.prototype;
|
||||||
|
|
||||||
var highlight = function(el, opts, callback) {
|
var highlight = function(el, opts, callback) {
|
||||||
var m = el.className.match(/lang-(\w+)/);
|
var m = el.className.match(/lang-(\w+)/);
|
||||||
|
|
@ -149,12 +153,8 @@ highlight.renderSync = function(input, mode, theme, lineStart, disableGutter) {
|
||||||
session.setUseWorker(false);
|
session.setUseWorker(false);
|
||||||
session.setMode(mode);
|
session.setMode(mode);
|
||||||
|
|
||||||
var textLayer = new TextLayer(document.createElement("div"));
|
var textLayer = new SimpleTextLayer();
|
||||||
textLayer.setSession(session);
|
textLayer.setSession(session);
|
||||||
textLayer.config = {
|
|
||||||
characterWidth: 10,
|
|
||||||
lineHeight: 20
|
|
||||||
};
|
|
||||||
|
|
||||||
session.setValue(input);
|
session.setValue(input);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -91,6 +91,11 @@ exports.toggleCssClass = function(el, name) {
|
||||||
return add;
|
return add;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (typeof document == "undefined") {
|
||||||
|
exports.importCssString = function() {};
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Add or remove a CSS class from the list of classes on the given node
|
* Add or remove a CSS class from the list of classes on the given node
|
||||||
* depending on the value of <tt>include</tt>
|
* depending on the value of <tt>include</tt>
|
||||||
|
|
@ -173,9 +178,6 @@ exports.getInnerHeight = function(element) {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
if (typeof document == "undefined")
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (window.pageYOffset !== undefined) {
|
if (window.pageYOffset !== undefined) {
|
||||||
exports.getPageScrollTop = function() {
|
exports.getPageScrollTop = function() {
|
||||||
return window.pageYOffset;
|
return window.pageYOffset;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue