1 | # WMD
|
2 |
|
3 | A Markdown parser for CommonJS (and node.js) based on the excellent
|
4 | [Showdown](http://attacklab.net/showdown/).
|
5 |
|
6 | Essentially WMD, is just a wrapper around Showdown, with a few hooks for
|
7 | preprocessing, and some default preprocessors and postprocessors.
|
8 |
|
9 |
|
10 | ## Example
|
11 |
|
12 | var wmd = require('wmd');
|
13 |
|
14 | var html = wmd('Markdown *rocks*.');
|
15 | console.log(html);
|
16 |
|
17 |
|
18 | # Documentation
|
19 |
|
20 |
|
21 | ## wmd(markdown, options)
|
22 |
|
23 | * __markdown__ - A string containing Markdown.
|
24 | * __options__ - (optional) An object containing options (see options section)
|
25 |
|
26 | The main function for converting Markdown to HTML, and normally the only
|
27 | function you'll need ot use. Applies all preprocessors defined in options
|
28 | before passing the result to Showdown for the final rendering.
|
29 |
|
30 | By default, the underscores and metadata preprocessors are used.
|
31 |
|
32 | This function returns a __doc__ object. The contents of the doc object may
|
33 | differ depending on the preprocessors used, but will always contain the
|
34 | following:
|
35 |
|
36 | * __doc.html__ - The final HTML output of the conversion.
|
37 | * __doc.markdown__ - The markdown text passed to the processsor after all
|
38 | preprocesor functions have been applied.
|
39 | * __doc.raw__ - The raw string before preprocessors were applied.
|
40 |
|
41 | The string representation of a doc object (doc.toString()) is the same as
|
42 | doc.html.
|
43 |
|
44 |
|
45 | ## wmd.preprocessors
|
46 |
|
47 | An object containing core preprocessor functions:
|
48 |
|
49 | * __underscores__ - code-friendly underscore processing taken from GitHub
|
50 | Flavored Markdown. This means the bar in foo\_bar\_baz does not get emphasis.
|
51 | * __fencedCodeBlocks__ - GitHub style fenced code blocks
|
52 | * __yamlFrontMatter__ - Jekyll style YAML front matter for metadata
|
53 | * __metadata__ - takes metatdata information from the top of a markdown file
|
54 | and adds it to doc.metadata.
|
55 |
|
56 | property1: some value
|
57 | property2: multi
|
58 | line
|
59 | value
|
60 |
|
61 | # Markdown goes here
|
62 |
|
63 | Would result in the following doc object:
|
64 |
|
65 | {
|
66 | metadata: {
|
67 | property1: "some value",
|
68 | property2: "multi\nline\nvalue"
|
69 | },
|
70 | html: "<h1>Markdown goes here</h1>",
|
71 | markdown: "# Markdown goes here",
|
72 | raw: "property1: some value\nproperty2: multi\nline\nvalue\n\n# Markdown goes here"
|
73 | }
|
74 |
|
75 | Adding preprocessors to wmd:
|
76 |
|
77 | var wmd = require('wmd');
|
78 | var html = wmd('Markdown *rocks*.', {
|
79 | preprocessors: [
|
80 | function (doc) {
|
81 | doc.markdown += '.. even more!';
|
82 | return doc;
|
83 | }
|
84 | ]
|
85 | });
|
86 |
|
87 | By default, the underscores and metadata preprocessors will be used.
|
88 |
|
89 | ## wmd.postprocessors
|
90 |
|
91 | An object containing core postprocessor functions:
|
92 |
|
93 | * __jsdom__ - uses jsdom to add doc.window containing the HTML generated from
|
94 | markdown
|
95 | * __first_para__ - adds doc.first_para containing the text in the first p tag
|
96 | * __heading__ - adds doc.heading containing the text in the first h1 tag
|
97 |
|
98 | Adding postprocessors to wmd:
|
99 |
|
100 | var wmd = require('wmd');
|
101 | var html = wmd('Markdown *rocks*.', {
|
102 | postprocessors: [
|
103 | function (doc) {
|
104 | doc.html += '<b>more html stuff</b>';
|
105 | return doc;
|
106 | }
|
107 | ]
|
108 | });
|
109 |
|
110 | By default, no postprocessors will be used.
|
111 |
|
112 |
|
113 | ## wmd.processor(markdown)
|
114 |
|
115 | * __markdown__ - A string containing Markdown.
|
116 |
|
117 | The function which performs the conversion from markdown to html. By default
|
118 | this is just Showdown's makeHTML function.
|
119 |
|
120 |
|
121 | ## wmd.preprocess(doc, options)
|
122 |
|
123 | * __doc__ - A doc object
|
124 | * __options__ - (optional) An object containing options (see options section)
|
125 |
|
126 | Applies the preprocessor functions defined in options to the doc (usually
|
127 | updating doc.markdown, sometimes adding new properties) before the doc is
|
128 | passed to the processor.
|
129 |
|
130 |
|
131 | ## wmd.postprocess(doc, options)
|
132 |
|
133 | * __doc__ - A doc object
|
134 | * __options__ - (optional) An object containing options (see options section)
|
135 |
|
136 | Applies the postprocessor functions defined in options to the doc.
|
137 |
|
138 |
|
139 | ## wmd.readOptions(options)
|
140 |
|
141 | * __options__ - (optional) An object containing options (see options section)
|
142 |
|
143 | You would not normally need to call this directly. This function adds default
|
144 | options to those passed to the main wmd function.
|
145 |
|
146 |
|
147 | ## Options
|
148 |
|
149 | * __preprocessors__ - An array of functions which can transform the document
|
150 | before its passed to the processor function. By default the underscores and
|
151 | metadata preprocessors are used.
|
152 | * __postprocessors__ - An array of functions which can transform the document
|
153 | after its been passed to the processor function. By default, no
|
154 | postprocessors are used.
|