From ea17dcc66cd4bf3154afa16b38d357b2285c8f5e Mon Sep 17 00:00:00 2001 From: Tom Schaible Date: Thu, 2 Apr 2020 08:27:03 -0400 Subject: [PATCH 01/36] updated the insertion of embedded tokens so it correctly handles embedded token results returning in any order fixes #970 --- src/core/render/embed.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/core/render/embed.js b/src/core/render/embed.js index 083fb7f9..8c0cf575 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 = {}; @@ -117,17 +117,27 @@ export function prerenderEmbed({ compiler, raw = '', fetch }, done) { } }); - let moveIndex = 0; + // keep track of which tokens have been embedded so far + // so that we know where to insert the embedded tokens as they + // are returned + const moves = []; walkFetchEmbed({ compile, embedTokens, fetch }, ({ embedToken, token }) => { if (token) { - const index = token.index + moveIndex; + // iterate through the array of previously inserted tokens + // to determine where the current embedded tokens should be inserted + let index = token.index; + moves.forEach(pos => { + if (index > pos.start) { + index += pos.length; + } + }); merge(links, embedToken.links); tokens = tokens .slice(0, index) .concat(embedToken, tokens.slice(index + 1)); - moveIndex += embedToken.length - 1; + moves.push({ start: index, length: embedToken.length - 1 }); } else { cached[raw] = tokens.concat(); tokens.links = cached[raw].links = links; From d32d91bebc54939585c4a371c8d5bf898f674d12 Mon Sep 17 00:00:00 2001 From: CHUXK Date: Fri, 10 Apr 2020 11:28:32 +0800 Subject: [PATCH 02/36] Update sidebar.js fix bug https://github.com/docsifyjs/docsify/issues/1110 --- src/core/event/sidebar.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/core/event/sidebar.js b/src/core/event/sidebar.js index f252f2b4..5c09fb2b 100644 --- a/src/core/event/sidebar.js +++ b/src/core/event/sidebar.js @@ -38,7 +38,8 @@ export function collapse(el) { dom.on(el, 'click', ({ target }) => { if ( target.nodeName === 'A' && - target.nextSibling && + target.nextSibling && + target.nextSibling.classList && target.nextSibling.classList.contains('app-sub-sidebar') ) { dom.toggleClass(target.parentNode, 'collapse'); From b4e7b219284ae88a1550e72ed0a198db1552f7f8 Mon Sep 17 00:00:00 2001 From: CHUXK Date: Fri, 10 Apr 2020 11:30:12 +0800 Subject: [PATCH 03/36] Update component.js fix bug https://github.com/docsifyjs/docsify/issues/1098 --- src/plugins/search/component.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/plugins/search/component.js b/src/plugins/search/component.js index 21add7ef..1ac16fa2 100644 --- a/src/plugins/search/component.js +++ b/src/plugins/search/component.js @@ -171,11 +171,11 @@ function bindEvents() { let timeId; // Prevent to Fold sidebar - Docsify.dom.on( - $search, - 'click', - e => e.target.tagName !== 'A' && e.stopPropagation() - ); +// Docsify.dom.on( +// $search, +// 'click', +// e => e.target.tagName !== 'A' && e.stopPropagation() +// ); Docsify.dom.on($input, 'input', e => { clearTimeout(timeId); timeId = setTimeout(_ => doSearch(e.target.value.trim()), 100); From 517f0d7dead27481da7eb0707217cf28ffd8b6f4 Mon Sep 17 00:00:00 2001 From: koooooo-7 <369491420@qq.com> Date: Mon, 13 Apr 2020 23:04:34 +0800 Subject: [PATCH 04/36] [fix #1115] Image resize in % doesn't work. --- src/core/render/utils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/render/utils.js b/src/core/render/utils.js index 2b7f0e05..6f2d14fa 100644 --- a/src/core/render/utils.js +++ b/src/core/render/utils.js @@ -5,7 +5,7 @@ export function getAndRemoveConfig(str = '') { str = str .replace(/^'/, '') .replace(/'$/, '') - .replace(/(?:^|\s):([\w-]+:?)=?([\w-]+)?/g, (m, key, value) => { + .replace(/(?:^|\s):([\w-]+:?)=?([\w-%]+)?/g, (m, key, value) => { if (key.indexOf(':') === -1) { config[key] = (value && value.replace(/"/g, '')) || true; return ''; From fed6a8393025c88699454d9eebaf2b66b278aea9 Mon Sep 17 00:00:00 2001 From: CHUXK Date: Wed, 15 Apr 2020 16:01:09 +0800 Subject: [PATCH 05/36] Linting Checks --- src/{core/event => core/事件}/sidebar.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename src/{core/event => core/事件}/sidebar.js (98%) diff --git a/src/core/event/sidebar.js b/src/ core/事件/sidebar.js similarity index 98% rename from src/core/event/sidebar.js rename to src/ core/事件/sidebar.js index 5c09fb2b..b15cb2af 100644 --- a/src/core/event/sidebar.js +++ b/src/ core/事件/sidebar.js @@ -38,7 +38,7 @@ export function collapse(el) { dom.on(el, 'click', ({ target }) => { if ( target.nodeName === 'A' && - target.nextSibling && + target.nextSibling && target.nextSibling.classList && target.nextSibling.classList.contains('app-sub-sidebar') ) { From 1c43abe8ff8456d7fb65f36898e210126891e993 Mon Sep 17 00:00:00 2001 From: CHUXK Date: Wed, 15 Apr 2020 16:03:40 +0800 Subject: [PATCH 06/36] Linting Checks --- src/plugins/search/component.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/plugins/search/component.js b/src/plugins/search/component.js index 1ac16fa2..a2e4ec17 100644 --- a/src/plugins/search/component.js +++ b/src/plugins/search/component.js @@ -171,11 +171,6 @@ function bindEvents() { let timeId; // Prevent to Fold sidebar -// Docsify.dom.on( -// $search, -// 'click', -// e => e.target.tagName !== 'A' && e.stopPropagation() -// ); Docsify.dom.on($input, 'input', e => { clearTimeout(timeId); timeId = setTimeout(_ => doSearch(e.target.value.trim()), 100); From dcb0aaea99efbd68175f1d1aeb5076b6dde9801e Mon Sep 17 00:00:00 2001 From: Luffy <52o@qq52o.cn> Date: Sun, 19 Apr 2020 22:12:55 +0800 Subject: [PATCH 07/36] fix: Inconsistent search and body rendering * fix * Update search.js * Update search.js * Update search.js * Update search.js * Update search.js --- src/plugins/search/search.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/plugins/search/search.js b/src/plugins/search/search.js index 29d74b79..b1f5f025 100644 --- a/src/plugins/search/search.js +++ b/src/plugins/search/search.js @@ -25,10 +25,9 @@ function escapeHtml(string) { '>': '>', '"': '"', "'": ''', - '/': '/', }; - return String(string).replace(/[&<>"'/]/g, s => entityMap[s]); + return String(string).replace(/[&<>"']/g, s => entityMap[s]); } function getAllPaths(router) { @@ -66,7 +65,7 @@ export function genIndex(path, content = '', router, depth) { tokens.forEach(token => { if (token.type === 'heading' && token.depth <= depth) { - slug = router.toURL(path, { id: slugify(token.text) }); + slug = router.toURL(path, { id: slugify(escapeHtml(token.text)) }); index[slug] = { slug, title: token.text, body: '' }; } else { if (!slug) { From b2e6123980e98c75a6a6e6cb1f366b19e9856c13 Mon Sep 17 00:00:00 2001 From: Joe Pea Date: Sun, 19 Apr 2020 08:32:07 -0700 Subject: [PATCH 08/36] Update nameLink option docs (#1125) --- docs/configuration.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/configuration.md b/docs/configuration.md index 11797c79..d402384f 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -265,7 +265,7 @@ window.$docsify = { - Type: `String` - Default: `window.location.pathname` -The name of the link. +The URL that the website `name` links to. ```js window.$docsify = { @@ -587,4 +587,4 @@ Adds a space on top when scrolling content page to reach the selected section. T window.$docsify = { topMargin: 90, // default: 0 }; -``` \ No newline at end of file +``` From 2623b94dd38424fce4a8b131fe72c42c5fe6358b Mon Sep 17 00:00:00 2001 From: Luffy <52o@qq52o.cn> Date: Mon, 27 Apr 2020 13:09:45 +0800 Subject: [PATCH 09/36] Update index.html (#1144) --- index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.html b/index.html index 59e6911b..1729635a 100644 --- a/index.html +++ b/index.html @@ -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/$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' From b108c86d3884e6b396b36f2777d12dcd64e8f7ac Mon Sep 17 00:00:00 2001 From: vagra Date: Mon, 27 Apr 2020 16:55:55 +0800 Subject: [PATCH 10/36] reset and modify. --- src/core/event/scroll.js | 8 ++++---- src/core/router/util.js | 4 ++++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/core/event/scroll.js b/src/core/event/scroll.js index ef78443b..47d64b41 100644 --- a/src/core/event/scroll.js +++ b/src/core/event/scroll.js @@ -1,5 +1,6 @@ import { isMobile } from '../util/env'; import * as dom from '../util/dom'; +import { removeParams } from '../router/util'; import config from '../config'; import Tweezer from 'tweezer.js'; @@ -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; @@ -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) { @@ -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', () => { diff --git a/src/core/router/util.js b/src/core/router/util.js index ba2eed8a..fc3e2f79 100644 --- a/src/core/router/util.js +++ b/src/core/router/util.js @@ -44,6 +44,10 @@ export const isAbsolutePath = cached(path => { return /(:|(\/{2}))/g.test(path); }); +export const removeParams = cached(path => { + return path.split(/[?#]/)[0]; +}); + export const getParentPath = cached(path => { if (/\/$/g.test(path)) { return path; From 717991c90cf709f4da91fe32610129de6529266b Mon Sep 17 00:00:00 2001 From: Herbert <30955264+HerbertHe@users.noreply.github.com> Date: Tue, 28 Apr 2020 01:07:27 +0800 Subject: [PATCH 11/36] fix: rendering cover width bug --- src/themes/basic/_coverpage.styl | 1 + 1 file changed, 1 insertion(+) diff --git a/src/themes/basic/_coverpage.styl b/src/themes/basic/_coverpage.styl index 00149322..3ad8149e 100644 --- a/src/themes/basic/_coverpage.styl +++ b/src/themes/basic/_coverpage.styl @@ -4,6 +4,7 @@ section.cover background-repeat no-repeat background-size cover height 100vh + width 100vw display none &.show From b05949a1615a0358e58cf1fd9007cc42c1af319f Mon Sep 17 00:00:00 2001 From: Sytone Date: Mon, 27 Apr 2020 12:24:24 -0700 Subject: [PATCH 12/36] Add front matter to dev page Update embeded files documentation Add example with front matter Add various comments I used to understand code Updated front matter to have installed flag Added function to parse front matter Added intercept to remove front matter for embed --- docs/_media/example-with-yaml.md | 6 ++++++ docs/embed-files.md | 14 +++++++++++++- index.html | 1 + src/core/render/compiler.js | 15 +++++++++++++++ src/core/render/embed.js | 7 +++++++ src/core/render/utils.js | 20 ++++++++++++++++++++ src/plugins/front-matter/index.js | 8 ++++++++ 7 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 docs/_media/example-with-yaml.md diff --git a/docs/_media/example-with-yaml.md b/docs/_media/example-with-yaml.md new file mode 100644 index 00000000..081bedde --- /dev/null +++ b/docs/_media/example-with-yaml.md @@ -0,0 +1,6 @@ +--- +author: John Smith +date: 2020-1-1 +--- + +> This is from the `example.md` diff --git a/docs/embed-files.md b/docs/embed-files.md index dab2efe4..d5038747 100644 --- a/docs/embed-files.md +++ b/docs/embed-files.md @@ -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 @@ -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. diff --git a/index.html b/index.html index 59e6911b..fba1a407 100644 --- a/index.html +++ b/index.html @@ -76,6 +76,7 @@ + diff --git a/src/core/render/compiler.js b/src/core/render/compiler.js index c4c02620..5cb8f9e5 100644 --- a/src/core/render/compiler.js +++ b/src/core/render/compiler.js @@ -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; diff --git a/src/core/render/embed.js b/src/core/render/embed.js index 083fb7f9..8b84c7ac 100644 --- a/src/core/render/embed.js +++ b/src/core/render/embed.js @@ -36,6 +36,13 @@ function walkFetchEmbed({ embedTokens, compile, fetch }, cb) { return x; }); + // This may contain YAML front matter and will need to be stripped. + const frontMatterInstalled = + ($docsify.frontMatter || {}).installed || false; + if (frontMatterInstalled === true) { + text = $docsify.frontMatter.parseMarkdown(text); + } + embedToken = compile.lexer(text); } else if (token.embed.type === 'code') { if (token.embed.fragment) { diff --git a/src/core/render/utils.js b/src/core/render/utils.js index 6f2d14fa..100d595c 100644 --- a/src/core/render/utils.js +++ b/src/core/render/utils.js @@ -1,3 +1,23 @@ +/** + * Converts a colon formatted string to a object with properties. + * + * This is process a provided string and look for any tokens in the format + * of `:name[=value]` and then convert it to a object and return. + * An example of this is ':include :type=code :fragment=demo' is taken and + * then converted to: + * + * ``` + * { + * include: '', + * type: 'code', + * fragment: 'demo' + * } + * ``` + * + * @param {string} str The string to parse. + * + * @return {object} The original string and parsed object, { str, config }. + */ export function getAndRemoveConfig(str = '') { const config = {}; diff --git a/src/plugins/front-matter/index.js b/src/plugins/front-matter/index.js index e91c4efc..a0aac5b6 100644 --- a/src/plugins/front-matter/index.js +++ b/src/plugins/front-matter/index.js @@ -1,6 +1,14 @@ import parser from './parser'; const install = function(hook, vm) { + // Used to remove front matter from embedded pages if installed. + vm.config.frontMatter = {}; + vm.config.frontMatter.installed = true; + vm.config.frontMatter.parseMarkdown = function(content) { + const { body } = parser(content); + return body; + }; + hook.beforeEach(content => { const { attributes, body } = parser(content); From 468ee2d58afc9850730843c54fd9c5b7cff3e0c2 Mon Sep 17 00:00:00 2001 From: Laura Kishimoto Date: Mon, 27 Apr 2020 21:47:49 +0100 Subject: [PATCH 13/36] Improve accessibility of viewport meta --- cypress/fixtures/tpl/docs.index.html | 2 +- docs/index.html | 4 ++-- docs/ssr.md | 2 +- packages/docsify-server-renderer/README.md | 2 +- server.js | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cypress/fixtures/tpl/docs.index.html b/cypress/fixtures/tpl/docs.index.html index 94d9526e..6a8b41a4 100644 --- a/cypress/fixtures/tpl/docs.index.html +++ b/cypress/fixtures/tpl/docs.index.html @@ -16,7 +16,7 @@ diff --git a/docs/index.html b/docs/index.html index 39c32b81..b99db702 100644 --- a/docs/index.html +++ b/docs/index.html @@ -9,12 +9,12 @@ - + - +