Skip to content

Commit

Permalink
Bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
HokkaidoPerson committed Jan 28, 2019
1 parent 5dfe268 commit 7189d24
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 52 deletions.
2 changes: 1 addition & 1 deletion plugin.info.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
base wikiformatstyling
author Main development by Hir/wataame, adjustment and distribution by HokkaidoPerson
email [email protected]
date 2019-01-13
date 2019-01-28
name Wiki-Style Script
desc If there are wiki syntax of bold, italic, underlined, or monospaced text remaining (such as those in headers and link texts), this plugin will apply them. You can also change color of characters in headers and link texts. Characters of nowiki syntax won't be changed.
url http://www.dokuwiki.org/plugin:wikiformatstyling
141 changes: 90 additions & 51 deletions script.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// DokuWikiのWikiスタイル書体補完スクリプト
// Wiki-Style Script
// hGcl_Wiki_Style.js
// version 2.1
// 2019 / 01 / 11
// version 2.2
// 2019 / 01 / 26
//
// 2019 ひぃ(Hir)/ワタアメ
// Twitter : @Hir_gca
Expand Down Expand Up @@ -37,8 +37,8 @@
// The script to complement DokuWiki syntax
// Wiki-Style Script
// hGcl_Wiki_Style.js
// version 2.1
// 2019 / 01 / 11
// version 2.2
// 2019 / 01 / 26
//
// 2019 Hir/wataame
// Twitter : @Hir_gca
Expand Down Expand Up @@ -85,53 +85,71 @@ var ConvertArray = new Array(
'code' // 等幅 / Monospaced
);

function AddressArguemnt(){
var arg = new Object;
var eq = location.search.substring(1).split("&");
var key;
for(var i=0;eq[i];i++){
key = eq[i].split("=");
arg[key[0].toUpperCase()]=key[1];
}
if(arg.DO && arg.DO.toLowerCase() == "admin"){
return -1;
}
return 0;
}

