-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathindex.js
executable file
·383 lines (334 loc) · 8.27 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
/*!
* markdown-utils <https://github.com/jonschlinkert/markdown-utils>
*
* Copyright (c) 2014-2018, Jon Schlinkert, contributors.
* Licensed under the MIT license.
*/
'use strict';
const isNumber = require('is-number');
const listitem = require('list-item');
/**
* Create a markdown-formatted blockquote.
*
* ```js
* utils.blockquote('This is a blockquote');
* //=> '> This is a blockquote'
* ```
* @param {String} `str`
* @api public
*/
exports.blockquote = str => str ? `> ${str}` : '';
/**
* Create a markdown-formatted `<code></code>` snippet.
*
* ```js
* utils.code('const foo = bar;');
* //=> '`const foo = bar;`'
* ```
* @param {String} `str`
* @api public
*/
exports.code = str => str ? `\`${str}\`` : '';
/**
* Create markdown-formatted deleted text: `~~text~~`.
*
* ```js
* utils.del('text');
* //=> '~~text~~'
* ```
* @param {String} `str`
* @api public
*/
exports.del = str => str ? `~~${str}~~` : '';
/**
* Create a markdown-formatted em.
*
* ```js
* utils.em('This is emphasized');
* //=> '_This is emphasized_'
* ```
* @param {String} `str`
* @api public
*/
exports.em = str => str ? `_${str}_` : '';
/**
* Create a markdown-formatted heading.
*
* ```js
* utils.h(1, 'This is a heading');
* //=> '# This is a heading'
* ```
* @param {String} `str`
* @param {Number} `level`
* @api public
*/
exports.h = (level, str) => str ? exports.heading(str, level) : '';
/**
* Create a markdown-formatted h1 heading.
*
* ```js
* utils.h1('This is a heading');
* //=> '# This is a heading'
* ```
* @param {String} `str`
* @api public
*/
exports.h1 = str => str ? `# ${str}` : '';
/**
* Create a markdown-formatted h2 heading.
*
* ```js
* utils.h2('This is a heading');
* //=> '## This is a heading'
* ```
* @param {String} `str`
* @api public
*/
exports.h2 = str => str ? `## ${str}` : '';
/**
* Create a markdown-formatted h3 heading.
*
* ```js
* utils.h3('This is a heading');
* //=> '### This is a heading'
* ```
* @param {String} `str`
* @api public
*/
exports.h3 = str => str ? `### ${str}` : '';
/**
* Create a markdown-formatted h4 heading.
*
* ```js
* utils.h4('This is a heading');
* //=> '#### This is a heading'
* ```
* @param {String} `str`
* @api public
*/
exports.h4 = str => str ? `#### ${str}` : '';
/**
* Create a markdown-formatted h5 heading.
*
* ```js
* utils.h5('This is a heading');
* //=> '##### This is a heading'
* ```
* @param {String} `str`
* @api public
*/
exports.h5 = str => str ? `##### ${str}` : '';
/**
* Create a markdown-formatted h6 heading.
*
* ```js
* utils.h6('This is a heading');
* //=> '###### This is a heading'
* ```
* @param {String} `str`
* @api public
*/
exports.h6 = str => str ? `###### ${str}` : '';
/**
* Create a markdown-formatted heading.
*
* ```js
* utils.heading('This is a heading', 1);
* //=> '# This is a heading'
* ```
* @param {String} `str`
* @param {Number} `level`
* @api public
*/
exports.heading = (str, level) => str ? exports[`h${(level || 1)}`](str) : '';
/**
* Create a markdown-formatted horizontal rule.
*
* ```js
* utils.hr();
* //=> '***'
* ```
* @param {String} `str` Alternate string to use. Default is `***` to avoid collision with `---` which is commonly used for front-matter.
* @api public
*/
exports.hr = (str = '***') => str;
/**
* Create a markdown-formatted link from the given values.
*
* ```js
* utils.link('fs-utils', 'https://github.com/assemble/fs-utils', 'hover title');
* //=> [fs-utils](https://github.com/assemble/fs-utils "hover title")
* ```
* @param {String} `anchor`
* @param {String} `href`
* @param {String} `title`
* @api public
*/
exports.link = (anchor, href, title) => {
return `[${anchor}](${href}${title ? ` "${title}"` : ''})`;
};
/**
* Create a markdown-formatted anchor link from the given values.
*
* ```js
* utils.anchor('embed', 'assemble/handlebars-helpers/lib/code.js', 25, 'v0.6.0');
* //=> [embed](https://github.com/assemble/handlebars-helpers/blob/v0.6.0/lib/helpers/code.js#L25)
* ```
* @param {String} `anchor`
* @param {String} `href`
* @param {String} `title`
* @api public
*/
exports.anchor = (text, repo, line, branch) => {
return `[${text}](${format(repo, branch, line)})`;
};
function format(str, branch, line) {
let segs = str.split(/[\\\/]/);
let repo = segs.slice(0, 2).join('/');
let rest = segs.slice(2).join('/');
if (isNumber(branch)) {
line = branch;
branch = 'master';
}
let res = 'https://github.com/';
res += `${repo}/blob/${branch}/${rest}`;
res += line ? `#L${line}` : '';
return res;
}
/**
* Create a markdown-formatted reference link from the given values.
*
* ```js
* utils.reference('template', 'https://github/jonschlinkert/template', 'Make stuff!');
* //=> [template]: https://github/jonschlinkert/template "Make stuff!"
* ```
* @param {String} `id`
* @param {String} `url`
* @param {String} `title`
* @api public
*/
exports.reference = (id, url, title) => {
return `[${id}]: ${url}${title ? ` "${title}"` : ''}`;
};
/**
* Create a markdown-formatted image from the given values.
*
* ```js
* utils.image(alt, src);
* //=> ![Build Status](https://travis-ci.org/jonschlinkert/template.svg)
*
* utils.image(alt, src, title);
* //=> ![Build Status](https://travis-ci.org/jonschlinkert/template.svg "This is title of image!")
* ```
* @param {String} `alt`
* @param {String} `src`
* @param {String} `title`
* @api public
*/
exports.image = (alt, src, title) => '!' + exports.link(alt, src, title);
/**
* Create a markdown-formatted badge.
*
* ```js
* utils.badge(alt, img_url, url);
* //=> [![Build Status](https://travis-ci.org/jonschlinkert/template.svg)](https://travis-ci.org/jonschlinkert/template)
* ```
* @param {String} `alt`
* @param {String} `img_url`
* @param {String} `url`
* @api public
*/
exports.badge = (alt, img_url, url, title) => {
return exports.link(exports.image(alt, img_url, title), url);
};
/**
* Returns a function to generate a plain-text/markdown list-item,
* allowing options to be cached for subsequent calls.
*
* ```js
* const li = listitem(options);
*
* li(0, 'Level 0 list item');
* //=> '- Level 0 list item'
*
* li(1, 'Level 1 list item');
* //=> ' * Level 1 list item'
*
* li(2, 'Level 2 list item');
* //=> ' + Level 2 list item'
* ```
* @param {String} `options`
* @option {Boolean} [options] `nobullet` Pass true if you only want the list iten and identation, but no bullets.
* @option {String} [options] `indent` The amount of leading indentation to use. default is ` `.
* @option {String|Array} [options] `chars` If a string is passed, [fill-range] will be used to generate an array of bullets (visit [fill-range] to see all options.) Or directly pass an array of bullets, numbers, letters or other characters to use for each list item. Default `['-', '*', '+', '~']`
* @param {Function} `fn` pass a function [fill-range] to modify the bullet for an item as it's generated.
* @api public
*/
exports.li = (char, level, options, fn) => listitem(options, fn)(level, char);
/**
* Create a markdown-formatted `<pre><code></code></pre>` snippet with or without lang.
*
* ```js
* utils.pre('const foo = bar;');
* ```
* Results in:
*
* ```html
* <pre>
* const foo = bar;
* </pre>
* ```
* @param {String} `str`
* @param {String} `language`
* @api public
*/
exports.pre = str => str ? `<pre>\n${str}\n</pre>` : '';
/**
* Create a markdown-formatted code snippet with or without `lang`.
*
* ```js
* utils.gfm('const foo = bar;', 'js');
* ```
* Results in:
*
* <pre>
* ```js
* const foo = bar;
* ```
* </pre>
*
* @param {String} `str`
* @param {String} `language`
* @api public
*/
exports.gfm = (str, lang = '') => {
let fence = '```';
return str ? `${fence}${lang}\n${str}\n${fence}` : '';
};
/**
* Create markdown-formatted bold text.
*
* ```js
* utils.strong('This is bold');
* //=> '**This is bold**'
* ```
* @param {String} `str`
* @api public
*/
exports.strong = str => str ? `**${str}**` : '';
/**
* Create a markdown-formatted todo item.
*
* ```js
* utils.todo('this is a todo.');
* //=> '- [ ] this is a todo'
*
* utils.todo('this is a completed todo.', true);
* //=> '- [x] this is a todo'
* ```
* @param {String} `str`
* @api public
*/
exports.todo = (str, checked) => {
return str ? ((checked ? '- [x] ' : '- [ ] ') + str) : '';
};