Skip to content

Commit 3d662a5

Browse files
committed
fix: fixed target and rel issue (fixes #1183)
1 parent 9ff4d06 commit 3d662a5

File tree

10 files changed

+117
-95
lines changed

10 files changed

+117
-95
lines changed

packages/docsify-server-renderer/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { readFileSync } from 'fs';
22
import { resolve, basename } from 'path';
33
import resolvePathname from 'resolve-pathname';
4+
import fetch from 'node-fetch';
5+
import debug from 'debug';
46
import { AbstractHistory } from '../../src/core/router/history/abstract';
57
import { Compiler } from '../../src/core/render/compiler';
68
import { isAbsolutePath } from '../../src/core/router/util';
79
import * as tpl from '../../src/core/render/tpl';
810
import { prerenderEmbed } from '../../src/core/render/embed';
9-
import fetch from 'node-fetch';
10-
import debug from 'debug';
1111

1212
function cwd(...args) {
1313
return resolve(process.cwd(), ...args);

src/core/event/scroll.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
import Tweezer from 'tweezer.js';
12
import { isMobile } from '../util/env';
23
import * as dom from '../util/dom';
34
import { removeParams } from '../router/util';
45
import config from '../config';
5-
import Tweezer from 'tweezer.js';
66

77
const nav = {};
88
let hoverOver = false;

src/core/global-api.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
import prism from 'prismjs';
2+
import marked from 'marked';
13
import * as util from './util';
24
import * as dom from './util/dom';
35
import { Compiler } from './render/compiler';
46
import { slugify } from './render/slugify';
57
import { get } from './fetch/ajax';
6-
import prism from 'prismjs';
7-
import marked from 'marked';
88

99
export default function() {
1010
window.Docsify = {

src/core/render/compiler.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import marked from 'marked';
12
import { isAbsolutePath, getPath, getParentPath } from '../router/util';
23
import { isFn, merge, cached, isPrimitive } from '../util/core';
34
import { tree as treeTpl } from './tpl';
@@ -11,7 +12,6 @@ import { paragraphCompiler } from './compiler/paragraph';
1112
import { taskListCompiler } from './compiler/taskList';
1213
import { taskListItemCompiler } from './compiler/taskListItem';
1314
import { linkCompiler } from './compiler/link';
14-
import marked from 'marked';
1515

1616
const cachedLinks = {};
1717

@@ -193,7 +193,7 @@ export class Compiler {
193193

194194
_initRenderer() {
195195
const renderer = new marked.Renderer();
196-
const { linkTarget, router, contentBase } = this;
196+
const { linkTarget, linkRel, router, contentBase } = this;
197197
const _self = this;
198198
const origin = {};
199199

@@ -233,6 +233,7 @@ export class Compiler {
233233
renderer,
234234
router,
235235
linkTarget,
236+
linkRel,
236237
compilerClass: _self,
237238
});
238239
origin.paragraph = paragraphCompiler({ renderer });

src/core/render/compiler/link.js

+19-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
11
import { getAndRemoveConfig } from '../utils';
22
import { isAbsolutePath } from '../../router/util';
33

4-
export const linkCompiler = ({ renderer, router, linkTarget, compilerClass }) =>
4+
export const linkCompiler = ({
5+
renderer,
6+
router,
7+
linkTarget,
8+
linkRel,
9+
compilerClass,
10+
}) =>
511
(renderer.link = (href, title = '', text) => {
612
let attrs = [];
713
const { str, config } = getAndRemoveConfig(title);
8-
14+
linkTarget = config.target || linkTarget;
15+
linkRel =
16+
linkTarget === '_blank'
17+
? compilerClass.config.externalLinkRel || 'noopener'
18+
: '';
919
title = str;
1020

1121
if (
@@ -24,10 +34,13 @@ export const linkCompiler = ({ renderer, router, linkTarget, compilerClass }) =>
2434
document.URL.replace(/\/(?!.*\/).*/, '/').replace('#/./', '') + href;
2535
}
2636
attrs.push(href.indexOf('mailto:') === 0 ? '' : `target="${linkTarget}"`);
27-
}
28-
29-
if (config.target) {
30-
attrs.push(`target="${config.target}"`);
37+
attrs.push(
38+
href.indexOf('mailto:') === 0
39+
? ''
40+
: linkRel !== ''
41+
? ` rel="${linkRel}"`
42+
: ''
43+
);
3144
}
3245

3346
// special case to check crossorigin urls

src/core/render/embed.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import stripIndent from 'strip-indent';
12
import { get } from '../fetch/ajax';
23
import { merge } from '../util/core';
3-
import stripIndent from 'strip-indent';
44

55
const cached = {};
66

src/core/render/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/* eslint-disable no-unused-vars */
2+
import tinydate from 'tinydate';
23
import * as dom from '../util/dom';
34
import cssVars from '../util/polyfill/css-vars';
45
import { callHook } from '../init/lifecycle';
@@ -10,7 +11,6 @@ import { scrollActiveSidebar } from '../event/scroll';
1011
import { Compiler } from './compiler';
1112
import * as tpl from './tpl';
1213
import { prerenderEmbed } from './embed';
13-
import tinydate from 'tinydate';
1414

1515
function executeScript() {
1616
const script = dom

test/unit/base.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
require = require('esm')(
33
module /* , options */
44
); /* eslint-disable-line no-global-assign */
5-
const { History } = require('../../src/core/router/history/base');
65
const { expect } = require('chai');
6+
const { History } = require('../../src/core/router/history/base');
77

88
class MockHistory extends History {
99
parse(path) {

0 commit comments

Comments
 (0)