Skip to content

Commit

Permalink
Merge branch 'develop' into allow-config-function
Browse files Browse the repository at this point in the history
  • Loading branch information
trusktr committed Jun 7, 2020
2 parents 63f1b88 + 7853026 commit 809fda9
Show file tree
Hide file tree
Showing 28 changed files with 2,116 additions and 1,639 deletions.
4 changes: 4 additions & 0 deletions .github/semantic.yml
@@ -0,0 +1,4 @@
titleAndCommits: true
allowMergeCommits: true
allowRevertCommits: true
anyCommit: true
2 changes: 1 addition & 1 deletion cypress/fixtures/tpl/docs.index.html
Expand Up @@ -16,7 +16,7 @@
<meta name="description" content="A magical documentation generator." />
<meta
name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"
content="width=device-width, initial-scale=1.0, minimum-scale=1.0"
/>
<link rel="stylesheet" href="lib/themes/vue.css" title="vue" />
<link rel="stylesheet" href="lib/themes/dark.css" title="dark" disabled />
Expand Down
6 changes: 6 additions & 0 deletions docs/_media/example-with-yaml.md
@@ -0,0 +1,6 @@
---
author: John Smith
date: 2020-1-1
---

> This is from the `example.md`
14 changes: 12 additions & 2 deletions docs/configuration.md
Expand Up @@ -162,6 +162,16 @@ window.$docsify = {
};
```

If you have a link to the homepage in the sidebar and want it to be shown as active when accessing the root url, make sure to update your sidebar accordingly:

```markdown
- Sidebar
- [Home](/)
- [Another page](another.md)
```

For more details, see [#1131](https://github.com/docsifyjs/docsify/issues/1131).

## basePath

- Type: `String`
Expand Down Expand Up @@ -464,11 +474,11 @@ window.$docsify = {
- type: `String`
- default: `noopener`

Default `'noopener'` (no opener) prevents the newly opened external page (when [externalLinkTarget](#externallinktarget) is `'_blank'`) from having the ability to control our page. No `rel` is set when its not `'_blank'`.
Default `'noopener'` (no opener) prevents the newly opened external page (when [externalLinkTarget](#externallinktarget) is `'_blank'`) from having the ability to control our page. No `rel` is set when its not `'_blank'`. See [this post](https://mathiasbynens.github.io/rel-noopener/) for more information about why you may want to use this option.

```js
window.$docsify = {
externalLinkTarget: '', // default: 'noopener'
externalLinkRel: '', // default: 'noopener'
};
```

Expand Down
14 changes: 13 additions & 1 deletion docs/embed-files.md
Expand Up @@ -39,7 +39,20 @@ You will get it

[filename](_media/example.md ':include :type=code')

## Markdown with YAML Front Matter

When using Markdown, YAML front matter will be stripped from the rendered content. The attributes cannot be used in this case.

```markdown
[filename](_media/example-with-yaml.md ':include')
```

You will get just the content

[filename](_media/example-with-yaml.md ':include')

## Embedded code fragments

Sometimes you don't want to embed a whole file. Maybe because you need just a few lines but you want to compile and test the file in CI.

```markdown
Expand All @@ -53,7 +66,6 @@ Example:

[filename](_media/example.js ':include :type=code :fragment=demo')


## Tag attribute

