Skip to content

Commit 0e51825

Browse files
author
Vitaly Puzrin
committed
Updated docs builder
1 parent 38bf443 commit 0e51825

File tree

4 files changed

+174
-47
lines changed

4 files changed

+174
-47
lines changed

.ndocrc

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
--index "./support/api_header.md"
66
--package "./package.json"
7-
--gh-ribbon "{package.homepage}"
7+
--gh-ribbon "https://github.com/{package.repository}"
88
--output "apidoc"
99
--render "html"
10-
--link-format "{package.homepage}/blob/master/{file}#L{line}"
10+
--link-format "https://github.com/{package.repository}/blob/master/{file}#L{line}"
1111
--broken-links "show"
1212

1313

Makefile

+1-6
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,8 @@ report-coverage:
5353
-istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage
5454

5555
doc:
56-
@if test ! `which ndoc` ; then \
57-
echo "You need 'ndoc' installed in order to generate docs." >&2 ; \
58-
echo " $ npm install -g ndoc" >&2 ; \
59-
exit 128 ; \
60-
fi
6156
rm -rf ./apidoc
62-
ndoc --link-format "{package.homepage}/blob/${CURR_HEAD}/{file}#L{line}"
57+
ndoc --link-format "https://github.com/{package.repository}/blob/${CURR_HEAD}/{file}#L{line}"
6358

6459
gh-doc: doc
6560
touch ./apidoc/.nojekyll

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
"markdown-it",
1010
"markdown-it-plugin"
1111
],
12-
"homepage": "https://github.com/markdown-it/markdown-it",
1312
"repository": "markdown-it/markdown-it",
1413
"license": "MIT",
1514
"main": "index.js",
@@ -59,6 +58,7 @@
5958
"markdown-it-testgen": "~0.1.3",
6059
"marked": "0.3.5",
6160
"mocha": "*",
61+
"ndoc": "^4.0.0",
6262
"stylus": "~0.53.0",
6363
"uglify-js": "*"
6464
}

support/api_header.md

+170-38
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,199 @@
1-
<!-- styles hack until ndoc updated -->
2-
<style>
3-
header .name_prefix { font-weight: normal; }
4-
</style>
1+
# markdown-it
52

6-
# markdown-it API
3+
## Install
74

