diff --git a/build/base64js.min.js b/build/base64js.min.js new file mode 100644 index 0000000..0c621d3 --- /dev/null +++ b/build/base64js.min.js @@ -0,0 +1 @@ +(function(r){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=r()}else if(typeof define==="function"&&define.amd){define([],r)}else{var e;if(typeof window!=="undefined"){e=window}else if(typeof global!=="undefined"){e=global}else if(typeof self!=="undefined"){e=self}else{e=this}e.base64js=r()}})(function(){var r,e,n;return function(){function r(e,n,t){function o(f,i){if(!n[f]){if(!e[f]){var u="function"==typeof require&&require;if(!i&&u)return u(f,!0);if(a)return a(f,!0);var v=new Error("Cannot find module '"+f+"'");throw v.code="MODULE_NOT_FOUND",v}var d=n[f]={exports:{}};e[f][0].call(d.exports,function(r){var n=e[f][1][r];return o(n||r)},d,d.exports,r,e,n,t)}return n[f].exports}for(var a="function"==typeof require&&require,f=0;f0){throw new Error("Invalid string. Length must be a multiple of 4")}var n=r.indexOf("=");if(n===-1)n=e;var t=n===e?0:4-n%4;return[n,t]}function d(r){var e=v(r);var n=e[0];var t=e[1];return(n+t)*3/4-t}function c(r,e,n){return(e+n)*3/4-n}function h(r){var e;var n=v(r);var t=n[0];var f=n[1];var i=new a(c(r,t,f));var u=0;var d=f>0?t-4:t;for(var h=0;h>16&255;i[u++]=e>>8&255;i[u++]=e&255}if(f===2){e=o[r.charCodeAt(h)]<<2|o[r.charCodeAt(h+1)]>>4;i[u++]=e&255}if(f===1){e=o[r.charCodeAt(h)]<<10|o[r.charCodeAt(h+1)]<<4|o[r.charCodeAt(h+2)]>>2;i[u++]=e>>8&255;i[u++]=e&255}return i}function s(r){return t[r>>18&63]+t[r>>12&63]+t[r>>6&63]+t[r&63]}function l(r,e,n){var t;var o=[];for(var a=e;au?u:i+f))}if(o===1){e=r[n-1];a.push(t[e>>2]+t[e<<4&63]+"==")}else if(o===2){e=(r[n-2]<<8)+r[n-1];a.push(t[e>>10]+t[e>>4&63]+t[e<<2&63]+"=")}return a.join("")}},{}]},{},[])("/")}); diff --git a/build/page-catalogue.js b/build/page-catalogue.js index 43c77a1..a938613 100644 --- a/build/page-catalogue.js +++ b/build/page-catalogue.js @@ -2,6 +2,13 @@ * @desc amWiki 工作端·提取H2-H3为页内目录模块 * @author Tevin */ + +const base64js = require('./base64js.min'); + +function Base64Encode(str, encoding = 'utf-8') { + var bytes = new (TextEncoder || TextEncoderLite)(encoding).encode(str); + return base64js.fromByteArray(bytes); +} module.exports = { //创建 @@ -56,7 +63,7 @@ module.exports = { text = lines[i].split('## ')[1]; if (text != undefined) { lineStr = trimStr(text); - contents += '1. [' + lineStr + '](#' + lineStr.replace(/"/g, '') + ' "' + lineStr + '")\n'; + contents += '1. [' + lineStr + '](#' + Base64Encode(lineStr.replace(/"/g, '')) + ' "' + lineStr + '")\n'; } else { contents += '1.  \n'; } @@ -65,7 +72,7 @@ module.exports = { text = lines[i].split('### ')[1]; if (text != undefined) { lineStr = trimStr(text); - contents += '\t1. [' + lineStr + '](#' + lineStr.replace(/"/g, '') + ' "' + lineStr + '")\n'; + contents += '\t1. [' + lineStr + '](#' + Base64Encode(lineStr.replace(/"/g, '')) + ' "' + lineStr + '")\n'; } else { contents += '\t1.  \n'; } diff --git a/files/amWiki.docs.js b/files/amWiki.docs.js index 7bc4b0f..891b3c4 100644 --- a/files/amWiki.docs.js +++ b/files/amWiki.docs.js @@ -77,6 +77,11 @@ .replace(/\[/g, '[') //转义左中括号 .replace(/\]/g, ']'); //转义右中括号 }; + + function Base64Encode(str, encoding = 'utf-8') { + var bytes = new (TextEncoder || TextEncoderLite)(encoding).encode(str); + return base64js.fromByteArray(bytes); + } //设置文档h1、h2、h3描记 Docs.prototype._setTitlesAnchor = function () { @@ -94,14 +99,15 @@ var $this = $(element); var text1 = that._tramsformLinkText($this.text()); var text2 = text1.replace(/"/g, ''); //删除双引号 + var text3 = Base64Encode(text2); //提取目录 if ($this.is('h2')) { - contentsMd += '1. [' + text1 + '](#' + text2 + ' "' + text2 + '")\n'; + contentsMd += '1. [' + text1 + '](#' + text3 + ' "' + text2 + '")\n'; } else if ($this.is('h3')) { - contentsMd += '\t1. [' + text1 + '](#' + text2 + ' "' + text2 + '")\n'; + contentsMd += '\t1. [' + text1 + '](#' + text3 + ' "' + text2 + '")\n'; } //设置描记 - $this.prepend(anchorHtml.replace(/\{title\}/g, text2)); + $this.prepend(anchorHtml.replace(/\{title\}/g, text3)); //首次打开页面滚动位置修正 if (hash == $this.text().replace(/"/g, '')) { if (that.data.pageWidth <= 720) { diff --git a/files/amWiki.tpl b/files/amWiki.tpl index cf80838..f37422a 100644 --- a/files/amWiki.tpl +++ b/files/amWiki.tpl @@ -135,6 +135,7 @@