Skip to content

Commit c8013ce

Browse files
authored
Merge branch 'develop' into snyk-fix-868c33890c75695951e54378ffde6e05
2 parents 842fffc + 79a6619 commit c8013ce

File tree

9 files changed

+129
-28
lines changed

9 files changed

+129
-28
lines changed

docs/deploy.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ Similar to [GitBook](https://www.gitbook.com), you can deploy files to GitHub Pa
77
There are three places to populate your docs for your GitHub repository:
88

99
- `docs/` folder
10-
- master branch
10+
- main branch
1111
- gh-pages branch
1212

13-
It is recommended that you save your files to the `./docs` subfolder of the `master` branch of your repository. Then select `master branch /docs folder` as your GitHub Pages source in your repository's settings page.
13+
It is recommended that you save your files to the `./docs` subfolder of the `main` branch of your repository. Then select `main branch /docs folder` as your GitHub Pages source in your repository's settings page.
1414

1515
![GitHub Pages](_images/deploy-github-pages.png)
1616

17-
!> You can also save files in the root directory and select `master branch`.
17+
!> You can also save files in the root directory and select `main branch`.
1818
You'll need to place a `.nojekyll` file in the deploy location (such as `/docs` or the gh-pages branch)
1919

2020
## GitLab Pages

docs/write-a-plugin.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,16 @@ window.$docsify = {
2222
Alternatively, a plugin can be stored in a separate file and "installed" using a standard `<script>` tag:
2323

2424
```js
25+
// docsify-plugin-myplugin.js
26+
2527
(function () {
2628
var myPlugin = function (hook, vm) {
2729
// ...
2830
};
2931

3032
// Add plugin to docsify's plugin array
3133
$docsify = $docsify || {};
32-
$docsify.plugins = [].concat(myPlugin, $docsify.plugins || []);
34+
$docsify.plugins = [].concat($docsify.plugins || [], myPlugin);
3335
})();
3436
```
3537

package-lock.json

+16-10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/core/render/emojify.js

+4
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ export function emojify(text, useNativeEmoji) {
3535
)
3636
// Mark colons in comments
3737
.replace(/<!--[\s\S]+?-->/g, m => m.replace(/:/g, '__colon__'))
38+
// Mark colons in URIs
39+
.replace(/([a-z]{2,}:)?\/\/[^\s'">)]+/gi, m =>
40+
m.replace(/:/g, '__colon__')
41+
)
3842
// Replace emoji shorthand codes
3943
.replace(/:([a-z0-9_\-+]+?):/g, (m, $1) =>
4044
replaceEmojiShorthand(m, $1, useNativeEmoji)

src/core/util/str.js

+9
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,12 @@ export function startsWith(str, prefix) {
55
export function endsWith(str, suffix) {
66
return str.indexOf(suffix, str.length - suffix.length) !== -1;
77
}
8+
9+
export function removeDocsifyIgnoreTag(str) {
10+
return str
11+
.replace(/<!-- {docsify-ignore} -->/, '')
12+
.replace(/{docsify-ignore}/, '')
13+
.replace(/<!-- {docsify-ignore-all} -->/, '')
14+
.replace(/{docsify-ignore-all}/, '')
15+
.trim();
16+
}

src/plugins/search/search.js

+13-14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/* eslint-disable no-unused-vars */
22
import { getAndRemoveConfig } from '../../core/render/utils';
3+
import { removeDocsifyIgnoreTag } from '../../core/util/str';
34

45
let INDEXS = {};
56

@@ -89,19 +90,16 @@ export function genIndex(path, content = '', router, depth) {
8990
if (token.type === 'heading' && token.depth <= depth) {
9091
const { str, config } = getAndRemoveConfig(token.text);
9192

93+
const text = removeDocsifyIgnoreTag(token.text);
94+
9295
if (config.id) {
9396
slug = router.toURL(path, { id: slugify(config.id) });
9497
} else {
95-
slug = router.toURL(path, { id: slugify(escapeHtml(token.text)) });
98+
slug = router.toURL(path, { id: slugify(escapeHtml(text)) });
9699
}
97100

98101
if (str) {
99-
title = str
100-
.replace(/<!-- {docsify-ignore} -->/, '')
101-
.replace(/{docsify-ignore}/, '')
102-
.replace(/<!-- {docsify-ignore-all} -->/, '')
103-
.replace(/{docsify-ignore-all}/, '')
104-
.trim();
102+
title = removeDocsifyIgnoreTag(str);
105103
}
106104

107105
index[slug] = { slug, title: title, body: '' };
@@ -213,14 +211,15 @@ export function search(query) {
213211
}
214212

215213
const matchContent =
214+
handlePostContent &&
216215
'...' +
217-
handlePostContent
218-
.substring(start, end)
219-
.replace(
220-
regEx,
221-
word => `<em class="search-keyword">${word}</em>`
222-
) +
223-
'...';
216+
handlePostContent
217+
.substring(start, end)
218+
.replace(
219+
regEx,
220+
word => `<em class="search-keyword">${word}</em>`
221+
) +
222+
'...';
224223

225224
resultStr += matchContent;
226225
}

test/e2e/search.test.js

+20
Original file line numberDiff line numberDiff line change
@@ -176,4 +176,24 @@ test.describe('Search Plugin Tests', () => {
176176
await searchFieldElm.fill('hello');
177177
await expect(resultsHeadingElm).toHaveText('Changelog Title');
178178
});
179+
test('search when there is no body', async ({ page }) => {
180+
const docsifyInitConfig = {
181+
markdown: {
182+
homepage: `
183+
# EmptyContent
184+
---
185+
---
186+
`,
187+
},
188+
scriptURLs: ['/lib/plugins/search.min.js'],
189+
};
190+
191+
const searchFieldElm = page.locator('input[type=search]');
192+
const resultsHeadingElm = page.locator('.results-panel h2');
193+
194+
await docsifyInit(docsifyInitConfig);
195+
196+
await searchFieldElm.fill('empty');
197+
await expect(resultsHeadingElm).toHaveText('EmptyContent');
198+
});
179199
});

test/integration/__snapshots__/emoji.test.js.snap

+8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
exports[`Emoji Ignores all emoji shorthand codes (noEmoji:true) 1`] = `"<p>:smile:</p><p>:smile::smile:</p><p>:smile: :smile:</p><p>:smile::smile::smile:</p><p>:smile: :smile: :smile:</p><p>text:smile:</p><p>:smile:text</p><p>text:smile:text</p>"`;
44

5+
exports[`Emoji Ignores emoji shorthand codes in URIs 1`] = `"<p>Url <a href=\\"https://docsify.js.org/:foo:/\\" target=\\"_blank\\" rel=\\"noopener\\">https://docsify.js.org/:foo:/</a> <a href=\\"http://docsify.js.org/:100:/\\" target=\\"_blank\\" rel=\\"noopener\\">http://docsify.js.org/:100:/</a> <a href=\\"ftp://docsify.js.org/:smile:/\\" target=\\"_blank\\" rel=\\"noopener\\">ftp://docsify.js.org/:smile:/</a></p>"`;
6+
7+
exports[`Emoji Ignores emoji shorthand codes in URIs while handling anchor content 1`] = `"<p>Achor tags <a href=\\"http://docsify.js.org/:100:/\\" target=\\"_blank\\" rel=\\"noopener\\"><img src=\\"https://github.githubassets.com/images/icons/emoji/unicode/1f4af.png?v8.png\\" alt=\\"100\\" class=\\"emoji\\" loading=\\"lazy\\"></a></p>"`;
8+
59
exports[`Emoji Ignores emoji shorthand codes in code, pre, script, and template tags 1`] = `
610
"<pre>:100:</pre>
711
@@ -16,6 +20,10 @@ exports[`Emoji Ignores emoji shorthand codes in code, pre, script, and template
1620
1721
exports[`Emoji Ignores emoji shorthand codes in comments 1`] = `"<p>Text <!-- :foo: :100: --></p>"`;
1822
23+
exports[`Emoji Ignores emoji shorthand codes in html attributes 1`] = `"<p><a href=\\"http://domain.com/:smile:/\\"> <img src=\\"http://domain.com/:smile:/file.png\\"> <script src=\\"http://domain.com/:smile:/file.js\\"></script></a></p>"`;
24+
25+
exports[`Emoji Ignores emoji shorthand codes in style url() values 1`] = `"<style>@import url(http://domain.com/:smile/file.css);</style>"`;
26+
1927
exports[`Emoji Ignores unmatched emoji shorthand codes 1`] = `"<p>hh:mm</p><p>hh:mm:ss</p><p>Namespace::SubNameSpace</p><p>Namespace::SubNameSpace::Class</p><p>2014-12-29T16:11:20+00:00</p>"`;
2028
2129
exports[`Emoji Renders GitHub emoji images (nativeEmoji:false) 1`] = `"<p><img src=\\"https://github.githubassets.com/images/icons/emoji/unicode/1f604.png?v8.png\\" alt=\\"smile\\" class=\\"emoji\\" loading=\\"lazy\\"></p><p><img src=\\"https://github.githubassets.com/images/icons/emoji/unicode/1f604.png?v8.png\\" alt=\\"smile\\" class=\\"emoji\\" loading=\\"lazy\\"><img src=\\"https://github.githubassets.com/images/icons/emoji/unicode/1f604.png?v8.png\\" alt=\\"smile\\" class=\\"emoji\\" loading=\\"lazy\\"></p><p><img src=\\"https://github.githubassets.com/images/icons/emoji/unicode/1f604.png?v8.png\\" alt=\\"smile\\" class=\\"emoji\\" loading=\\"lazy\\"> <img src=\\"https://github.githubassets.com/images/icons/emoji/unicode/1f604.png?v8.png\\" alt=\\"smile\\" class=\\"emoji\\" loading=\\"lazy\\"></p><p><img src=\\"https://github.githubassets.com/images/icons/emoji/unicode/1f604.png?v8.png\\" alt=\\"smile\\" class=\\"emoji\\" loading=\\"lazy\\"><img src=\\"https://github.githubassets.com/images/icons/emoji/unicode/1f604.png?v8.png\\" alt=\\"smile\\" class=\\"emoji\\" loading=\\"lazy\\"><img src=\\"https://github.githubassets.com/images/icons/emoji/unicode/1f604.png?v8.png\\" alt=\\"smile\\" class=\\"emoji\\" loading=\\"lazy\\"></p><p><img src=\\"https://github.githubassets.com/images/icons/emoji/unicode/1f604.png?v8.png\\" alt=\\"smile\\" class=\\"emoji\\" loading=\\"lazy\\"> <img src=\\"https://github.githubassets.com/images/icons/emoji/unicode/1f604.png?v8.png\\" alt=\\"smile\\" class=\\"emoji\\" loading=\\"lazy\\"> <img src=\\"https://github.githubassets.com/images/icons/emoji/unicode/1f604.png?v8.png\\" alt=\\"smile\\" class=\\"emoji\\" loading=\\"lazy\\"></p><p>text<img src=\\"https://github.githubassets.com/images/icons/emoji/unicode/1f604.png?v8.png\\" alt=\\"smile\\" class=\\"emoji\\" loading=\\"lazy\\"></p><p><img src=\\"https://github.githubassets.com/images/icons/emoji/unicode/1f604.png?v8.png\\" alt=\\"smile\\" class=\\"emoji\\" loading=\\"lazy\\">text</p><p>text<img src=\\"https://github.githubassets.com/images/icons/emoji/unicode/1f604.png?v8.png\\" alt=\\"smile\\" class=\\"emoji\\" loading=\\"lazy\\">text</p>"`;

test/integration/emoji.test.js

+53
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,59 @@ describe('Emoji', function () {
107107
expect(mainElm.innerHTML).toMatchSnapshot();
108108
});
109109

110+
test('Ignores emoji shorthand codes in URIs', async () => {
111+
await docsifyInit({
112+
markdown: {
113+
homepage:
114+
'Url https://docsify.js.org/:foo:/ http://docsify.js.org/:100:/ ftp://docsify.js.org/:smile:/',
115+
},
116+
// _logHTML: true,
117+
});
118+
119+
const mainElm = document.querySelector('#main');
120+
121+
expect(mainElm.innerHTML).toMatchSnapshot();
122+
});
123+
124+
test('Ignores emoji shorthand codes in URIs while handling anchor content', async () => {
125+
await docsifyInit({
126+
markdown: {
127+
homepage: 'Achor tags [:100:](http://docsify.js.org/:100:/)',
128+
},
129+
// _logHTML: true,
130+
});
131+
132+
const mainElm = document.querySelector('#main');
133+
134+
expect(mainElm.innerHTML).toMatchSnapshot();
135+
});
136+
137+
test('Ignores emoji shorthand codes in html attributes', async () => {
138+
await docsifyInit({
139+
markdown: {
140+
homepage: `<a href="http://domain.com/:smile:/"> <img src='http://domain.com/:smile:/file.png'> <script src=http://domain.com/:smile:/file.js></script>`,
141+
},
142+
// _logHTML: true,
143+
});
144+
145+
const mainElm = document.querySelector('#main');
146+
147+
expect(mainElm.innerHTML).toMatchSnapshot();
148+
});
149+
150+
test('Ignores emoji shorthand codes in style url() values', async () => {
151+
await docsifyInit({
152+
markdown: {
153+
homepage: `<style>@import url(http://domain.com/:smile/file.css);</style>`,
154+
},
155+
// _logHTML: true,
156+
});
157+
158+
const mainElm = document.querySelector('#main');
159+
160+
expect(mainElm.innerHTML).toMatchSnapshot();
161+
});
162+
110163
test('Ignores emoji shorthand codes in code, pre, script, and template tags', async () => {
111164
await docsifyInit({
112165
markdown: {

0 commit comments

Comments
 (0)