function wikiStyle(){
if(AddressArguemnt() == -1){
return;
}

var bodyInnerHTML = document.body.innerHTML;
var HeaderSplit;
var result;
var k;

// textareaタグのデータを保持する / Preserve datas in <textarea>
// textareaタグのデータを保持する / Preserve datas in tags <textarea>
var TextareaBoxs = document.getElementsByTagName('textarea');
var TextareaStrs = new Array(TextareaBoxs.length);

for(k=0;k<TextareaBoxs.length;k++){
TextareaStrs[k] = TextareaBoxs[k].innerHTML;
}

// preタグのデータを保持する / Preserve datas in <pre>
// preタグのデータを保持する / Preserve datas in tags <pre>
var PreBoxs = document.getElementsByTagName('pre');
var PreStrs = new Array(PreBoxs.length);

for(k=0;k<PreBoxs.length;k++){
PreStrs[k] = PreBoxs[k].innerHTML;
}

// wss-nowiki-selectionクラスのデータを保持する / Preserve datas in the class "wss-nowiki-section"
// wss-nowiki-selectionクラスのデータを保持する / Preserve datas in class "wss-nowiki-section"
var WSSNoWikiBoxs = document.getElementsByClassName('wss-nowiki-section');
var WSSNoWikiStrs = new Array(WSSNoWikiBoxs.length);

for(k=0;k<WSSNoWikiBoxs.length;k++){
WSSNoWikiStrs[k] = WSSNoWikiBoxs[k].innerHTML;
}

// diffクラスのデータを保持する / Preserve datas in the class "diff"
// diffクラスのデータを保持する / Preserve datas in class "diff"
var DiffBoxs = document.getElementsByClassName('diff');
var DiffStrs = new Array(DiffBoxs.length);

for(k=0;k<DiffBoxs.length;k++){
DiffStrs[k] = DiffBoxs[k].innerHTML;
}

// formタグのデータを保持する / Preserve datas in <form>
// formタグのデータを保持する / Preserve datas in tags <form>
var FormBoxs = document.getElementsByTagName('form');
var FormStrs = new Array(FormBoxs.length);

for(k=0;k<FormBoxs.length;k++){
FormStrs[k] = FormBoxs[k].innerHTML;
}

// とりあえずbody全体の$[、$]、$\を<、>、'に変換する / Well, let's convert $[, $], and $\ to <, >, and ' in the whole body tag
// とりあえずbody全体の$[、$]、$\を<、>、'に変換する / Well, let's convert $[, $], and $\ in the whole body tag to <, >, and '
HeaderSplit = bodyInnerHTML.split('$\\');
bodyInnerHTML = HeaderSplit[0];
for(k=1;k<HeaderSplit.length;k++){
Expand All @@ -147,7 +165,7 @@ function wikiStyle(){
for(k=1;k<HeaderSplit.length;k++){
bodyInnerHTML += '>' + HeaderSplit[k];
}

//変換して生成された<hdcolor>、</hdcolor>を更に変換 / Then convert <hdcolor> and </hdcolor> generated by the script above
HeaderSplit = bodyInnerHTML.split('<hdcolor');
bodyInnerHTML = HeaderSplit[0];
Expand All @@ -159,62 +177,81 @@ function wikiStyle(){
for(k=1;k<HeaderSplit.length;k++){
bodyInnerHTML += '</font' + HeaderSplit[k];
}

HeaderSplit = bodyInnerHTML.split('://');
bodyInnerHTML = HeaderSplit[0];
for(k=1;k<HeaderSplit.length;k++){
bodyInnerHTML += ':\\//' + HeaderSplit[k];
}


var cnvCnt,cnvRes,hs,hss,x;

bodyInnerHTML = bodyInnerHTML.replace("/\".+__.+\"/g","\0001\0001");
for(i=0;i<StyleArray.length;i++){
if(i == 2) continue;
cnvCnt = 1;

HeaderSplit = bodyInnerHTML.split('\\' + StyleArray[i]);
bodyInnerHTML = HeaderSplit[0];
for(k=1;k<HeaderSplit.length;k++){
bodyInnerHTML += '&#x2065;&#x2065;' + HeaderSplit[k];
}

HeaderSplit = bodyInnerHTML.split(StyleArray[i]);
result = HeaderSplit[0];

for(k=1;k<HeaderSplit.length;k++){
result += '<' + (k%2==0?'/':'') + ConvertArray[i] + '>' + HeaderSplit[k];
if(cnvCnt%2 == 1){
hs = HeaderSplit[k].split('\n');
hss = hs[0];
if(hs.length > 1){
hss += '</' + ConvertArray[i] + '>';
for(x=1;x<hs.length;x++){
hss += '\n' + hs[x];
}
cnvRes = hss;
}else{
cnvRes = '<' + (cnvCnt%2==0?'/':'') + ConvertArray[i] + '>' + HeaderSplit[k];
}
}else{
cnvRes = '<' + (cnvCnt%2==0?'/':'') + ConvertArray[i] + '>' + HeaderSplit[k];
}
result += cnvRes;
cnvCnt++;
}
bodyInnerHTML = result;

HeaderSplit = bodyInnerHTML.split('&#x2065;&#x2065;');
bodyInnerHTML = HeaderSplit[0];
for(k=1;k<HeaderSplit.length;k++){
bodyInnerHTML += StyleArray[i] + HeaderSplit[k];
}
}

document.body.innerHTML = bodyInnerHTML;

TagsUnder();

// textareaタグのデータを戻す / Restore datas in <textarea>
// textareaタグのデータを戻す / Restore data in tags <textarea>
for(k=0;k<TextareaBoxs.length;k++){
TextareaBoxs[k].innerHTML = TextareaStrs[k];
}

// preタグのデータを戻す / Restore datas in <pre>
// preタグのデータを戻す / Restore data in tags <pre>
for(k=0;k<PreBoxs.length;k++){
PreBoxs[k].innerHTML = PreStrs[k];
}

// wss-nowiki-selectionクラスのデータを戻す / Restore datas in the class "wss-nowiki-section"
// wss-nowiki-selectionクラスのデータを戻す / Restore data in class "wss-nowiki-section"
for(k=0;k<WSSNoWikiBoxs.length;k++){
WSSNoWikiBoxs[k].innerHTML = WSSNoWikiStrs[k];
}

// diffクラスのデータを戻す / Restore datas in the class "diff"
// diffクラスのデータを戻す / Restore data in class "diff"
for(k=0;k<DiffBoxs.length;k++){
DiffBoxs[k].innerHTML = DiffStrs[k];
}

// formタグのデータを戻す / Restore datas in <form>
// formタグのデータを戻す / Restore data in tags <form>
for(k=0;k<FormBoxs.length;k++){
FormBoxs[k].innerHTML = FormStrs[k];
}
Expand All @@ -226,48 +263,50 @@ function TagsUnder(){
var i;
var j;
var k;
var h;
var HeaderSplit;
var result;



for(i=1;i<=6;i++){
Headers = document.getElementsByTagName('h' + i);
for(j=0;j<Headers.length;j++){
result = Headers[j].innerHTML;

HeaderSplit = result.split(StyleArray[2]);
result = HeaderSplit[0];

for(k=1;k<HeaderSplit.length;k++){
result += '<' + (k%2==0?'/':'') + ConvertArray[2] + '>' + HeaderSplit[k];
}

Headers[j].innerHTML = result;
}
Headers = document.getElementsByClassName('level' + i);
for(j=0;j<Headers.length;j++){
result = Headers[j].innerHTML;

HeaderSplit = result.split(StyleArray[2]);
result = HeaderSplit[0];

for(k=1;k<HeaderSplit.length;k++){
result += '<' + (k%2==0?'/':'') + ConvertArray[2] + '>' + HeaderSplit[k];
}

Headers[j].innerHTML = result;
}
}
Headers = document.getElementsByTagName('p');
for(j=0;j<Headers.length;j++){
result = Headers[j].innerHTML;

HeaderSplit = result.split(StyleArray[2]);
result = HeaderSplit[0];

for(k=1;k<HeaderSplit.length;k++){
result += '<' + (k%2==0?'/':'') + ConvertArray[2] + '>' + HeaderSplit[k];
}

Headers[j].innerHTML = result;
}
}
}

0 comments on commit 7189d24

Please sign in to comment.