git ssb

2+

cel / scuttlebot.io



Commit b8ae20f0192e52a26783f66104a4f5c98f6aa48d

add anchor links to headings

Paul Frazee committed on 3/16/2016, 5:29:28 PM
Parent: 13691e1ee2bb8b8cec137e18d9f495648fba6793

Files changed

markdown.jschanged
package.jsonchanged
tmpl/css/index.css.jschanged
markdown.jsView
@@ -1,12 +1,21 @@
11 var fs = require('fs')
22 var remark = require('remark')
33 var html = require('remark-html')
4+var slug = require('remark-slug')
5+var autolinkHeadings = require('remark-autolink-headings')
46 var com = require('./tmpl/com.part')
57
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+
610 module.exports.doc = function (path) {
711 var text = fs.readFileSync(path, 'utf-8')
812 return remark()
13+ .use(slug)
14+ .use(autolinkHeadings, {
15+ attributes: { class: 'anchor' },
16+ template: linkSvg
17+ })
918 .use(html)
1019 .use(transformCodeExamples)
1120 .process(text)
1221 }
package.jsonView
@@ -15,7 +15,9 @@
1515 "nodemon": "^1.9.1"
1616 },
1717 "dependencies": {
1818 "remark": "^4.1.2",
19- "remark-html": "^3.0.0"
19+ "remark-autolink-headings": "^3.0.0",
20+ "remark-html": "^3.0.0",
21+ "remark-slug": "^4.1.0"
2022 }
2123 }
tmpl/css/index.css.jsView
@@ -12,8 +12,21 @@
1212 h1 small {
1313 font-weight: 300;
1414 }
1515
16+.anchor {
17+ visibility: hidden;
18+ margin-left: -23px;
19+ padding: 0 3px;
20+}
21+h1:hover .anchor,
22+h2:hover .anchor,
23+h3:hover .anchor,
24+h4:hover .anchor,
25+h5:hover .anchor {
26+ visibility: visible;
27+}
28+
1629 code, pre {
1730 font-family: 'Source Code Pro', monospace;
1831 }
1932 pre {

Built with git-ssb-web