Skip to content

Commit

Permalink
Added tests, removed some non-module scaffolding, and added generic '…
Browse files Browse the repository at this point in the history
…encode' export.
  • Loading branch information
kriskowal committed Aug 2, 2009
1 parent 88992bd commit 861ef73
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 22 deletions.
32 changes: 10 additions & 22 deletions lib/markdown.js
Expand Up @@ -51,29 +51,16 @@
//
// var text = "Markdown *rocks*.";
//
// var converter = new Showdown.converter();
// var html = converter.makeHtml(text);
// var markdown = require("markdown");
// var html = markdown.encode(text);
//
// alert(html);
// print(html);
//
// Note: move the sample code to the bottom of this
// file before uncommenting it.
//


//
// Showdown namespace
//
var Showdown = {};

//
// converter
//
// Wraps all "globals" so that the only thing
// exposed is makeHtml().
//
Showdown.converter = function() {

//
// Globals:
//
Expand All @@ -88,7 +75,7 @@ var g_html_blocks;
var g_list_level = 0;


this.makeHtml = function(text) {
exports.makeHtml = function(text) {
//
// Main function. The order in which other subs are called here is
// essential. Link and image substitutions need to happen before
Expand Down Expand Up @@ -1293,10 +1280,11 @@ var escapeCharacters_callback = function(wholeMatch,m1) {
return "~E"+charCodeToEscape+"E";
}

} // end of Showdown.converter
exports.markdown = function(src) {
return exports.makeHtml(src);
};

exports.Markdown = Showdown.converter;
exports.encode = function (src) {
return exports.makeHtml(src);
};

exports.markdown = function(src) {
return new Showdown.converter().makeHtml(src);
}
13 changes: 13 additions & 0 deletions tests/all-tests.js
@@ -0,0 +1,13 @@
var assert = require("test/assert");
var markdown = require("markdown");

exports.testH1 = function () {
assert.eq("<h1>Hi</h1>", markdown.encode("Hi\n="));
};

exports.testP = function () {
assert.eq("<p>Paragraph.</p>", markdown.markdown("Paragraph."));
};

if (require.main === module.id)
require("os").exit(require("test/runner").run(exports));

0 comments on commit 861ef73

Please sign in to comment.