|
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: '); |
7 | 24 | } |
8 | | - return html; |
| 25 | + |
| 26 | + return markdown; |
9 | 27 | }); |
10 | | -}; |
| 28 | +} |
11 | 29 |
|
12 | | -$docsify = $docsify || {}; |
13 | | -$docsify.plugins = [].concat(footnotes, $docsify.plugins || []); |
| 30 | +window.$docsify = window.$docsify || {}; |
| 31 | +$docsify.plugins = [...($docsify.plugins || []), footnotes]; |
0 commit comments