markdown.jsView |
---|
1 | 1 | var fs = require('fs') |
2 | 2 | var remark = require('remark') |
3 | 3 | var html = require('remark-html') |
| 4 | +var slug = require('remark-slug') |
| 5 | +var autolinkHeadings = require('remark-autolink-headings') |
4 | 6 | var com = require('./tmpl/com.part') |
5 | 7 | |
| 8 | +const linkSvg = '<svg aria-hidden="true" class="octicon octicon-link" height="16" role="img" version="1.1" viewBox="0 0 16 16" width="16"><path d="M4 9h1v1h-1c-1.5 0-3-1.69-3-3.5s1.55-3.5 3-3.5h4c1.45 0 3 1.69 3 3.5 0 1.41-0.91 2.72-2 3.25v-1.16c0.58-0.45 1-1.27 1-2.09 0-1.28-1.02-2.5-2-2.5H4c-0.98 0-2 1.22-2 2.5s1 2.5 2 2.5z m9-3h-1v1h1c1 0 2 1.22 2 2.5s-1.02 2.5-2 2.5H9c-0.98 0-2-1.22-2-2.5 0-0.83 0.42-1.64 1-2.09v-1.16c-1.09 0.53-2 1.84-2 3.25 0 1.81 1.55 3.5 3 3.5h4c1.45 0 3-1.69 3-3.5s-1.5-3.5-3-3.5z"></path></svg>' |
| 9 | + |
6 | 10 | module.exports.doc = function (path) { |
7 | 11 | var text = fs.readFileSync(path, 'utf-8') |
8 | 12 | return remark() |
| 13 | + .use(slug) |
| 14 | + .use(autolinkHeadings, { |
| 15 | + attributes: { class: 'anchor' }, |
| 16 | + template: linkSvg |
| 17 | + }) |
9 | 18 | .use(html) |
10 | 19 | .use(transformCodeExamples) |
11 | 20 | .process(text) |
12 | 21 | } |