UNPKG

2.99 kBJavaScriptView Raw
1var wmd = require('../lib/wmd');
2
3
4exports['processor'] = function (test) {
5 test.equals(
6 wmd.processor('Markdown *rocks*.'),
7 '<p>Markdown <em>rocks</em>.</p>'
8 );
9 test.done();
10};
11
12exports['preprocess'] = function (test) {
13 test.expect(3);
14 var options = {
15 preprocessors: [
16 function (content) {
17 test.equals(content, 'original markdown');
18 return 'preprocessor 1';
19 },
20 function (content) {
21 test.equals(content, 'preprocessor 1');
22 return 'preprocessor 2';
23 }
24 ]
25 };
26 test.equals(wmd.preprocess('original markdown', options), 'preprocessor 2');
27 test.done();
28};
29
30exports['postprocess'] = function (test) {
31 test.expect(3);
32 var options = {
33 postprocessors: [
34 function (doc) {
35 test.equals(doc, 'markdown');
36 return 'postprocessor 1';
37 },
38 function (doc) {
39 test.equals(doc, 'postprocessor 1');
40 return 'postprocessor 2';
41 }
42 ]
43 };
44 test.equals(
45 wmd.postprocess('markdown', options),
46 'postprocessor 2'
47 );
48 test.done();
49};
50
51exports['wmd'] = function (test) {
52 test.expect(10);
53
54 // create a copy of all exported functions so we can safely stub them
55 var _readOptions = wmd.readOptions;
56 var _preprocess = wmd.preprocess;
57 var _processor = wmd.processor;
58 var _postprocess = wmd.postprocess;
59
60 wmd.readOptions = function (options) {
61 test.equals(options, 'options');
62 return 'read options';
63 };
64 wmd.preprocess = function (content, options) {
65 test.same(content, {markdown: 'content', raw: 'content'});
66 test.equals(options, 'read options');
67 content.markdown = 'preprocessed';
68 return content;
69 };
70 wmd.processor = function (content) {
71 test.equals(content, 'preprocessed');
72 return 'processed';
73 };
74 wmd.postprocess = function (content, options) {
75 test.same(content, {
76 markdown: 'preprocessed',
77 raw: 'content',
78 html: 'processed'
79 });
80 test.equals(options, 'read options');
81 content.html = 'postprocessed';
82 return content;
83 };
84
85 var doc = wmd('content', 'options');
86 test.equals(doc, 'postprocessed');
87 test.equals(doc.html, 'postprocessed');
88 test.equals(doc.raw, 'content');
89 test.equals(doc.markdown, 'preprocessed');
90
91 // reinstate original exported functions
92 wmd.readOptions = _readOptions;
93 wmd.preprocess = _preprocess;
94 wmd.processor = _processor;
95 wmd.postprocess = _postprocess;
96 test.done();
97};
98
99exports['readOptions - defaults'] = function (test) {
100 test.same(wmd.readOptions(), {
101 preprocessors: [
102 wmd.preprocessors.metadata,
103 wmd.preprocessors.underscores
104 ],
105 postprocessors: []
106 });
107 test.done();
108};