Skip to content

Commit f1fa585

Browse files
authored
Compatible with Docsify v5 Preview (#3)
1 parent f44f61c commit f1fa585

File tree

6 files changed

+36
-20
lines changed

6 files changed

+36
-20
lines changed

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
node_modules/
22
.idea/
3-
lib/
4-
package-lock.json
3+
dist/
4+
package-lock.json

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
build/
22
screenshots.png
33
.idea/
4+
src/

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ A plugin that supports the use of footnotes in docsify.
1111
## Usage
1212

1313
```html
14-
<script src="//cdn.jsdelivr.net/npm/@sy-records/docsify-footnotes/lib/index.min.js"></script>
14+
<script src="//cdn.jsdelivr.net/npm/@sy-records/docsify-footnotes/dist/index.min.js"></script>
1515
```
1616

1717
## Example

build/build.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,11 @@ async function build(opts) {
3939
}
4040
})
4141
.then(function (bundle) {
42-
var dest = 'lib/' + (opts.output || opts.input)
42+
var dest = 'dist/' + (opts.output || opts.input)
4343

4444
console.log(dest)
4545
return bundle.write({
46-
format: 'iife',
47-
output: opts.globalName ? {name: opts.globalName} : {},
48-
file: dest,
49-
strict: false
46+
output: {file: dest, format: 'iife', strict: false},
5047
})
5148
})
5249
}

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@sy-records/docsify-footnotes",
3-
"version": "1.0.2",
3+
"version": "2.0.0",
44
"description": "A plugin that supports the use of footnotes in docsify.",
55
"main": "src/index.js",
66
"repository": {
@@ -20,7 +20,7 @@
2020
"homepage": "https://github.com/sy-records/docsify-footnotes#readme",
2121
"devDependencies": {
2222
"cross-env": "^6.0.3",
23-
"rollup": "^1.23.1",
23+
"rollup": "^2.79.2",
2424
"rollup-plugin-async": "^1.2.0",
2525
"rollup-plugin-buble": "^0.19.8",
2626
"rollup-plugin-commonjs": "^10.1.0",

src/index.js

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,31 @@
1-
const footnotes = function(hook) {
2-
hook.beforeEach(function (html) {
3-
if (/\[\^([A-Za-z0-9\-]+)\][^:]/.test(html)) {
4-
html = html
5-
.replace(/\[\^([A-Za-z0-9\-]+)\][^:]/gm, '<sup class="footnote-symbol" id="fn-$1">[\[$1]\](#fnref-$1)</sup>')
6-
.replace(/\[\^([A-Za-z0-9\-]+)\]\: /gm, '<strong class="footnote-reference-symbol" id="fnref-$1">[\[$1\]](#fn-$1)</strong>:leftwards_arrow_with_hook: ');
1+
document.addEventListener('click', function (event) {
2+
const target = event.target.closest('.footnote-symbol, .footnote-reference-symbol');
3+
4+
if (!target || !target.hasAttribute('data-id')) return;
5+
6+
const dataId = target.getAttribute('data-id');
7+
8+
const footnotesElm = Docsify.dom.find(`.markdown-section :where(sup, strong)[id="${dataId}"]`);
9+
10+
if (footnotesElm) {
11+
footnotesElm.scrollIntoView({
12+
behavior: 'smooth',
13+
block: 'start',
14+
});
15+
}
16+
});
17+
18+
function footnotes(hook) {
19+
hook.beforeEach(function (markdown) {
20+
if (/\[\^([A-Za-z0-9\-]+)\][^:]/.test(markdown)) {
21+
markdown = markdown
22+
.replace(/\[\^([A-Za-z0-9\-]+)\][^:]/gm, '<sup class="footnote-symbol" data-id="fnref-$1" id="fn-$1">[\[$1]\](#fnref-$1)</sup>')
23+
.replace(/\[\^([A-Za-z0-9\-]+)\]\: /gm, '<strong class="footnote-reference-symbol" data-id="fn-$1" id="fnref-$1">[\[$1\]](#fn-$1)</strong>:leftwards_arrow_with_hook: ');
724
}
8-
return html;
25+
26+
return markdown;
927
});
10-
};
28+
}
1129

12-
$docsify = $docsify || {};
13-
$docsify.plugins = [].concat(footnotes, $docsify.plugins || []);
30+
window.$docsify = window.$docsify || {};
31+
$docsify.plugins = [...($docsify.plugins || []), footnotes];

0 commit comments

Comments
 (0)