8-
### Simple use
5+
**node.js** & **bower**:
6+
7+
```bash
8+
npm install markdown-it --save
9+
bower install markdown-it --save
10+
```
11+
12+
**browser (CDN):**
13+
14+
- [jsDeliver CDN](http://www.jsdelivr.com/#!markdown-it "jsDelivr CDN")
15+
- [cdnjs.com CDN](https://cdnjs.com/libraries/markdown-it "cdnjs.com")
16+
17+
18+
## Usage examples
19+
20+
See also:
21+
22+
- [Development info](https://github.com/markdown-it/markdown-it/tree/master/docs) -
23+
for plugins writers.
924

10-
In most cases you will use `markdown-it` in very simple way:
1125

12-
```javascript
26+
### Simple
27+
28+
```js
29+
// node.js, "classic" way:
30+
var MarkdownIt = require('markdown-it'),
31+
md = new MarkdownIt();
32+
var result = md.render('# markdown-it rulezz!');
33+
34+
// node.js, the same, but with sugar:
1335
var md = require('markdown-it')();
36+
var result = md.render('# markdown-it rulezz!');
37+
38+
// browser without AMD, added to "window" on script load
39+
// Note, there is no dash in "markdownit".
40+
var md = window.markdownit();
41+
var result = md.render('# markdown-it rulezz!');
42+
```
1443

15-
var result = md.render('your_markdown_string');
44+
Single line rendering, without paragraph wrap:
1645

17-
// Or for inline (without paragraths & blocks)
18-
var resultInline = md.renderInline('your_markdown_inline_string');
46+
```js
47+
var md = require('markdown-it')();
48+
var result = md.renderInline('__markdown-it__ rulezz!');
1949
```
2050

21-
### Advanced use
2251

23-
Advanced use consist of this steps:
52+
### Init with presets and options
2453

25-
1. Create instance with desired preset & options.
26-
2. Add plugins.
27-
3. Enable/Disable additional rules.
28-
4. Rewrite renderer functions.
29-
5. Use result to call `.render()` or `.renderInline()` method.
54+
(*) presets define combinations of active rules and options. Can be
55+
`"commonmark"`, `"zero"` or `"default"` (if skipped). See
56+
[API docs](https://markdown-it.github.io/markdown-it/#MarkdownIt.new) for more details.
3057

31-
Of cause, you can skip not needed steps, or change sequense.
58+
```js
59+
// commonmark mode
60+
var md = require('markdown-it')('commonmark');
3261

62+
// default mode
63+
var md = require('markdown-it')();
3364

34-
__Example 1.__ Minimalistic mode with bold, italic and line breaks:
65+
// enable everything
66+
var md = require('markdown-it')({
67+
html: true,
68+
linkify: true,
69+
typographer: true
70+
});
71+
72+
// full options list (defaults)
73+
var md = require('markdown-it')({
74+
html: false, // Enable HTML tags in source
75+
xhtmlOut: false, // Use '/' to close single tags (<br />).
76+
// This is only for full CommonMark compatibility.
77+
breaks: false, // Convert '\n' in paragraphs into <br>
78+
langPrefix: 'language-', // CSS language prefix for fenced blocks. Can be
79+
// useful for external highlighters.
80+
linkify: false, // Autoconvert URL-like text to links
81+
82+
// Enable some language-neutral replacement + quotes beautification
83+
typographer: false,
84+
85+
// Double + single quotes replacement pairs, when typographer enabled,
86+
// and smartquotes on. Could be either a String or an Array.
87+
//
88+
// For example, you can use '«»„“' for Russian, '„“‚‘' for German,
89+
// and ['«\xA0', '\xA0»', '‹\xA0', '\xA0›'] for French (including nbsp).
90+
quotes: '“”‘’',
91+
92+
// Highlighter function. Should return escaped HTML,
93+
// or '' if the source string is not changed and should be escaped externaly.
94+
// If result starts with <pre... internal wrapper is skipped.
95+
highlight: function (/*str, lang*/) { return ''; }
96+
});
97+
```
3598

36-
```javascript
37-
var md = require('markdown-it')('zero', { breaks: true })
38-
.enable([ 'newline', 'emphasis' ]);
99+
### Plugins load
39100

40-
var result = md.renderInline(...);
101+
```js
102+
var md = require('markdown-it')()
103+
.use(plugin1)
104+
.use(plugin2, opts, ...)
105+
.use(plugin3);
41106
```
42107

43108

44-
__Example 2.__ Load plugin and disable tables:
109+
### Syntax highlighting
45110

46-
```javascript
47-
var md = require('markdown-it')()
48-
.use(require('markdown-it-emoji'))
49-
.disable('table');
111+
Apply syntax highlighting to fenced code blocks with the `highlight` option:
50112

51-
var result = md.render(...);
52-
```
113+
```js
114+
var hljs = require('highlight.js') // https://highlightjs.org/
53115

116+
// Actual default values
117+
var md = require('markdown-it')({
118+
highlight: function (str, lang) {
119+
if (lang && hljs.getLanguage(lang)) {
120+
try {
121+
return hljs.highlight(lang, str).value;
122+
} catch (__) {}
123+
}
54124

55-
__Example 3.__ Replace `<strong>` with `<b>` in rendered result:
125+
return ''; // use external default escaping
126+
}
127+
});
128+
```
56129

57-
```javascript
58-
var md = require('markdown-it')();
130+
Or with full wrapper override (if you need assign class to `<pre>`):
131+
132+
```js
133+
var hljs = require('highlight.js') // https://highlightjs.org/
134+
135+
// Actual default values
136+
var md = require('markdown-it')({
137+
highlight: function (str, lang) {
138+
if (lang && hljs.getLanguage(lang)) {
139+
try {
140+
return '<pre class="hljs"><code>' +
141+
hljs.highlight(lang, str, true).value +
142+
'</code></pre>';
143+
} catch (__) {}
144+
}
145+
146+
return '<pre class="hljs"><code>' + md.utils.escapeHtml(str) + '</code></pre>';
147+
}
148+
});
149+
```
150+
151+
### Linkify
59152

60-
md.renderer.rules.strong_open = function () { return '<b>'; };
61-
md.renderer.rules.strong_close = function () { return '</b>'; };
153+
`linkify: true` uses [linkify-it](https://github.com/markdown-it/linkify-it). To
154+
configure linkify-it, access the linkify instance through `md.linkify`:
62155

63-
var result = md.renderInline(...);
156+
```js
157+
md.linkify.tlds('.py', false); // disables .py as top level domain
64158
```
65159

160+
## Syntax extensions
161+
162+
Embedded (enabled by default):
163+
164+
- [Tables](https://help.github.com/articles/github-flavored-markdown/#tables) (GFM)
165+
- [Strikethrough](https://help.github.com/articles/github-flavored-markdown/#strikethrough) (GFM)
66166

67-
See classes doc for all available features and more examples.
167+
Via plugins:
168+
169+
- [subscript](https://github.com/markdown-it/markdown-it-sub)
170+
- [superscript](https://github.com/markdown-it/markdown-it-sup)
171+
- [footnote](https://github.com/markdown-it/markdown-it-footnote)
172+
- [definition list](https://github.com/markdown-it/markdown-it-deflist)
173+
- [abbreviation](https://github.com/markdown-it/markdown-it-abbr)
174+
- [emoji](https://github.com/markdown-it/markdown-it-emoji)
175+
- [custom container](https://github.com/markdown-it/markdown-it-container)
176+
- [insert](https://github.com/markdown-it/markdown-it-ins)
177+
- [mark](https://github.com/markdown-it/markdown-it-mark)
178+
- ... and [others](https://www.npmjs.org/browse/keyword/markdown-it-plugin)
179+
180+
181+
### Manage rules
182+
183+
By default all rules are enabled, but can be restricted by options. On plugin
184+
load all its rules are enabled automatically.
185+
186+
```js
187+
// Activate/deactivate rules, with curring
188+
var md = require('markdown-it')()
189+
.disable([ 'link', 'image' ])
190+
.enable([ 'link' ])
191+
.enable('image');
192+
193+
// Enable everything
194+
md = require('markdown-it')('full', {
195+
html: true,
196+
linkify: true,
197+
typographer: true,
198+
});
199+
```

0 commit comments

Comments
 (0)