mirror of
https://github.com/markedjs/marked.git
synced 2026-12-01 16:56:16 +01:00
quick and dirty test interface for clientside
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
<!doctype html>
|
||||
<title>marked tests</title>
|
||||
<p>testing...</p>
|
||||
<script src="marked.js"></script>
|
||||
<script src="test.js"></script>
|
||||
@@ -0,0 +1,40 @@
|
||||
var fs = require('fs');
|
||||
|
||||
var main = require('../')
|
||||
, load = main.load;
|
||||
|
||||
var express = require('express')
|
||||
, app = express.createServer();
|
||||
|
||||
app.use(function(req, res, next) {
|
||||
var setHeader = res.setHeader;
|
||||
res.setHeader = function(name) {
|
||||
switch (name) {
|
||||
case 'Cache-Control':
|
||||
case 'Last-Modified':
|
||||
case 'ETag':
|
||||
return;
|
||||
}
|
||||
return setHeader.apply(res, arguments);
|
||||
};
|
||||
next();
|
||||
});
|
||||
|
||||
var dir = __dirname + '/../tests'
|
||||
, files = {};
|
||||
|
||||
app.get('/test.js', function(req, res, next) {
|
||||
var test = fs.readFileSync(__dirname + '/test.js', 'utf8')
|
||||
, files = load();
|
||||
|
||||
test = test.replace('__TESTS__', JSON.stringify(files));
|
||||
test = test.replace('__MAIN__', main + '');
|
||||
|
||||
res.contentType('.js');
|
||||
res.send(test);
|
||||
});
|
||||
|
||||
app.use(express.static(__dirname + '/../../lib'));
|
||||
app.use(express.static(__dirname));
|
||||
|
||||
app.listen(8080);
|
||||
@@ -0,0 +1,57 @@
|
||||
;(function() {
|
||||
|
||||
var files = __TESTS__;
|
||||
|
||||
var BREAK_ON_ERROR = false;
|
||||
|
||||
var print = function(text) {
|
||||
var args = Array.prototype.slice.call(arguments, 1)
|
||||
, i = 0;
|
||||
|
||||
text = text.replace(/%\w/g, function() {
|
||||
return args[i++] || '';
|
||||
});
|
||||
|
||||
if (window.console) window.console.log(text);
|
||||
document.body.innerHTML += '<pre>' + escape(text) + '</pre>';
|
||||
};
|
||||
|
||||
var console = { log: print };
|
||||
|
||||
var pretty = function(text) {
|
||||
return text;
|
||||
};
|
||||
|
||||
var load = function() {};
|
||||
|
||||
Object.keys = Object.keys || function(obj) {
|
||||
var out = []
|
||||
, key;
|
||||
|
||||
for (key in obj) {
|
||||
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
||||
out.push(key);
|
||||
}
|
||||
}
|
||||
|
||||
return out;
|
||||
};
|
||||
|
||||
String.prototype.trim = String.prototype.trim || function() {
|
||||
return this.replace(/^\s+|\s+$/g, '');
|
||||
};
|
||||
|
||||
var escape = function(html, encode) {
|
||||
return html
|
||||
.replace(!encode ? /&(?!#?\w+;)/g : /&/g, '&')
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/"/g, '"')
|
||||
.replace(/'/g, ''');
|
||||
};
|
||||
|
||||
var main = __MAIN__;
|
||||
|
||||
main();
|
||||
|
||||
}).call(this);
|
||||
@@ -34,6 +34,8 @@ var load = function() {
|
||||
html: fs.readFileSync(file.replace(/[^.]+$/, 'html'), 'utf8')
|
||||
};
|
||||
}
|
||||
|
||||
return files;
|
||||
};
|
||||
|
||||
var main = function() {
|
||||
@@ -290,5 +292,6 @@ if (!module.parent) {
|
||||
main();
|
||||
}
|
||||
} else {
|
||||
main.load = load;
|
||||
module.exports = main;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user