From e2ad161026cf739e2e98a150e1943f3a0b02ed4b Mon Sep 17 00:00:00 2001 From: cjr1705 Date: Thu, 26 Jul 2018 10:43:40 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=86=E6=A0=B9=E6=8D=AE=E6=A0=87=E9=A2=98?= =?UTF-8?q?=E8=BF=9B=E8=A1=8C=E5=AF=BC=E8=88=AA=E5=8F=8A=E7=94=9F=E6=88=90?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E7=9B=AE=E5=BD=95=E5=8A=9F=E8=83=BD=E4=B8=AD?= =?UTF-8?q?=E7=9A=84=E9=94=9A=E7=82=B9name=E4=BD=BF=E7=94=A8Base64?= =?UTF-8?q?=E8=BF=9B=E8=A1=8C=E7=BC=96=E7=A0=81,=E4=BB=A5=E4=BE=BF?= =?UTF-8?q?=E5=9C=A8=E6=89=93=E5=8D=B0=E6=88=90PDF=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E6=97=B6=E6=94=AF=E6=8C=81=E8=87=AA=E5=8A=A8=E7=94=9F=E6=88=90?= =?UTF-8?q?=E7=9B=AE=E5=BD=95=E7=9A=84=E9=93=BE=E6=8E=A5=E7=82=B9=E5=87=BB?= =?UTF-8?q?.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build/base64js.min.js | 1 + build/page-catalogue.js | 11 +++++++++-- files/amWiki.docs.js | 12 +++++++++--- files/amWiki.tpl | 1 + files/base64js.min.js | 1 + 5 files changed, 21 insertions(+), 5 deletions(-) create mode 100644 build/base64js.min.js create mode 100644 files/base64js.min.js 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 @@