mirror of
https://gitee.com/docsifyjs/docsify.git
synced 2024-12-02 03:59:19 +08:00
Add vue theme
This commit is contained in:
parent
44ac51b9c2
commit
e82b5c58bc
24
build/build.js
Normal file
24
build/build.js
Normal file
@ -0,0 +1,24 @@
|
||||
var rollup = require('rollup')
|
||||
var buble = require('rollup-plugin-buble')
|
||||
|
||||
var build = function (entry, moduleName) {
|
||||
rollup
|
||||
.rollup({
|
||||
entry: 'src/' + entry,
|
||||
plugins: [buble()]
|
||||
})
|
||||
.then(function (bundle) {
|
||||
bundle.write({
|
||||
globals: {
|
||||
marked: 'marked',
|
||||
prismjs: 'Prism'
|
||||
},
|
||||
format: 'umd',
|
||||
moduleName: moduleName,
|
||||
dest: 'lib/' + entry
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
build('docsify.js', 'Docsify')
|
||||
build('plugins/nav.js', 'Docsify.Nav')
|
@ -1 +0,0 @@
|
||||
# ahhh
|
1
docs/README.md
Symbolic link
1
docs/README.md
Symbolic link
@ -0,0 +1 @@
|
||||
../README.md
|
142
lib/docsify.js
142
lib/docsify.js
@ -20,6 +20,49 @@ var ajax = function (url, options) {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @link from https://github.com/killercup/grock/blob/5280ae63e16c5739e9233d9009bc235ed7d79a50/styles/solarized/assets/js/behavior.coffee#L54-L81
|
||||
*/
|
||||
var tocToTree = function (toc) {
|
||||
var headlines = [];
|
||||
var last = {};
|
||||
|
||||
toc.forEach(function (headline) {
|
||||
var level = headline.level || 1;
|
||||
var len = level - 1;
|
||||
|
||||
if (last[len]) {
|
||||
last[len].children = last[len].children || [];
|
||||
last[len].children.push(headline);
|
||||
} else {
|
||||
headlines.push(headline);
|
||||
last[level] = headline;
|
||||
}
|
||||
});
|
||||
|
||||
return headlines
|
||||
};
|
||||
|
||||
var buildHeadlinesTree = function (tree, tpl) {
|
||||
if ( tpl === void 0 ) tpl = '';
|
||||
|
||||
if (!tree || !tree.length) { return '' }
|
||||
|
||||
tree.forEach(function (node) {
|
||||
tpl += "<li><a class=\"section-link\" href=\"#" + (node.slug) + "\">" + (node.title) + "</a></li>";
|
||||
if (node.children) {
|
||||
tpl += "<li><ul class=\"children\">" + (buildHeadlinesTree(node.children)) + "</li>";
|
||||
}
|
||||
});
|
||||
|
||||
return tpl + '</ul>'
|
||||
};
|
||||
|
||||
var genToc = function (toc) {
|
||||
return buildHeadlinesTree(tocToTree(toc), '<ul>')
|
||||
};
|
||||
|
||||
var toc = [];
|
||||
var renderer = new marked.Renderer();
|
||||
|
||||
/**
|
||||
@ -27,31 +70,95 @@ var renderer = new marked.Renderer();
|
||||
* @link https://github.com/chjj/marked#overriding-renderer-methods
|
||||
*/
|
||||
renderer.heading = function (text, level) {
|
||||
var escapedText = text.toLowerCase().replace(/[^\w]+/g, '-');
|
||||
var slug = text.toLowerCase().replace(/[\s\n\t]+/g, '-');
|
||||
|
||||
return '<h' + level + '><a name="' + escapedText + '" class="anchor" href="#' +
|
||||
escapedText + '"><span class="header-link"></span></a>' + text +
|
||||
'</h' + level + '>'
|
||||
toc.push({ level: level, slug: slug, title: text });
|
||||
|
||||
return ("<h" + level + " id=\"" + slug + "\"><a href=\"#" + slug + "\" class=\"anchor\"></a>" + text + "</h" + level + ">")
|
||||
};
|
||||
|
||||
marked.setOptions({
|
||||
renderer: renderer,
|
||||
highlight: function highlight (code, lang) {
|
||||
return Prism.highlight(code, Prism.languages[lang])
|
||||
return Prism.highlight(code, Prism.languages[lang] || Prism.languages.markup)
|
||||
}
|
||||
});
|
||||
|
||||
var render = function (content) {
|
||||
return marked(content, { renderer: renderer })
|
||||
var section = "<section class=\"content\">\n <article class=\"markdown-section\">" + (marked(content)) + "</article>\n </section>";
|
||||
var sidebar = "<aside class=\"sidebar\">" + (genToc(toc)) + "</aside>";
|
||||
|
||||
return ("<main>" + sidebar + section + "</main>")
|
||||
};
|
||||
|
||||
function scrollActiveSidebar () {
|
||||
if (/mobile/i.test(navigator.userAgent)) { return }
|
||||
|
||||
var anchors = document.querySelectorAll('.anchor');
|
||||
var nav = {};
|
||||
var lis = document.querySelectorAll('.sidebar li');
|
||||
var active = null;
|
||||
|
||||
for (var i = 0, len = lis.length; i < len; i += 1) {
|
||||
var li = lis[i];
|
||||
var a = li.querySelector('a');
|
||||
|
||||
nav[a.getAttribute('href').slice(1)] = li;
|
||||
}
|
||||
|
||||
function highlight () {
|
||||
for (var i = 0, len = anchors.length; i < len; i += 1) {
|
||||
var node = anchors[i].parentNode;
|
||||
var bcr = node.getBoundingClientRect();
|
||||
|
||||
if (bcr.top < 150 && bcr.bottom > 150) {
|
||||
var li = nav[ node.id ];
|
||||
if (li === active) { return }
|
||||
if (active) { active.classList.remove('active'); }
|
||||
|
||||
li.classList.add('active');
|
||||
active = li;
|
||||
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
document.querySelector('main .content').addEventListener('scroll', highlight);
|
||||
highlight();
|
||||
|
||||
function scrollIntoView () {
|
||||
var id = window.location.hash.slice(1);
|
||||
var section = document.querySelector('#' + id);
|
||||
|
||||
if (section) { section.scrollIntoView(); }
|
||||
}
|
||||
|
||||
window.addEventListener('hashchange', scrollIntoView);
|
||||
scrollIntoView();
|
||||
}
|
||||
|
||||
var bindEvent = function () {
|
||||
scrollActiveSidebar();
|
||||
};
|
||||
|
||||
var DEFAULT_OPTS = {
|
||||
el: '#app',
|
||||
title: document.title,
|
||||
sep: ' - '
|
||||
};
|
||||
|
||||
var Docsify = function Docsify (opts) {
|
||||
if ( opts === void 0 ) opts = {};
|
||||
|
||||
Docsify.installed = true;
|
||||
|
||||
this.dom = document.querySelector(opts.el || 'body');
|
||||
this.replace = true;
|
||||
this.opts = Object.assign({}, opts, DEFAULT_OPTS);
|
||||
this.dom = document.querySelector(this.opts.el);
|
||||
if (!this.dom) {
|
||||
this.dom = document.body;
|
||||
this.replace = false;
|
||||
}
|
||||
this.loc = document.location.pathname;
|
||||
this.loc = this.loc === '/' ? 'README' : this.loc;
|
||||
if (/\/$/.test(this.loc)) { this.loc += 'README'; }
|
||||
this.load();
|
||||
};
|
||||
|
||||
@ -64,12 +171,23 @@ Docsify.prototype.load = function load () {
|
||||
this$1.render('not found');
|
||||
} else {
|
||||
this$1.render(res.target.response);
|
||||
bindEvent();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
Docsify.prototype.render = function render$1 (content) {
|
||||
this.dom.innerHTML = render(content);
|
||||
document.title = this.loc.slice(1) + this.opts.sep + this.opts.title;
|
||||
this.dom[this.replace ? 'outerHTML' : 'innerHTML'] = render(content);
|
||||
};
|
||||
|
||||
Docsify.use = function () {
|
||||
var plugin = arguments[0];
|
||||
if (typeof plugin === 'function') {
|
||||
plugin.call(Docsify);
|
||||
} else {
|
||||
throw TypeError('[docsify] Invalid plugin ' + plugin.name)
|
||||
}
|
||||
};
|
||||
|
||||
window.addEventListener('load', function () {
|
||||
|
2
lib/docsify.min.js
vendored
2
lib/docsify.min.js
vendored
@ -1 +1 @@
|
||||
(function(global,factory){typeof exports==="object"&&typeof module!=="undefined"?module.exports=factory(require("marked"),require("highlight.js")):typeof define==="function"&&define.amd?define(["marked","highlight.js"],factory):global.Docsify=factory(global.marked,global.hljs)})(this,function(marked,hljs){"use strict";marked="default"in marked?marked["default"]:marked;hljs="default"in hljs?hljs["default"]:hljs;var ajax=function(url,options){if(options===void 0)options={};var xhr=new XMLHttpRequest;xhr.open(options.method||"get",url);xhr.send();return{then:function(cb){return xhr.addEventListener("load",cb)},catch:function(cb){return xhr.addEventListener("error",cb)}}};var renderer=new marked.Renderer;renderer.heading=function(text,level){var escapedText=text.toLowerCase().replace(/[^\w]+/g,"-");return"<h"+level+'><a name="'+escapedText+'" class="anchor" href="#'+escapedText+'"><span class="header-link"></span></a>'+text+"</h"+level+">"};var render=function(content){return marked(content,{renderer:renderer,highlight:function highlight(code){return hljs.highlightAuto(code).value}})};var Docsify=function Docsify(opts){if(opts===void 0)opts={};Docsify.installed=true;this.dom=document.querySelector(opts.el||"body");var loc="https://yanagieiichi.github.io/reciper/intro/README.md";this.load(loc)};Docsify.prototype.load=function load(loc){var this$1=this;ajax(""+loc).then(function(res){this$1.render(res.target.response)})};Docsify.prototype.render=function render$1(content){this.dom.innerHTML=render(content)};window.addEventListener("load",function(){if(Docsify.installed){return}new Docsify});return Docsify});
|
||||
(function(global,factory){typeof exports==="object"&&typeof module!=="undefined"?module.exports=factory(require("marked"),require("prismjs")):typeof define==="function"&&define.amd?define(["marked","prismjs"],factory):global.Docsify=factory(global.marked,global.Prism)})(this,function(marked,Prism){"use strict";marked="default"in marked?marked["default"]:marked;Prism="default"in Prism?Prism["default"]:Prism;var ajax=function(url,options){if(options===void 0)options={};var xhr=new XMLHttpRequest;xhr.open(options.method||"get",url);xhr.send();return{then:function(cb){return xhr.addEventListener("load",cb)}}};var tocToTree=function(toc){var headlines=[];var last={};toc.forEach(function(headline){var level=headline.level||1;var len=level-1;if(last[len]){last[len].children=last[len].children||[];last[len].children.push(headline)}else{headlines.push(headline);last[level]=headline}});return headlines};var buildHeadlinesTree=function(tree,tpl){if(tpl===void 0)tpl="";if(!tree||!tree.length){return""}tree.forEach(function(node){tpl+='<li><a class="section-link" href="#'+node.slug+'">'+node.title+"</a></li>";if(node.children){tpl+='<li><ul class="children">'+buildHeadlinesTree(node.children)+"</li>"}});return tpl+"</ul>"};var genToc=function(toc){return buildHeadlinesTree(tocToTree(toc),"<ul>")};var toc=[];var renderer=new marked.Renderer;renderer.heading=function(text,level){var slug=text.toLowerCase().replace(/[\s\n\t]+/g,"-");toc.push({level:level,slug:slug,title:text});return"<h"+level+' id="'+slug+'"><a href="#'+slug+'" class="anchor"></a>'+text+"</h"+level+">"};marked.setOptions({renderer:renderer,highlight:function highlight(code,lang){return Prism.highlight(code,Prism.languages[lang]||Prism.languages.markup)}});var render=function(content){var section='<section class="content">\n <article class="markdown-section">'+marked(content)+"</article>\n </section>";var sidebar='<aside class="sidebar">'+genToc(toc)+"</aside>";return"<main>"+sidebar+section+"</main>"};function scrollActiveSidebar(){if(/mobile/i.test(navigator.userAgent)){return}var anchors=document.querySelectorAll(".anchor");var nav={};var lis=document.querySelectorAll(".sidebar li");var active=null;for(var i=0,len=lis.length;i<len;i+=1){var li=lis[i];var a=li.querySelector("a");nav[a.getAttribute("href").slice(1)]=li}function highlight(){for(var i=0,len=anchors.length;i<len;i+=1){var node=anchors[i].parentNode;var bcr=node.getBoundingClientRect();if(bcr.top<150&&bcr.bottom>150){var li=nav[node.id];if(li===active){return}if(active){active.classList.remove("active")}li.classList.add("active");active=li;return}}}document.querySelector("main .content").addEventListener("scroll",highlight);highlight();function scrollIntoView(){var id=window.location.hash.slice(1);var section=document.querySelector("#"+id);if(section){section.scrollIntoView()}}window.addEventListener("hashchange",scrollIntoView);scrollIntoView()}var bindEvent=function(){scrollActiveSidebar()};var DEFAULT_OPTS={el:"#app",title:document.title,sep:" - "};var Docsify=function Docsify(opts){Docsify.installed=true;this.replace=true;this.opts=Object.assign({},opts,DEFAULT_OPTS);this.dom=document.querySelector(this.opts.el);if(!this.dom){this.dom=document.body;this.replace=false}this.loc=document.location.pathname;if(/\/$/.test(this.loc)){this.loc+="README"}this.load()};Docsify.prototype.load=function load(){var this$1=this;ajax(this.loc+".md").then(function(res){var target=res.target;if(target.status>=400){this$1.render("not found")}else{this$1.render(res.target.response);bindEvent()}})};Docsify.prototype.render=function render$1(content){document.title=this.loc.slice(1)+this.opts.sep+this.opts.title;this.dom[this.replace?"outerHTML":"innerHTML"]=render(content)};Docsify.use=function(){var plugin=arguments[0];if(typeof plugin==="function"){plugin.call(Docsify)}else{throw TypeError("[docsify] Invalid plugin "+plugin.name)}};window.addEventListener("load",function(){if(Docsify.installed){return}new Docsify});return Docsify});
|
18
lib/plugins/nav.js
Normal file
18
lib/plugins/nav.js
Normal file
@ -0,0 +1,18 @@
|
||||
(function (global, factory) {
|
||||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
||||
typeof define === 'function' && define.amd ? define(factory) :
|
||||
(global.Docsify = global.Docsify || {}, global.Docsify.Nav = factory());
|
||||
}(this, (function () { 'use strict';
|
||||
|
||||
var Nav = function () {
|
||||
console.log(this);
|
||||
};
|
||||
Nav.name = 'Doscify.Nav';
|
||||
|
||||
if (window.Docsify) {
|
||||
window.Docsify.use(Nav);
|
||||
}
|
||||
|
||||
return Nav;
|
||||
|
||||
})));
|
@ -2,14 +2,14 @@
|
||||
"name": "docsify",
|
||||
"version": "0.0.0",
|
||||
"description": "A magical documentation generator.",
|
||||
"main": "index.js",
|
||||
"main": "lib/docsify.js",
|
||||
"files": [
|
||||
"lib",
|
||||
"themes"
|
||||
],
|
||||
"scripts": {
|
||||
"build": "rollup -c && uglifyjs lib/docsify.js -o lib/docsify.min.js",
|
||||
"dev": "nodemon -w src -x 'rollup -c && node test/server.js'",
|
||||
"build": "node build/build.js && uglifyjs lib/docsify.js -o lib/docsify.min.js",
|
||||
"dev": "nodemon -w src -x 'node build/build.js && node test/server.js'",
|
||||
"test": "eslint src server"
|
||||
},
|
||||
"keywords": [
|
||||
|
@ -1,13 +0,0 @@
|
||||
import buble from 'rollup-plugin-buble'
|
||||
|
||||
export default {
|
||||
entry: 'src/index.js',
|
||||
dest: 'lib/docsify.js',
|
||||
plugins: [buble()],
|
||||
globals: {
|
||||
marked: 'marked',
|
||||
prismjs: 'Prism'
|
||||
},
|
||||
format: 'umd',
|
||||
moduleName: 'Docsify'
|
||||
}
|
59
src/bind-event.js
Normal file
59
src/bind-event.js
Normal file
@ -0,0 +1,59 @@
|
||||
function activeSidebar () {
|
||||
document.addEventListener('click', ({ target }) => {
|
||||
if (target.classList.contains('section-link') && target.nodeName === 'A') {
|
||||
[].slice.call(document.querySelectorAll('.sidebar li')).forEach(node => node.classList.remove('active'))
|
||||
target.parentNode.classList.toggle('active')
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function scrollActiveSidebar () {
|
||||
if (/mobile/i.test(navigator.userAgent)) return
|
||||
|
||||
const anchors = document.querySelectorAll('.anchor')
|
||||
const nav = {}
|
||||
const lis = document.querySelectorAll('.sidebar li')
|
||||
let active = null
|
||||
|
||||
for (let i = 0, len = lis.length; i < len; i += 1) {
|
||||
const li = lis[i]
|
||||
const a = li.querySelector('a')
|
||||
|
||||
nav[a.getAttribute('href').slice(1)] = li
|
||||
}
|
||||
|
||||
function highlight () {
|
||||
for (let i = 0, len = anchors.length; i < len; i += 1) {
|
||||
const node = anchors[i].parentNode
|
||||
const bcr = node.getBoundingClientRect()
|
||||
|
||||
if (bcr.top < 150 && bcr.bottom > 150) {
|
||||
const li = nav[ node.id ]
|
||||
if (li === active) return
|
||||
if (active) active.classList.remove('active')
|
||||
|
||||
li.classList.add('active')
|
||||
active = li
|
||||
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
document.querySelector('main .content').addEventListener('scroll', highlight)
|
||||
highlight()
|
||||
|
||||
function scrollIntoView () {
|
||||
var id = window.location.hash.slice(1)
|
||||
var section = document.querySelector('#' + id)
|
||||
|
||||
if (section) section.scrollIntoView()
|
||||
}
|
||||
|
||||
window.addEventListener('hashchange', scrollIntoView)
|
||||
scrollIntoView()
|
||||
}
|
||||
|
||||
export default function () {
|
||||
scrollActiveSidebar()
|
||||
}
|
59
src/docsify.js
Normal file
59
src/docsify.js
Normal file
@ -0,0 +1,59 @@
|
||||
import ajax from './ajax'
|
||||
import render from './render'
|
||||
import bindEvent from './bind-event'
|
||||
|
||||
const DEFAULT_OPTS = {
|
||||
el: '#app',
|
||||
title: document.title,
|
||||
sep: ' - '
|
||||
}
|
||||
|
||||
class Docsify {
|
||||
constructor (opts) {
|
||||
Docsify.installed = true
|
||||
|
||||
this.replace = true
|
||||
this.opts = Object.assign({}, opts, DEFAULT_OPTS)
|
||||
this.dom = document.querySelector(this.opts.el)
|
||||
if (!this.dom) {
|
||||
this.dom = document.body
|
||||
this.replace = false
|
||||
}
|
||||
this.loc = document.location.pathname
|
||||
if (/\/$/.test(this.loc)) this.loc += 'README'
|
||||
this.load()
|
||||
}
|
||||
|
||||
load () {
|
||||
ajax(`${this.loc}.md`).then(res => {
|
||||
const target = res.target
|
||||
if (target.status >= 400) {
|
||||
this.render('not found')
|
||||
} else {
|
||||
this.render(res.target.response)
|
||||
bindEvent()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
render (content) {
|
||||
document.title = this.loc.slice(1) + this.opts.sep + this.opts.title
|
||||
this.dom[this.replace ? 'outerHTML' : 'innerHTML'] = render(content)
|
||||
}
|
||||
}
|
||||
|
||||
Docsify.use = function () {
|
||||
const plugin = arguments[0]
|
||||
if (typeof plugin === 'function') {
|
||||
plugin.call(Docsify)
|
||||
} else {
|
||||
throw TypeError('[docsify] Invalid plugin ' + plugin.name)
|
||||
}
|
||||
}
|
||||
|
||||
window.addEventListener('load', () => {
|
||||
if (Docsify.installed) return
|
||||
new Docsify()
|
||||
})
|
||||
|
||||
export default Docsify
|
39
src/gen-toc.js
Normal file
39
src/gen-toc.js
Normal file
@ -0,0 +1,39 @@
|
||||
/**
|
||||
* @link from https://github.com/killercup/grock/blob/5280ae63e16c5739e9233d9009bc235ed7d79a50/styles/solarized/assets/js/behavior.coffee#L54-L81
|
||||
*/
|
||||
const tocToTree = function (toc) {
|
||||
const headlines = []
|
||||
const last = {}
|
||||
|
||||
toc.forEach(headline => {
|
||||
const level = headline.level || 1
|
||||
const len = level - 1
|
||||
|
||||
if (last[len]) {
|
||||
last[len].children = last[len].children || []
|
||||
last[len].children.push(headline)
|
||||
} else {
|
||||
headlines.push(headline)
|
||||
last[level] = headline
|
||||
}
|
||||
})
|
||||
|
||||
return headlines
|
||||
}
|
||||
|
||||
const buildHeadlinesTree = function (tree, tpl = '') {
|
||||
if (!tree || !tree.length) return ''
|
||||
|
||||
tree.forEach((node) => {
|
||||
tpl += `<li><a class="section-link" href="#${node.slug}">${node.title}</a></li>`
|
||||
if (node.children) {
|
||||
tpl += `<li><ul class="children">${buildHeadlinesTree(node.children)}</li>`
|
||||
}
|
||||
})
|
||||
|
||||
return tpl + '</ul>'
|
||||
}
|
||||
|
||||
export default function (toc) {
|
||||
return buildHeadlinesTree(tocToTree(toc), '<ul>')
|
||||
}
|
35
src/index.js
35
src/index.js
@ -1,35 +0,0 @@
|
||||
import ajax from './ajax'
|
||||
import render from './render'
|
||||
|
||||
class Docsify {
|
||||
constructor (opts = {}) {
|
||||
Docsify.installed = true
|
||||
|
||||
this.dom = document.querySelector(opts.el || 'body')
|
||||
this.loc = document.location.pathname
|
||||
this.loc = this.loc === '/' ? 'README' : this.loc
|
||||
this.load()
|
||||
}
|
||||
|
||||
load () {
|
||||
ajax(`${this.loc}.md`).then(res => {
|
||||
const target = res.target
|
||||
if (target.status >= 400) {
|
||||
this.render('not found')
|
||||
} else {
|
||||
this.render(res.target.response)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
render (content) {
|
||||
this.dom.innerHTML = render(content)
|
||||
}
|
||||
}
|
||||
|
||||
window.addEventListener('load', () => {
|
||||
if (Docsify.installed) return
|
||||
new Docsify()
|
||||
})
|
||||
|
||||
export default Docsify
|
10
src/plugins/nav.js
Normal file
10
src/plugins/nav.js
Normal file
@ -0,0 +1,10 @@
|
||||
const Nav = function () {
|
||||
console.log(this)
|
||||
}
|
||||
Nav.name = 'Doscify.Nav'
|
||||
|
||||
if (window.Docsify) {
|
||||
window.Docsify.use(Nav)
|
||||
}
|
||||
|
||||
export default Nav
|
@ -1,6 +1,8 @@
|
||||
import marked from 'marked'
|
||||
import Prism from 'prismjs'
|
||||
import genToc from './gen-toc'
|
||||
|
||||
const toc = []
|
||||
const renderer = new marked.Renderer()
|
||||
|
||||
/**
|
||||
@ -8,19 +10,24 @@ const renderer = new marked.Renderer()
|
||||
* @link https://github.com/chjj/marked#overriding-renderer-methods
|
||||
*/
|
||||
renderer.heading = function (text, level) {
|
||||
const escapedText = text.toLowerCase().replace(/[^\w]+/g, '-')
|
||||
const slug = text.toLowerCase().replace(/[\s\n\t]+/g, '-')
|
||||
|
||||
return '<h' + level + '><a name="' + escapedText + '" class="anchor" href="#' +
|
||||
escapedText + '"><span class="header-link"></span></a>' + text +
|
||||
'</h' + level + '>'
|
||||
toc.push({ level, slug, title: text })
|
||||
|
||||
return `<h${level} id="${slug}"><a href="#${slug}" class="anchor"></a>${text}</h${level}>`
|
||||
}
|
||||
|
||||
marked.setOptions({
|
||||
renderer,
|
||||
highlight (code, lang) {
|
||||
return Prism.highlight(code, Prism.languages[lang])
|
||||
return Prism.highlight(code, Prism.languages[lang] || Prism.languages.markup)
|
||||
}
|
||||
})
|
||||
|
||||
export default function (content) {
|
||||
return marked(content, { renderer })
|
||||
const section = `<section class="content">
|
||||
<article class="markdown-section">${marked(content)}</article>
|
||||
</section>`
|
||||
const sidebar = `<aside class="sidebar">${genToc(toc)}</aside>`
|
||||
|
||||
return `<main>${sidebar}${section}</main>`
|
||||
}
|
||||
|
437
src/themes/vue.css
Normal file
437
src/themes/vue.css
Normal file
@ -0,0 +1,437 @@
|
||||
@import url('https://fonts.googleapis.com/css?family=Roboto+Mono|Source+Sans+Pro:300,400,600');
|
||||
|
||||
* {
|
||||
-webkit-box-sizing: border-box;
|
||||
-moz-box-sizing: border-box;
|
||||
box-sizing: border-box;
|
||||
-webkit-overflow-scrolling: touch;
|
||||
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
|
||||
-webkit-text-size-adjust: none;
|
||||
-webkit-touch-callout: none;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
}
|
||||
|
||||
html, body {
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
body {
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
background-color: #fff;
|
||||
color: #34495e;
|
||||
font-family: 'Source Sans Pro', 'Helvetica Neue', Arial, sans-serif;
|
||||
font-size: 15px;
|
||||
letter-spacing: 0;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
li a {
|
||||
color: #42b983;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
/* main */
|
||||
main {
|
||||
height: 100%;
|
||||
position: relative;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
/* sidebar */
|
||||
.sidebar {
|
||||
background-color: #fff;
|
||||
border-right: 1px solid rgba(0,0,0,.07);
|
||||
bottom: 0;
|
||||
color: #364149;
|
||||
overflow-y: auto;
|
||||
position: absolute;
|
||||
top: 0;
|
||||
width: 300px;
|
||||
z-index: 1;
|
||||
padding-top: 40px;
|
||||
}
|
||||
|
||||
.sidebar ul {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.sidebar ul, .sidebar ul li {
|
||||
list-style: none;
|
||||
}
|
||||
|
||||
.sidebar ul li a {
|
||||
color: #7f8c8d;
|
||||
display: block;
|
||||
padding: 10px 15px;
|
||||
border-bottom: none;
|
||||
text-overflow: ellipsis;
|
||||
overflow: hidden;
|
||||
white-space: nowrap;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.sidebar ul li a:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.sidebar ul li.active>a {
|
||||
color: #42b983;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.sidebar ul li ul {
|
||||
padding-left: 20px;
|
||||
}
|
||||
|
||||
/* main content */
|
||||
.content {
|
||||
bottom: 0;
|
||||
left: 300px;
|
||||
overflow-y: auto;
|
||||
position: absolute;
|
||||
right: 0;
|
||||
top: 0;
|
||||
overflow-x: hidden;
|
||||
padding-top: 20px;
|
||||
}
|
||||
|
||||
/* markdown content found on pages */
|
||||
.markdown-section {
|
||||
position: relative;
|
||||
margin: 0 auto;
|
||||
max-width: 800px;
|
||||
padding: 20px 15px 40px 15px;
|
||||
}
|
||||
|
||||
.markdown-section * {
|
||||
box-sizing: border-box;
|
||||
-webkit-box-sizing: border-box;
|
||||
font-size: inherit;
|
||||
}
|
||||
|
||||
.markdown-section>:first-child {
|
||||
margin-top: 0!important;
|
||||
}
|
||||
|
||||
.markdown-section h1,
|
||||
.markdown-section h2,
|
||||
.markdown-section h3,
|
||||
.markdown-section h4,
|
||||
.markdown-section strong {
|
||||
font-weight: 600;
|
||||
color: #2c3e50;
|
||||
}
|
||||
|
||||
.markdown-section a {
|
||||
color: #42b983;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.markdown-section p,
|
||||
.markdown-section ul,
|
||||
.markdown-section ol {
|
||||
word-spacing: 0.05em;
|
||||
}
|
||||
|
||||
.markdown-section h1 {
|
||||
margin: 0 0 1em;
|
||||
font-size: 2em;
|
||||
}
|
||||
|
||||
.markdown-section h2 {
|
||||
border-bottom: 1px solid #ddd;
|
||||
font-size: 1.75em;
|
||||
margin: 45px 0 0.8em;
|
||||
padding-bottom: 0.7em;
|
||||
}
|
||||
|
||||
.markdown-section h3 {
|
||||
margin: 52px 0 1.2em;
|
||||
font-size: 1.5em;
|
||||
}
|
||||
|
||||
|
||||
.markdown-section h4 {
|
||||
font-size: 1.25em;
|
||||
}
|
||||
|
||||
.markdown-section h5 {
|
||||
font-size: 1em;
|
||||
}
|
||||
|
||||
.markdown-section h6 {
|
||||
font-size: 1em;
|
||||
color: #777;
|
||||
}
|
||||
|
||||
.markdown-section figure,
|
||||
.markdown-section p,
|
||||
.markdown-section ul,
|
||||
.markdown-section ol {
|
||||
margin: 1.2em 0;
|
||||
}
|
||||
|
||||
.markdown-section p,
|
||||
.markdown-section ul,
|
||||
.markdown-section ol {
|
||||
line-height: 1.6em;
|
||||
}
|
||||
|
||||
.markdown-section ul,
|
||||
.markdown-section ol {
|
||||
padding-left: 1.5em;
|
||||
}
|
||||
|
||||
.markdown-section a {
|
||||
color: #42b983;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.markdown-section blockquote {
|
||||
color: #858585;
|
||||
border-left: 4px solid #42b983;
|
||||
margin: 2em 0;
|
||||
padding-left: 20px;
|
||||
}
|
||||
|
||||
.markdown-section blockquote p {
|
||||
font-weight: 600;
|
||||
margin-left: 0;
|
||||
}
|
||||
|
||||
.markdown-section iframe {
|
||||
margin: 1em 0;
|
||||
}
|
||||
|
||||
.markdown-section em {
|
||||
color: #7f8c8d;
|
||||
}
|
||||
|
||||
.markdown-section code {
|
||||
border-radius: 2px;
|
||||
color: #e96900;
|
||||
margin: 0 2px;
|
||||
padding: 3px 5px;
|
||||
white-space: nowrap;
|
||||
font-size: 0.8em;
|
||||
}
|
||||
|
||||
.markdown-section pre {
|
||||
padding: 1.2em 1.4em;
|
||||
line-height: 1.5em;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.markdown-section code, .markdown-section pre {
|
||||
font-family: 'Roboto Mono', Monaco, courier, monospace;
|
||||
-webkit-font-smoothing: initial;
|
||||
-moz-osx-font-smoothing: initial;
|
||||
background-color: #f8f8f8;
|
||||
}
|
||||
|
||||
/* code highlight */
|
||||
.token.comment,
|
||||
.token.prolog,
|
||||
.token.doctype,
|
||||
.token.cdata {
|
||||
color: #8e908c;
|
||||
}
|
||||
|
||||
.token.namespace {
|
||||
opacity: .7;
|
||||
}
|
||||
|
||||
.token.boolean,
|
||||
.token.number {
|
||||
color: #c76b29;
|
||||
}
|
||||
|
||||
.token.punctuation {
|
||||
color: #525252;
|
||||
}
|
||||
|
||||
.token.property {
|
||||
color: #c08b30;
|
||||
}
|
||||
|
||||
.token.tag {
|
||||
color: #2973b7;
|
||||
}
|
||||
|
||||
.token.string {
|
||||
color: #42b983;
|
||||
}
|
||||
|
||||
.token.selector {
|
||||
color: #6679cc;
|
||||
}
|
||||
|
||||
.token.attr-name {
|
||||
color: #2973b7;
|
||||
}
|
||||
|
||||
.token.entity,
|
||||
.token.url,
|
||||
.language-css .token.string,
|
||||
.style .token.string {
|
||||
color: #22a2c9;
|
||||
}
|
||||
|
||||
.token.attr-value,
|
||||
.token.control,
|
||||
.token.directive,
|
||||
.token.unit {
|
||||
color: #42b983;
|
||||
}
|
||||
|
||||
.token.keyword {
|
||||
color: #e96900;
|
||||
}
|
||||
|
||||
.token.statement,
|
||||
.token.regex,
|
||||
.token.atrule {
|
||||
color: #22a2c9;
|
||||
}
|
||||
|
||||
.token.placeholder,
|
||||
.token.variable {
|
||||
color: #3d8fd1;
|
||||
}
|
||||
|
||||
.token.deleted {
|
||||
text-decoration: line-through;
|
||||
}
|
||||
|
||||
.token.inserted {
|
||||
border-bottom: 1px dotted #202746;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.token.italic {
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
.token.important,
|
||||
.token.bold {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.token.important {
|
||||
color: #c94922;
|
||||
}
|
||||
|
||||
.token.entity {
|
||||
cursor: help;
|
||||
}
|
||||
|
||||
/* overrides color-values for the Line Numbers plugin
|
||||
* http://prismjs.com/plugins/line-numbers/
|
||||
*/
|
||||
.line-numbers .line-numbers-rows {
|
||||
border-right-color: #dfe2f1;
|
||||
}
|
||||
|
||||
.line-numbers-rows > span:before {
|
||||
color: #979db4;
|
||||
}
|
||||
|
||||
/* overrides color-values for the Line Highlight plugin
|
||||
* http://prismjs.com/plugins/line-highlight/
|
||||
*/
|
||||
.line-highlight {
|
||||
background: rgba(107, 115, 148, 0.2);
|
||||
background: -webkit-linear-gradient(left, rgba(107, 115, 148, 0.2) 70%, rgba(107, 115, 148, 0));
|
||||
background: linear-gradient(to right, rgba(107, 115, 148, 0.2) 70%, rgba(107, 115, 148, 0));
|
||||
}
|
||||
|
||||
.markdown-section pre>code {
|
||||
-moz-osx-font-smoothing: initial;
|
||||
-webkit-font-smoothing: initial;
|
||||
background-color: #f8f8f8;
|
||||
border-radius: 2px;
|
||||
color: #525252;
|
||||
display: block;
|
||||
font-family: 'Roboto Mono', Monaco, courier, monospace;
|
||||
font-size: 0.8em;
|
||||
line-height: inherit;
|
||||
margin: 0 2px;
|
||||
padding: 3px 5px;
|
||||
white-space: inherit;
|
||||
}
|
||||
|
||||
.markdown-section code:after, .markdown-section code:before {
|
||||
content: none;
|
||||
letter-spacing: 0.05em;
|
||||
}
|
||||
|
||||
code .token {
|
||||
min-height: 1.5em;
|
||||
-webkit-font-smoothing: initial;
|
||||
-moz-osx-font-smoothing: initial;
|
||||
}
|
||||
|
||||
pre code {
|
||||
overflow-x: auto;
|
||||
position: relative;
|
||||
padding: 0;
|
||||
background-color: #f8f8f8;
|
||||
padding: 0.8em 0.8em 0.4em;
|
||||
line-height: 1.1em;
|
||||
border-radius: 2px;
|
||||
}
|
||||
|
||||
pre code.lang-html:after,
|
||||
pre code.lang-js:after,
|
||||
pre code.lang-bash:after,
|
||||
pre code.lang-css:after {
|
||||
color: #ccc;
|
||||
font-size: 0.75em;
|
||||
font-weight: 600;
|
||||
height: 15px;
|
||||
line-height: 15px;
|
||||
padding: 5px 10px 0;
|
||||
position: absolute;
|
||||
right: 0;
|
||||
text-align: right;
|
||||
top: 0;
|
||||
}
|
||||
|
||||
pre code.lang-html:after {
|
||||
content: 'HTML';
|
||||
}
|
||||
|
||||
pre code.lang-js:after {
|
||||
content: 'JS';
|
||||
}
|
||||
|
||||
pre code.lang-bash:after {
|
||||
content: 'Shell';
|
||||
}
|
||||
|
||||
pre code.lang-css:after {
|
||||
content: 'CSS';
|
||||
}
|
||||
|
||||
.content img {
|
||||
max-width: 100%;
|
||||
}
|
||||
|
||||
.content span.light {
|
||||
color: #7f8c8d;
|
||||
}
|
||||
|
||||
.content span.info {
|
||||
display: inline-block;
|
||||
font-size: 0.85em;
|
||||
margin-left: 20px;
|
||||
vertical-align: middle;
|
||||
width: 280px;
|
||||
}
|
||||
|
||||
/* these aren't in gitbook at the moment, but leaving them in for future reference */
|
||||
img {
|
||||
border: none;
|
||||
}
|
@ -3,10 +3,12 @@
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>docsify</title>
|
||||
<link rel="stylesheet" href="themes/vue.css">
|
||||
<link rel="stylesheet" href="/themes/vue.css">
|
||||
</head>
|
||||
<body></body>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
</body>
|
||||
<script src="//unpkg.com/marked/marked.min.js"></script>
|
||||
<script src="//unpkg.com/prismjs/prism.js"></script>
|
||||
<script src="docsify.js"></script>
|
||||
<script src="/docsify.js"></script>
|
||||
</html>
|
||||
|
@ -1,27 +0,0 @@
|
||||
# docsify
|
||||
> A magical documentation generator.
|
||||
|
||||
## Usage
|
||||
Create `404.html` into `/docs`
|
||||
|
||||
```html
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<link rel="stylesheet" href="//unpkg.com/docsify/themes/vue.css">
|
||||
</head>
|
||||
<body></body>
|
||||
<script src="//unpkg.com/marked/marked.min.js"></script>
|
||||
<script src="//unpkg.com/highlight.js/lib/highlight.js"></script>
|
||||
<script src="//unpkg.com/docsify/lib/docsify.min.js"></script>
|
||||
</html>
|
||||
```
|
||||
|
||||
```javascript
|
||||
var a = require('a')
|
||||
console.log(a)
|
||||
```
|
||||
|
||||
## License
|
||||
MIT
|
1
test/README.md
Symbolic link
1
test/README.md
Symbolic link
@ -0,0 +1 @@
|
||||
../README.md
|
@ -1 +0,0 @@
|
||||
# Themes
|
@ -1 +1 @@
|
||||
../themes
|
||||
../src/themes
|
Loading…
Reference in New Issue
Block a user