Skip to content
This repository has been archived by the owner on Nov 29, 2020. It is now read-only.

Commit

Permalink
compatible for win
Browse files Browse the repository at this point in the history
  • Loading branch information
lisez committed Mar 12, 2017
1 parent 7f6e714 commit 1b982b2
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 18 deletions.
4 changes: 4 additions & 0 deletions README.md
Expand Up @@ -14,6 +14,10 @@

## 更新日誌

### v1.4

- 增加 Windows 換行顯示上相容性

### v1.31

- 優化判斷式
Expand Down
24 changes: 15 additions & 9 deletions getReJDocString.js
Expand Up @@ -3,22 +3,25 @@
* Copyright (c) 2017-Present lisez <mm4324@gmail.com>
* All rights reserved. This code is governed by a BSD-style license
* that can be found in the LICENSE file.
* version: 1.31
* version: 1.4
***********************************************/
'use strict';

/* exported getReJDocString */

/***************************************
* Re-layout ROC Judicial doc to easy reuse style.
* @params {String} input - the content of judicial doc
***************************************/
function getReJDocString(input) {

'use strict';

if (typeof input === 'undefined'){return null;}

var d = input.split('\n'),
o = '',
term,
// detect OS type
isWin = navigator.platform.toUpperCase().indexOf('WIN')>-1 ? true : false,
// breaks rule
duelBreaks = function(t){o+="\n"+t+"\n";},
topBreak = function(t){o+="\n"+t;},
Expand Down Expand Up @@ -47,7 +50,8 @@ function getReJDocString(input) {
regexParagraphMarks = /[,。、]+/,
regexFootMarks = /[。:!?]$/,
regexClosureMarks = /[\n\r]+([〉》」』】〕〗〙〛,,)\]])/gim,
regexBreakMarks = /^[\n\r]+/gim;
regexBreakMarks = /^[\n\r]+/gim,
regexLineBreak = /\n|\r/gm;

for (var i=0; i<d.length; i++){
// plain text table: break
Expand All @@ -66,7 +70,7 @@ function getReJDocString(input) {
// special columns: break
if( regexFormalDate.test(term) ||
regexTopColumns.test(term) ||
regexLawArticle.test(term)
regexLawArticle.test(term)
){duelBreaks(term);continue;}

// special columns: break
Expand All @@ -79,10 +83,10 @@ function getReJDocString(input) {

// paragraph mark: break
if(regexTier1.test(term) ||
regexTier2.test(term) ||
regexTier3.test(term) ||
regexTier4.test(term) ||
regexTier5.test(term)){topBreak(term);continue;}
regexTier2.test(term) ||
regexTier3.test(term) ||
regexTier4.test(term) ||
regexTier5.test(term)){topBreak(term);continue;}

// if a sentense has common punctuation marks but not in the foot: combine
if(regexAllMarks.test(term) && !regexFootMarks.test(term)){o+=term;continue;}
Expand All @@ -96,6 +100,8 @@ function getReJDocString(input) {
o = o.replace(regexClosureMarks, "$1");
// surplus line breaks: delete
o = o.replace(regexBreakMarks, '');
// compatible for Windows
if(isWin) o = o.replace(regexLineBreak, "\n\r");

return o;
}
24 changes: 15 additions & 9 deletions getReJDocString.uni.js
Expand Up @@ -3,22 +3,25 @@
* Copyright (c) 2017-Present lisez <mm4324@gmail.com>
* All rights reserved. This code is governed by a BSD-style license
* that can be found in the LICENSE file.
* version: 1.31
* version: 1.4
***********************************************/
'use strict';

/* exported getReJDocString */

/***************************************
* Re-layout ROC Judicial doc to easy reuse style.
* @params {String} input - the content of judicial doc
***************************************/
function getReJDocString(input) {

'use strict';

if (typeof input === 'undefined'){return null;}

var d = input.split('\n'),
o = '',
term,
// detect OS type
isWin = navigator.platform.toUpperCase().indexOf('WIN')>-1 ? true : false,
// breaks rule
duelBreaks = function(t){o+="\n"+t+"\n";},
topBreak = function(t){o+="\n"+t;},
Expand Down Expand Up @@ -47,7 +50,8 @@ function getReJDocString(input) {
regexParagraphMarks = /[\uff0c\u3002\u3001]+/,
regexFootMarks = /[\u3002\uff1a\uff01\uff1f]$/,
regexClosureMarks = /[\n\r]+([\u3009\u300b\u300d\u300f\u3011\u3015\u3017\u3019\u301b\uff0c,)\]])/gim,
regexBreakMarks = /^[\n\r]+/gim;
regexBreakMarks = /^[\n\r]+/gim,
regexLineBreak = /\n|\r/gm;

for (var i=0; i<d.length; i++){
// plain text table: break
Expand All @@ -66,7 +70,7 @@ function getReJDocString(input) {
// special columns: break
if( regexFormalDate.test(term) ||
regexTopColumns.test(term) ||
regexLawArticle.test(term)
regexLawArticle.test(term)
){duelBreaks(term);continue;}

// special columns: break
Expand All @@ -79,10 +83,10 @@ function getReJDocString(input) {

// paragraph mark: break
if(regexTier1.test(term) ||
regexTier2.test(term) ||
regexTier3.test(term) ||
regexTier4.test(term) ||
regexTier5.test(term)){topBreak(term);continue;}
regexTier2.test(term) ||
regexTier3.test(term) ||
regexTier4.test(term) ||
regexTier5.test(term)){topBreak(term);continue;}

// if a sentense has common punctuation marks but not in the foot: combine
if(regexAllMarks.test(term) && !regexFootMarks.test(term)){o+=term;continue;}
Expand All @@ -96,6 +100,8 @@ function getReJDocString(input) {
o = o.replace(regexClosureMarks, "$1");
// surplus line breaks: delete
o = o.replace(regexBreakMarks, '');
// compatible for Windows
if(isWin) o = o.replace(regexLineBreak, "\n\r");

return o;
}

0 comments on commit 1b982b2

Please sign in to comment.