diff --git a/package-lock.json b/package-lock.json index 16ce095f9..f9465888c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3606,12 +3606,6 @@ "integrity": "sha512-a+EPoD+uZiNfh+5fxw2nO9QwFa6nJe2Or35fGY6Ipw1R3R4AGz1d1TEZrCegvw2YTmZ0jXirGYlzxxpYSHwpEg==", "dev": true }, - "css.escape": { - "version": "1.5.1", - "resolved": "https://registry.npmjs.org/css.escape/-/css.escape-1.5.1.tgz", - "integrity": "sha1-QuJ9T6BK4y+TGktNQZH6nN3ul8s=", - "dev": true - }, "cssesc": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/cssesc/-/cssesc-2.0.0.tgz", diff --git a/package.json b/package.json index 55a765ece..365598520 100644 --- a/package.json +++ b/package.json @@ -76,7 +76,6 @@ "conventional-changelog-cli": "^2.0.25", "copy-dir": "^1.2.0", "cross-env": "^6.0.3", - "css.escape": "^1.5.1", "cssnano": "^4.1.10", "cypress": "^3.8.1", "cypress-image-snapshot": "^3.1.1", diff --git a/packages/docsify-server-renderer/index.js b/packages/docsify-server-renderer/index.js index 8f70f78d7..0d87dffdd 100644 --- a/packages/docsify-server-renderer/index.js +++ b/packages/docsify-server-renderer/index.js @@ -1,13 +1,13 @@ import { readFileSync } from 'fs'; import { resolve, basename } from 'path'; import resolvePathname from 'resolve-pathname'; -import debug from 'debug'; -import fetch from 'node-fetch'; import { AbstractHistory } from '../../src/core/router/history/abstract'; import { Compiler } from '../../src/core/render/compiler'; import { isAbsolutePath } from '../../src/core/router/util'; import * as tpl from '../../src/core/render/tpl'; import { prerenderEmbed } from '../../src/core/render/embed'; +import fetch from 'node-fetch'; +import debug from 'debug'; function cwd(...args) { return resolve(process.cwd(), ...args); diff --git a/src/core/event/scroll.js b/src/core/event/scroll.js index 7458ec0a6..ef78443ba 100644 --- a/src/core/event/scroll.js +++ b/src/core/event/scroll.js @@ -1,7 +1,7 @@ -import Tweezer from 'tweezer.js'; import { isMobile } from '../util/env'; import * as dom from '../util/dom'; import config from '../config'; +import Tweezer from 'tweezer.js'; const nav = {}; let hoverOver = false; diff --git a/src/core/global-api.js b/src/core/global-api.js index fd5269ae1..5529bdaf3 100644 --- a/src/core/global-api.js +++ b/src/core/global-api.js @@ -1,10 +1,10 @@ -import marked from 'marked'; -import prism from 'prismjs'; import * as util from './util'; import * as dom from './util/dom'; import { Compiler } from './render/compiler'; import { slugify } from './render/slugify'; import { get } from './fetch/ajax'; +import prism from 'prismjs'; +import marked from 'marked'; export default function() { window.Docsify = { diff --git a/src/core/render/compiler.js b/src/core/render/compiler.js index 4916aae5e..c4c026205 100644 --- a/src/core/render/compiler.js +++ b/src/core/render/compiler.js @@ -1,40 +1,20 @@ -import marked from 'marked'; import { isAbsolutePath, getPath, getParentPath } from '../router/util'; import { isFn, merge, cached, isPrimitive } from '../util/core'; import { tree as treeTpl } from './tpl'; import { genTree } from './gen-tree'; import { slugify } from './slugify'; import { emojify } from './emojify'; +import { getAndRemoveConfig } from './utils'; import { imageCompiler } from './compiler/image'; import { highlightCodeCompiler } from './compiler/code'; import { paragraphCompiler } from './compiler/paragraph'; import { taskListCompiler } from './compiler/taskList'; import { taskListItemCompiler } from './compiler/taskListItem'; import { linkCompiler } from './compiler/link'; +import marked from 'marked'; const cachedLinks = {}; -export function getAndRemoveConfig(str = '') { - const config = {}; - - if (str) { - str = str - .replace(/^'/, '') - .replace(/'$/, '') - .replace(/(?:^|\s):([\w-]+:?)=?([\w-]+)?/g, (m, key, value) => { - if (key.indexOf(':') === -1) { - config[key] = (value && value.replace(/"/g, '')) || true; - return ''; - } - - return m; - }) - .trim(); - } - - return { str, config }; -} - const compileMedia = { markdown(url) { return { diff --git a/src/core/render/compiler/headline.js b/src/core/render/compiler/headline.js index 10cb4ac84..3f5c22039 100644 --- a/src/core/render/compiler/headline.js +++ b/src/core/render/compiler/headline.js @@ -1,4 +1,4 @@ -import { getAndRemoveConfig } from '../compiler'; +import { getAndRemoveConfig } from '../utils'; import { slugify } from './slugify'; export const headingCompiler = ({ renderer, router, _self }) => diff --git a/src/core/render/compiler/link.js b/src/core/render/compiler/link.js index 2c4b0cd79..faf2e4f7c 100644 --- a/src/core/render/compiler/link.js +++ b/src/core/render/compiler/link.js @@ -1,4 +1,4 @@ -import { getAndRemoveConfig } from '../compiler'; +import { getAndRemoveConfig } from '../utils'; import { isAbsolutePath } from '../../router/util'; export const linkCompiler = ({ renderer, router, linkTarget, compilerClass }) => diff --git a/src/core/render/embed.js b/src/core/render/embed.js index b64d11a8b..083fb7f97 100644 --- a/src/core/render/embed.js +++ b/src/core/render/embed.js @@ -1,6 +1,6 @@ -import stripIndent from 'strip-indent'; import { get } from '../fetch/ajax'; import { merge } from '../util/core'; +import stripIndent from 'strip-indent'; const cached = {}; diff --git a/src/core/render/index.js b/src/core/render/index.js index 37cd6af34..9b50dc708 100644 --- a/src/core/render/index.js +++ b/src/core/render/index.js @@ -1,5 +1,4 @@ /* eslint-disable no-unused-vars */ -import tinydate from 'tinydate'; import * as dom from '../util/dom'; import cssVars from '../util/polyfill/css-vars'; import { callHook } from '../init/lifecycle'; @@ -11,6 +10,7 @@ import { scrollActiveSidebar } from '../event/scroll'; import { Compiler } from './compiler'; import * as tpl from './tpl'; import { prerenderEmbed } from './embed'; +import tinydate from 'tinydate'; function executeScript() { const script = dom diff --git a/src/core/render/utils.js b/src/core/render/utils.js new file mode 100644 index 000000000..2b7f0e052 --- /dev/null +++ b/src/core/render/utils.js @@ -0,0 +1,20 @@ +export function getAndRemoveConfig(str = '') { + const config = {}; + + if (str) { + str = str + .replace(/^'/, '') + .replace(/'$/, '') + .replace(/(?:^|\s):([\w-]+:?)=?([\w-]+)?/g, (m, key, value) => { + if (key.indexOf(':') === -1) { + config[key] = (value && value.replace(/"/g, '')) || true; + return ''; + } + + return m; + }) + .trim(); + } + + return { str, config }; +} diff --git a/src/core/router/index.js b/src/core/router/index.js index 1cb2f67d8..923168898 100644 --- a/src/core/router/index.js +++ b/src/core/router/index.js @@ -1,8 +1,8 @@ import { supportsPushState } from '../util/env'; import * as dom from '../util/dom'; +import { noop } from '../util/core'; import { HashHistory } from './history/hash'; import { HTML5History } from './history/html5'; -import { noop } from '../util/core'; export function routerMixin(proto) { proto.route = {}; diff --git a/test/unit/base.test.js b/test/unit/base.test.js index ed050424a..736b70ac6 100644 --- a/test/unit/base.test.js +++ b/test/unit/base.test.js @@ -2,8 +2,8 @@ require = require('esm')( module /* , options */ ); /* eslint-disable-line no-global-assign */ -const { expect } = require('chai'); const { History } = require('../../src/core/router/history/base'); +const { expect } = require('chai'); class MockHistory extends History { parse(path) { diff --git a/test/unit/render.test.js b/test/unit/render.test.js index 60ed5e0a0..c65d4c958 100644 --- a/test/unit/render.test.js +++ b/test/unit/render.test.js @@ -1,5 +1,5 @@ -const { expect } = require('chai'); const { init, expectSameDom } = require('../_helper'); +const { expect } = require('chai'); describe('render', function() { it('important content (tips)', async function() { diff --git a/test/unit/util.test.js b/test/unit/util.test.js index 9dadf28a3..e4e8a0e3b 100644 --- a/test/unit/util.test.js +++ b/test/unit/util.test.js @@ -2,8 +2,8 @@ require = require('esm')( module /* , options */ ); /* eslint-disable-line no-global-assign */ -const { expect } = require('chai'); const { resolvePath } = require('../../src/core/router/util'); +const { expect } = require('chai'); describe('router/util', function() { it('resolvePath', async function() {