mirror of
https://github.com/wahyd4/docsify.git
synced 2026-08-22 11:46:13 +10:00
Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
89389e786a | ||
|
|
a35531967a |
@@ -40,7 +40,7 @@
|
|||||||
- Smart full-text search plugin
|
- Smart full-text search plugin
|
||||||
- Multiple themes
|
- Multiple themes
|
||||||
- Useful plugin API
|
- Useful plugin API
|
||||||
- Compatible with IE10+
|
- Compatible with IE11
|
||||||
- Support SSR ([example](https://github.com/docsifyjs/docsify-ssr-demo))
|
- Support SSR ([example](https://github.com/docsifyjs/docsify-ssr-demo))
|
||||||
- Support embedded files
|
- Support embedded files
|
||||||
|
|
||||||
|
|||||||
Generated
+6
@@ -8791,6 +8791,12 @@
|
|||||||
"async-limiter": "~1.0.0"
|
"async-limiter": "~1.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"xhr2": {
|
||||||
|
"version": "0.1.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/xhr2/-/xhr2-0.1.4.tgz",
|
||||||
|
"integrity": "sha1-f4dliEdxbbUCYyOBL4GMras4el8=",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
"xml-name-validator": {
|
"xml-name-validator": {
|
||||||
"version": "3.0.0",
|
"version": "3.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/xml-name-validator/-/xml-name-validator-3.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/xml-name-validator/-/xml-name-validator-3.0.0.tgz",
|
||||||
|
|||||||
+3
-2
@@ -27,7 +27,7 @@
|
|||||||
"dev": "run-p serve watch:*",
|
"dev": "run-p serve watch:*",
|
||||||
"dev:ssr": "run-p serve:ssr watch:*",
|
"dev:ssr": "run-p serve:ssr watch:*",
|
||||||
"lint": "eslint {src,packages} --fix",
|
"lint": "eslint {src,packages} --fix",
|
||||||
"test": "mocha test/*/**",
|
"test": "mocha",
|
||||||
"css": "stylus src/themes/*.styl -u autoprefixer-stylus",
|
"css": "stylus src/themes/*.styl -u autoprefixer-stylus",
|
||||||
"watch:css": "run-p 'css -- -o themes -w'",
|
"watch:css": "run-p 'css -- -o themes -w'",
|
||||||
"watch:js": "node build/build.js",
|
"watch:js": "node build/build.js",
|
||||||
@@ -72,7 +72,8 @@
|
|||||||
"rollup-plugin-node-resolve": "^3.0.0",
|
"rollup-plugin-node-resolve": "^3.0.0",
|
||||||
"rollup-plugin-replace": "^2.0.0",
|
"rollup-plugin-replace": "^2.0.0",
|
||||||
"rollup-plugin-uglify": "^2.0.1",
|
"rollup-plugin-uglify": "^2.0.1",
|
||||||
"stylus": "^0.54.5"
|
"stylus": "^0.54.5",
|
||||||
|
"xhr2": "^0.1.4"
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"doc",
|
"doc",
|
||||||
|
|||||||
@@ -323,6 +323,9 @@ body.sticky
|
|||||||
|
|
||||||
.markdown-section iframe
|
.markdown-section iframe
|
||||||
border 1px solid #eee
|
border 1px solid #eee
|
||||||
|
/* fix horizontal overflow on iOS Safari */
|
||||||
|
width 1px
|
||||||
|
min-width 100%
|
||||||
|
|
||||||
.markdown-section table
|
.markdown-section table
|
||||||
border-collapse collapse
|
border-collapse collapse
|
||||||
|
|||||||
+45
-58
@@ -1,10 +1,45 @@
|
|||||||
// load ES6 modules in Node.js on the fly
|
// load ES6 modules in Node.js on the fly
|
||||||
require = require('esm')(module/*, options*/)
|
require = require('esm')(module/*, options*/)
|
||||||
|
|
||||||
const path = require('path')
|
|
||||||
const {expect} = require('chai')
|
const {expect} = require('chai')
|
||||||
|
|
||||||
const {JSDOM} = require('jsdom')
|
const {JSDOM} = require('jsdom')
|
||||||
|
const XMLHttpRequest = require('xhr2') // JSDOM doesn't support XMLHttpRequest
|
||||||
|
// TODO: try to fix tests when using `<div id="app"></div>` in body
|
||||||
|
const markup = `<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head></head>
|
||||||
|
<body></body>
|
||||||
|
</html>`
|
||||||
|
// TODO: this may not work if tests are mutate the DOM, instead a new instance needs to be created
|
||||||
|
// for every test case but that will slow down the tests
|
||||||
|
const dom = new JSDOM(markup)
|
||||||
|
|
||||||
|
global.window = dom.window
|
||||||
|
global.document = dom.window.document
|
||||||
|
global.navigator = dom.window.navigator
|
||||||
|
global.location = dom.window.location
|
||||||
|
global.XMLHttpRequest = XMLHttpRequest
|
||||||
|
|
||||||
|
const {initMixin} = require('../src/core/init')
|
||||||
|
const {routerMixin} = require('../src/core//router')
|
||||||
|
const {renderMixin} = require('../src/core//render')
|
||||||
|
const {fetchMixin} = require('../src/core/fetch')
|
||||||
|
const {eventMixin} = require('../src/core//event')
|
||||||
|
|
||||||
|
// mimic src/core/index.js but for Node.js
|
||||||
|
|
||||||
|
function Docsify() {
|
||||||
|
this._init()
|
||||||
|
}
|
||||||
|
|
||||||
|
const proto = Docsify.prototype
|
||||||
|
|
||||||
|
initMixin(proto)
|
||||||
|
routerMixin(proto)
|
||||||
|
renderMixin(proto)
|
||||||
|
fetchMixin(proto)
|
||||||
|
eventMixin(proto)
|
||||||
|
|
||||||
function ready(callback) {
|
function ready(callback) {
|
||||||
const state = document.readyState
|
const state = document.readyState
|
||||||
@@ -15,64 +50,16 @@ function ready(callback) {
|
|||||||
|
|
||||||
document.addEventListener('DOMContentLoaded', callback)
|
document.addEventListener('DOMContentLoaded', callback)
|
||||||
}
|
}
|
||||||
module.exports.init = function(fixture = 'default', config = {}, markup) {
|
let docsify = null
|
||||||
if (markup == null) {
|
module.exports.init = function(callback) {
|
||||||
markup = `<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head></head>
|
|
||||||
<body>
|
|
||||||
<div id="app"></div>
|
|
||||||
<script>
|
|
||||||
window.$docsify = ${JSON.stringify(config, null, 2)}
|
|
||||||
</script>
|
|
||||||
</body>
|
|
||||||
</html>`
|
|
||||||
}
|
|
||||||
const rootPath = path.join(__dirname, 'fixtures', fixture)
|
|
||||||
|
|
||||||
const dom = new JSDOM(markup)
|
|
||||||
dom.reconfigure({ url: 'file:///' + rootPath })
|
|
||||||
|
|
||||||
global.window = dom.window
|
|
||||||
global.document = dom.window.document
|
|
||||||
global.navigator = dom.window.navigator
|
|
||||||
global.location = dom.window.location
|
|
||||||
global.XMLHttpRequest = dom.window.XMLHttpRequest
|
|
||||||
|
|
||||||
// mimic src/core/index.js but for Node.js
|
|
||||||
function Docsify() {
|
|
||||||
this._init()
|
|
||||||
}
|
|
||||||
|
|
||||||
const proto = Docsify.prototype
|
|
||||||
|
|
||||||
const {initMixin} = require('../src/core/init')
|
|
||||||
const {routerMixin} = require('../src/core//router')
|
|
||||||
const {renderMixin} = require('../src/core//render')
|
|
||||||
const {fetchMixin} = require('../src/core/fetch')
|
|
||||||
const {eventMixin} = require('../src/core//event')
|
|
||||||
|
|
||||||
initMixin(proto)
|
|
||||||
routerMixin(proto)
|
|
||||||
renderMixin(proto)
|
|
||||||
fetchMixin(proto)
|
|
||||||
eventMixin(proto)
|
|
||||||
|
|
||||||
const NOT_INIT_PATTERN = '<!--main-->'
|
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
ready(() => {
|
// return cached version / TODO: see above: this might not scale, new instance of JSDOM is reqiured
|
||||||
const docsify = new Docsify()
|
if (docsify != null) {
|
||||||
// NOTE: I was not able to get it working with a callback, but polling works usually at the first time
|
return resolve(docsify)
|
||||||
const id = setInterval(() => {
|
}
|
||||||
if (dom.window.document.body.innerHTML.indexOf(NOT_INIT_PATTERN) == -1) {
|
ready(_ => {
|
||||||
clearInterval(id)
|
docsify = new Docsify()
|
||||||
return resolve({
|
return resolve(docsify)
|
||||||
docsify: docsify,
|
|
||||||
dom: dom
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}, 10)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|||||||
Vendored
-6
@@ -1,6 +0,0 @@
|
|||||||
<!--
|
|
||||||
|
|
||||||
create your own fixture directory
|
|
||||||
if you need a custom README.md or sidebar
|
|
||||||
|
|
||||||
-->
|
|
||||||
Vendored
-18
@@ -1,18 +0,0 @@
|
|||||||
# Heading
|
|
||||||
|
|
||||||
[another page](other.md)
|
|
||||||
|
|
||||||
## II 1
|
|
||||||
|
|
||||||
### III 1
|
|
||||||
|
|
||||||
#### IV 1
|
|
||||||
|
|
||||||
##### V 1
|
|
||||||
|
|
||||||
|
|
||||||
## II 2
|
|
||||||
|
|
||||||
### III 2
|
|
||||||
|
|
||||||
#### IV 2
|
|
||||||
Vendored
-16
@@ -1,16 +0,0 @@
|
|||||||
# Other
|
|
||||||
|
|
||||||
## two 1
|
|
||||||
|
|
||||||
### three 1
|
|
||||||
|
|
||||||
#### four 1
|
|
||||||
|
|
||||||
##### five 1
|
|
||||||
|
|
||||||
|
|
||||||
## two 2
|
|
||||||
|
|
||||||
### three 2
|
|
||||||
|
|
||||||
#### four 2
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
const path = require('path')
|
|
||||||
|
|
||||||
const {expect} = require('chai')
|
|
||||||
|
|
||||||
const {init, expectSameDom} = require('../_helper')
|
|
||||||
|
|
||||||
describe('full docsify initialization', function() {
|
|
||||||
it('TODO: check generated markup', async function() {
|
|
||||||
const {docsify, dom} = await init('simple', {loadSidebar: true})
|
|
||||||
console.log(dom.window.document.body.innerHTML)
|
|
||||||
// TODO: add some expectations
|
|
||||||
})
|
|
||||||
|
|
||||||
})
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
const path = require('path')
|
|
||||||
|
|
||||||
const {expect} = require('chai')
|
|
||||||
|
|
||||||
const {init, expectSameDom} = require('../_helper')
|
|
||||||
|
|
||||||
describe('router', function() {
|
|
||||||
it('TODO: trigger to load another page', async function() {
|
|
||||||
const {docsify} = await init()
|
|
||||||
window.location = '/?foo=bar'
|
|
||||||
// TODO: add some expectations
|
|
||||||
})
|
|
||||||
|
|
||||||
})
|
|
||||||
@@ -2,18 +2,18 @@ const path = require('path')
|
|||||||
|
|
||||||
const {expect} = require('chai')
|
const {expect} = require('chai')
|
||||||
|
|
||||||
const {init, expectSameDom} = require('../_helper')
|
const {init, expectSameDom} = require('./_helper')
|
||||||
|
|
||||||
describe('render', function() {
|
describe('render', function() {
|
||||||
it('important content (tips)', async function() {
|
it('important content (tips)', async function() {
|
||||||
const {docsify, dom} = await init()
|
docsify = await init()
|
||||||
const output = docsify.compiler.compile('!> **Time** is money, my friend!')
|
const output = docsify.compiler.compile('!> **Time** is money, my friend!')
|
||||||
expect(output).equal('<p class="tip"><strong>Time</strong> is money, my friend!</p>')
|
expect(output).equal('<p class="tip"><strong>Time</strong> is money, my friend!</p>')
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('lists', function() {
|
describe('lists', function() {
|
||||||
it('as unordered task list', async function() {
|
it('as unordered task list', async function() {
|
||||||
const {docsify, dom} = await init()
|
docsify = await init()
|
||||||
const output = docsify.compiler.compile(`
|
const output = docsify.compiler.compile(`
|
||||||
- [x] Task 1
|
- [x] Task 1
|
||||||
- [ ] Task 2
|
- [ ] Task 2
|
||||||
@@ -26,7 +26,7 @@ describe('render', function() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('as ordered task list', async function() {
|
it('as ordered task list', async function() {
|
||||||
const {docsify, dom} = await init()
|
docsify = await init()
|
||||||
const output = docsify.compiler.compile(`
|
const output = docsify.compiler.compile(`
|
||||||
1. [ ] Task 1
|
1. [ ] Task 1
|
||||||
2. [x] Task 2`)
|
2. [x] Task 2`)
|
||||||
@@ -37,7 +37,7 @@ describe('render', function() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('normal unordered', async function() {
|
it('normal unordered', async function() {
|
||||||
const {docsify, dom} = await init()
|
docsify = await init()
|
||||||
const output = docsify.compiler.compile(`
|
const output = docsify.compiler.compile(`
|
||||||
- [linktext](link)
|
- [linktext](link)
|
||||||
- just text`)
|
- just text`)
|
||||||
@@ -48,7 +48,7 @@ describe('render', function() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('unordered with custom start', async function() {
|
it('unordered with custom start', async function() {
|
||||||
const {docsify, dom} = await init()
|
docsify = await init()
|
||||||
const output = docsify.compiler.compile(`
|
const output = docsify.compiler.compile(`
|
||||||
1. first
|
1. first
|
||||||
2. second
|
2. second
|
||||||
@@ -67,7 +67,7 @@ text
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('nested', async function() {
|
it('nested', async function() {
|
||||||
const {docsify, dom} = await init()
|
docsify = await init()
|
||||||
const output = docsify.compiler.compile(`
|
const output = docsify.compiler.compile(`
|
||||||
- 1
|
- 1
|
||||||
- 2
|
- 2
|
||||||
Reference in New Issue
Block a user