If you embed the file as `iframe`, `audio` and `video`, then you may need to set the attributes of these tags.
Expand Down
8 changes: 8 additions & 0 deletions docs/helpers.md
Expand Up @@ -65,6 +65,14 @@ You will get `<a href="/demo/">link</a>`html. Do not worry, you can still set ti
[link](/demo ':disabled')
```

## Cross-Origin link

Only when you both set the `routerMode: 'history'` and `externalLinkTarget: '_self'`, you need add this configuration for those Cross-Origin links.

```md
[example.com](https://example.com/ ':crossorgin')
```

## Github Task Lists

```md
Expand Down
31 changes: 21 additions & 10 deletions docs/index.html
Expand Up @@ -9,14 +9,20 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="keywords" content="doc,docs,documentation,gitbook,creator,generator,github,jekyll,github-pages">
<meta name="description" content="A magical documentation generator.">
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/docsify/lib/themes/vue.css" title="vue">

<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0">
<link
rel="stylesheet"
href="//cdn.jsdelivr.net/npm/docsify-darklight-theme@3/dist/docsify-style.min.css"
title="docsify-darklight-theme"
type="text/css"
/>
<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/docsify/lib/themes/vue.css" title="vue" disabled>
<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/docsify/lib/themes/dark.css" title="dark" disabled>
<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/docsify/lib/themes/buble.css" title="buble" disabled>
<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/docsify/lib/themes/pure.css" title="pure" disabled>

<script src="//cdn.jsdelivr.net/npm/docsify-plugin-codefund/index.js"></script>
<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/docsify-dark-mode@0.6.1/dist/style.css"/>
<style>
nav.app-nav li ul {
min-width: 100px;
Expand All @@ -32,7 +38,7 @@
'.*?/awesome': 'https://raw.githubusercontent.com/docsifyjs/awesome-docsify/master/README.md',
'.*?/changelog': 'https://raw.githubusercontent.com/docsifyjs/docsify/master/CHANGELOG.md',
'/.*/_navbar.md': '/_navbar.md',
'/zh-cn/(.*)': 'https://raw.githubusercontent.com/docsifyjs/docs-zh/master/$1',
'/zh-cn/(.*)': 'https://cdn.jsdelivr.net/gh/docsifyjs/docs-zh@master/$1',
'/de-de/(.*)': 'https://raw.githubusercontent.com/docsifyjs/docs-de/master/$1',
'/ru/(.*)': 'https://raw.githubusercontent.com/docsifyjs/docs-ru/master/$1',
'/es/(.*)': 'https://raw.githubusercontent.com/docsifyjs/docs-es/master/$1'
Expand Down Expand Up @@ -64,10 +70,8 @@
'/': 'Search'
}
},
darkMode: {
light: {
toggleBtnBg: '#42b983'
}
darklightTheme: {
bodyFontSize : '15px',
},
formatUpdated: '{MM}/{DD} {HH}:{mm}',
plugins: [
Expand All @@ -77,6 +81,10 @@
url = vm.route.file
.replace('raw.githubusercontent.com', 'github.com')
.replace(/\/master/, '/blob/master')
} else if (/jsdelivr\.net/.test(vm.route.file)) {
url = vm.route.file
.replace('cdn.jsdelivr.net/gh', 'github.com')
.replace('@master', '/blob/master')
} else {
url = 'https://github.com/docsifyjs/docsify/blob/master/docs/' + vm.route.file
}
Expand All @@ -99,7 +107,10 @@
<script src="//cdn.jsdelivr.net/npm/prismjs/components/prism-bash.min.js"></script>
<script src="//cdn.jsdelivr.net/npm/prismjs/components/prism-markdown.min.js"></script>
<script src="//cdn.jsdelivr.net/npm/prismjs/components/prism-nginx.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/docsify-dark-mode@0.6.1/dist/index.js"></script>
<script
src="//cdn.jsdelivr.net/npm/docsify-darklight-theme@3/dist/index.min.js"
type="text/javascript">
</script>
<script>
((window.gitter = {}).chat = {}).options = {
room: 'docsifyjs/Lobby'
Expand Down
2 changes: 1 addition & 1 deletion docs/ssr.md
Expand Up @@ -68,7 +68,7 @@ You can provide a template for entire page's HTML. such as
<head>
<meta charset="UTF-8">
<title>docsify</title>
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0">
<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/docsify/themes/vue.css" title="vue">
</head>
<body>
Expand Down
8 changes: 7 additions & 1 deletion index.html
Expand Up @@ -24,7 +24,7 @@
'.*?/awesome': 'https://raw.githubusercontent.com/docsifyjs/awesome-docsify/master/README.md',
'.*?/changelog': 'https://raw.githubusercontent.com/docsifyjs/docsify/master/CHANGELOG.md',
'/.*/_navbar.md': '/_navbar.md',
'/zh-cn/(.*)': 'https://raw.githubusercontent.com/docsifyjs/docs-zh/master/$1',
'/zh-cn/(.*)': 'https://cdn.jsdelivr.net/gh/docsifyjs/docs-zh@master/$1',
'/de-de/(.*)': 'https://raw.githubusercontent.com/docsifyjs/docs-de/master/$1',
'/ru/(.*)': 'https://raw.githubusercontent.com/docsifyjs/docs-ru/master/$1',
'/es/(.*)': 'https://raw.githubusercontent.com/docsifyjs/docs-es/master/$1'
Expand Down Expand Up @@ -60,6 +60,10 @@
url = vm.route.file
.replace('raw.githubusercontent.com', 'github.com')
.replace(/\/master/, '/blob/master')
} else if (/jsdelivr\.net/.test(vm.route.file)) {
url = vm.route.file
.replace('cdn.jsdelivr.net/gh', 'github.com')
.replace('@master', '/blob/master')
} else {
url = 'https://github.com/docsifyjs/docsify/blob/master/docs/' + vm.route.file
}
Expand All @@ -76,6 +80,8 @@
</script>
<script src="/lib/docsify.js"></script>
<script src="/lib/plugins/search.js"></script>
<script src="/lib/plugins/emoji.js"></script>
<script src="/lib/plugins/front-matter.js"></script>
<script src="//unpkg.com/prismjs/components/prism-bash.min.js"></script>
<script src="//unpkg.com/prismjs/components/prism-markdown.min.js"></script>
<script src="//unpkg.com/prismjs/components/prism-nginx.min.js"></script>
Expand Down
2 changes: 1 addition & 1 deletion packages/docsify-server-renderer/README.md
Expand Up @@ -34,7 +34,7 @@ renderer.renderToString(url)
<head>
<meta charset="UTF-8">
<title>docsify</title>
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0">
<link rel="stylesheet" href="//unpkg.com/docsify/themes/buble.css" title="buble" disabled>
</head>
<body>
Expand Down
2 changes: 1 addition & 1 deletion server.js
Expand Up @@ -11,7 +11,7 @@ if (isSSR) {
<head>
<meta charset="UTF-8">
<title>docsify</title>
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0">
<link rel="stylesheet" href="/themes/vue.css" title="vue">
</head>
<body>
Expand Down
1 change: 1 addition & 0 deletions src/core/config.js
Expand Up @@ -32,6 +32,7 @@ export default function(vm) {
externalLinkRel: 'noopener',
routerMode: 'hash',
noCompileLinks: [],
crossOriginLinks: [],
relativePath: false,
topMargin: 0,
},
Expand Down
8 changes: 4 additions & 4 deletions src/core/event/scroll.js
@@ -1,6 +1,7 @@
import Tweezer from 'tweezer.js';
import { isMobile } from '../util/env';
import * as dom from '../util/dom';
import { removeParams } from '../router/util';
import config from '../config';

const nav = {};
Expand Down Expand Up @@ -59,8 +60,7 @@ function highlight(path) {
return;
}

const li =
nav[getNavKey(decodeURIComponent(path), last.getAttribute('data-id'))];
const li = nav[getNavKey(path, last.getAttribute('data-id'))];

if (!li || li === active) {
return;
Expand All @@ -86,7 +86,7 @@ function highlight(path) {
}

function getNavKey(path, id) {
return `${path}?id=${id}`;
return `${decodeURIComponent(path)}?id=${decodeURIComponent(id)}`;
}

export function scrollActiveSidebar(router) {
Expand Down Expand Up @@ -127,7 +127,7 @@ export function scrollActiveSidebar(router) {
return;
}

const path = router.getCurrentPath();
const path = removeParams(router.getCurrentPath());
dom.off('scroll', () => highlight(path));
dom.on('scroll', () => highlight(path));
dom.on(sidebar, 'mouseover', () => {
Expand Down
1 change: 1 addition & 0 deletions src/core/event/sidebar.js
Expand Up @@ -39,6 +39,7 @@ export function collapse(el) {
if (
target.nodeName === 'A' &&
target.nextSibling &&
target.nextSibling.classList &&
target.nextSibling.classList.contains('app-sub-sidebar')
) {
dom.toggleClass(target.parentNode, 'collapse');
Expand Down
18 changes: 17 additions & 1 deletion src/core/render/compiler.js
Expand Up @@ -121,6 +121,21 @@ export class Compiler {
};
}

/**
* Pulls content from file and renders inline on the page as a embedded item.
*
* This allows you to embed different file types on the returned
* page.
* The basic format is:
* ```
* [filename](_media/example.md ':include')
* ```
*
* @param {string} href The href to the file to embed in the page.
* @param {string} title Title of the link used to make the embed.
*
* @return {type} Return value description.
*/
compileEmbed(href, title) {
const { str, config } = getAndRemoveConfig(title);
let embed;
Expand Down Expand Up @@ -178,7 +193,7 @@ export class Compiler {

_initRenderer() {
const renderer = new marked.Renderer();
const { linkTarget, router, contentBase } = this;
const { linkTarget, linkRel, router, contentBase } = this;
const _self = this;
const origin = {};

Expand Down Expand Up @@ -218,6 +233,7 @@ export class Compiler {
renderer,
router,
linkTarget,
linkRel,
compilerClass: _self,
});
origin.paragraph = paragraphCompiler({ renderer });
Expand Down
2 changes: 1 addition & 1 deletion src/core/render/compiler/image.js
Expand Up @@ -22,7 +22,7 @@ export const imageCompiler = ({ renderer, contentBase, router }) =>
if (height) {
attrs.push(`width="${width}" height="${height}"`);
} else {
attrs.push(`width="${width}" height="${width}"`);
attrs.push(`width="${width}"`);
}
}

Expand Down
32 changes: 28 additions & 4 deletions src/core/render/compiler/link.js
@@ -1,11 +1,21 @@
import { getAndRemoveConfig } from '../utils';
import { isAbsolutePath } from '../../router/util';

export const linkCompiler = ({ renderer, router, linkTarget, compilerClass }) =>
export const linkCompiler = ({
renderer,
router,
linkTarget,
linkRel,
compilerClass,
}) =>
(renderer.link = (href, title = '', text) => {
let attrs = [];
const { str, config } = getAndRemoveConfig(title);

linkTarget = config.target || linkTarget;
linkRel =
linkTarget === '_blank'
? compilerClass.config.externalLinkRel || 'noopener'
: '';
title = str;

if (
Expand All @@ -24,10 +34,24 @@ export const linkCompiler = ({ renderer, router, linkTarget, compilerClass }) =>
document.URL.replace(/\/(?!.*\/).*/, '/').replace('#/./', '') + href;
}
attrs.push(href.indexOf('mailto:') === 0 ? '' : `target="${linkTarget}"`);
attrs.push(
href.indexOf('mailto:') === 0
? ''
: linkRel !== ''
? ` rel="${linkRel}"`
: ''
);
}

if (config.target) {
attrs.push(`target="${config.target}"`);
// special case to check crossorigin urls
if (
config.crossorgin &&
linkTarget === '_self' &&
compilerClass.config.routerMode === 'history'
) {
if (compilerClass.config.crossOriginLinks.indexOf(href) === -1) {
compilerClass.config.crossOriginLinks.push(href);
}
}

if (config.disabled) {
Expand Down

0 comments on commit 809fda9

Please sign in to comment.