From 6d1ccadd6d6bfdf8879a90fe70c3edb93257955d Mon Sep 17 00:00:00 2001 From: Ritsuki Goto Date: Fri, 20 May 2016 20:20:06 +0900 Subject: [PATCH 1/3] [delete] source code file --- README.md | 7 - bundle.js | 372 ------------------------------------------------ gulpfile.coffee | 19 --- src/nml.coffee | 213 --------------------------- 4 files changed, 611 deletions(-) delete mode 100644 README.md delete mode 100644 bundle.js delete mode 100644 gulpfile.coffee delete mode 100644 src/nml.coffee diff --git a/README.md b/README.md deleted file mode 100644 index eb33ba6..0000000 --- a/README.md +++ /dev/null @@ -1,7 +0,0 @@ -# NML-JavaScript -NML to HTML/PlainText for JavaScript by @kawakawaritsuki - -NMLをいろいろと変換するためのnpmパッケージ。 - -このリンクから試せます。 -http://writerlighter.github.io/NML-JavaScript/ diff --git a/bundle.js b/bundle.js deleted file mode 100644 index d29c491..0000000 --- a/bundle.js +++ /dev/null @@ -1,372 +0,0 @@ -(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o" + novel.to("html") + ""); - }else if (mode.options[mode.selectedIndex].value === "html"){ - var text = novel.to(mode.options[mode.selectedIndex].value); - text = text.replace( /\n/g , "" ) ; - $("#output").replaceWith(""); - var pre = document.querySelectorAll('pre'); - for(var i = 0; i < pre.length; i++) { - pre[i].innerHTML = escapeHtml(pre[i].innerHTML); - } - }else{ - $("#output").replaceWith("
" + "
" + novel.to(mode.options[mode.selectedIndex].value) + "
" + "
"); - } -} -function spaces(len) -{ - var s = ''; - var indent = len*4; - for (i=0;i)(<)(\/*)/g,"$1\r$2$3"); - - // add indents - var pad = 0; - var indent; - var node; - - // split the string - var strArr = str.split("\r"); - - // check the various tag states - for (var i = 0; i < strArr.length; i++) { - indent = 0; - node = strArr[i]; - - if(node.match(/.+<\/\w[^>]*>$/)){ //open and closing in the same line - indent = 0; - } else if(node.match(/^<\/\w/)){ // closing tag - if (pad > 0){pad -= 1;} - } else if (node.match(/^<\w[^>]*[^\/]>.*$/)){ //opening tag - indent = 1; - } else - indent = 0; - //} - - xml += spaces(pad) + node + "\r"; - pad += indent; - } - - return xml; -} - -var escapeHtml = (function (String) { - var escapeMap = { - '&': '&', - "'": ''', - '`': '`', - '"': '"', - '<': '<', - '>': '>' - }; - var escapeReg = '['; - var reg; - for (var p in escapeMap) { - if (escapeMap.hasOwnProperty(p)) { - escapeReg += p; - } - } - escapeReg += ']'; - reg = new RegExp(escapeReg, 'g'); - return function escapeHtml (str) { - str = (str === null || str === undefined) ? '' : '' + str; - return str.replace(reg, function (match) { - return escapeMap[match]; - }); - }; -}(String)); - - -$(function(){ - convert(); -}); - -$(function(){ - $("#textarea").bind("keyup", function(){ - convert(); - }); -}); - -},{"./out/nml":2}],2:[function(require,module,exports){ -(function() { - module.exports = this.NML = (function() { - var checkBlockquotes, checkBold, checkItalic, checkLine, checkLink, checkNewPage, checkNextLine, checkPunctuationNumber, checkPunctuationSymbol, checkReturn, checkRuby, checkSharp, checkSpace, checkStrikethrough, mode, multi_line, multi_line_mode; - - mode = 0; - - multi_line = ""; - - multi_line_mode = 0; - - function NML(text1) { - this.text = text1; - } - - NML.prototype.to = function(t) { - var body, s; - switch (t) { - case "html": - mode = 1; - s = ''; - body = this.text.split('\n'); - body.forEach(function(text1) { - this.text = text1; - return s = s + checkLine(this.text) + '\n'; - }); - return '
' + s + '
'; - case "plain": - mode = 2; - s = ''; - body = this.text.split('\n'); - body.forEach(function(text1) { - this.text = text1; - return s = s + checkLine(this.text) + '\n'; - }); - return s; - default: - return "Error!"; - } - }; - - checkLine = function(line) { - line = checkSpace(line); - line = checkReturn(line); - line = checkRuby(line); - line = checkNewPage(line); - line = checkSharp(line); - line = checkStrikethrough(line); - line = checkItalic(line); - line = checkBold(line); - line = checkBlockquotes(line); - line = checkLink(line); - line = checkPunctuationNumber(line); - line = checkPunctuationSymbol(line); - line = checkNextLine(line); - return line; - }; - - checkSpace = function(line) { - if (line.match(/^[ \s]/)) { - if (mode === 1) { - line = '

' + line + '

'; - } - } - return line; - }; - - checkReturn = function(line) { - if (line === '') { - if (mode === 1) { - line = '
'; - } - } - return line; - }; - - checkRuby = function(line) { - var moji, myArray, myRe, ruby, text; - myRe = /[\||].*?[\((].*?[\))]/g; - myArray = void 0; - while ((myArray = myRe.exec(line)) !== null) { - text = myArray[0]; - if (mode === 1) { - moji = text.match(/[\||].*?[\((]/)[0]; - moji = moji.substring(1, moji.length - 1); - ruby = text.match(/[\((].*?[\))]/)[0]; - ruby = ruby.substring(1, ruby.length - 1); - line = line.replace(text, '' + moji + '' + ruby + ''); - } else { - moji = text.match(/[\||].*?[\((]/)[0]; - moji = moji.substring(1, moji.length - 1); - line = line.replace(text, moji); - } - } - return line; - }; - - checkNewPage = function(line) { - if (line.match(/^[-ーis]{3,}$/)) { - if (mode === 1) { - line = '
'; - } else if (mode === 2) { - line = ''; - } - } - return line; - }; - - checkSharp = function(line) { - var count, md; - if (mode === 1) { - md = void 0; - if ((md = line.match(/^[##]*/)[0]) !== '') { - count = md.length > 6 ? 6 : md.length; - line = line.replace(/^[##]*/, ''); - line = '' + line + ''; - } - } else if (mode === 2) { - line = line.replace(/^[##]*/, ''); - } - return line; - }; - - checkStrikethrough = function(line) { - var myArray, myRe, text; - myRe = /[\~〜]{2}.*?[\~〜]{2}/g; - myArray = void 0; - while ((myArray = myRe.exec(line)) !== null) { - text = myArray[0]; - if (mode === 1) { - line = line.replace(text, '' + text.substring(2, text.length - 2) + ''); - } else if (mode === 2) { - line = line.replace(text, text.substring(2, text.length - 2)); - } - } - return line; - }; - - checkItalic = function(line) { - var myArray, myRe, text; - myRe = /[\__**]{1}.*?[\__**]{1}/g; - myArray = void 0; - while ((myArray = myRe.exec(line)) !== null) { - text = myArray[0]; - if (mode === 1) { - if (!text.match(/^[\__**]{2}$/)) { - line = line.replace(text, '' + text.substring(1, text.length - 1) + ''); - } - } else if (mode === 2) { - if (!text.match(/^[\__**]{2}$/)) { - line = line.replace(text, text.substring(1, text.length - 1)); - } - } - } - return line; - }; - - checkBold = function(line) { - var myArray, myRe, text; - myRe = /[\__**]{2}.*?[\__**]{2}/g; - myArray = void 0; - while ((myArray = myRe.exec(line)) !== null) { - text = myArray[0]; - if (mode === 1) { - line = line.replace(text, '' + text.substring(2, text.length - 2) + ''); - } else if (mode === 2) { - line = line.replace(text, text.substring(2, text.length - 2)); - } - } - return line; - }; - - checkBlockquotes = function(line) { - if (line.match(/^[>>]/)) { - if (mode === 1) { - line = '
' + line.substring(1) + '
'; - } - } - return line; - }; - - checkLink = function(line) { - var linkText, myArray, myRe, name, text, url; - myRe = /[!!]*\[.*?\][\((].*?[\))]/g; - myArray = void 0; - while ((myArray = myRe.exec(line)) !== null) { - text = myArray[0]; - if (text.match(/[!!]{1,}\[.*?\][\((].*?[\))]/)) { - if (mode === 1) { - if (text.match(/\".*\"/)) { - linkText = line.match(/\[.*?\]/)[0]; - url = line.match(/[\((].*?[\"]/)[0].replace(RegExp(' ', 'g'), ''); - name = line.match(/[\"].*?[\"]/)[0]; - linkText = linkText.substring(1, linkText.length - 1); - url = url.substring(1, url.length - 1); - name = name.substring(1, name.length - 1); - line = line.replace(text, '' + linkText + ''); - } else { - linkText = line.match(/\[.*?\]/)[0]; - url = line.match(/[\((].*?[\))]/)[0].replace(RegExp(' ', 'g'), ''); - linkText = linkText.substring(1, linkText.length - 1); - url = url.substring(1, url.length - 1); - line = line.replace(text, '' + linkText + ''); - } - } else if (mode === 2) { - line = line.replace(text, ""); - } - } else { - if (mode === 1) { - if (text.match(/\".*\"/)) { - linkText = line.match(/\[.*?\]/)[0]; - url = line.match(/[\((].*?[\"]/)[0].replace(RegExp(' ', 'g'), ''); - name = line.match(/[\"].*?[\"]/)[0]; - linkText = linkText.substring(1, linkText.length - 1); - url = url.substring(1, url.length - 1); - name = name.substring(1, name.length - 1); - line = line.replace(text, '' + linkText + ''); - } else { - linkText = line.match(/\[.*?\]/)[0]; - url = line.match(/[\((].*?[\))]/)[0].replace(RegExp(' ', 'g'), ''); - linkText = linkText.substring(1, linkText.length - 1); - url = url.substring(1, url.length - 1); - line = line.replace(text, '' + linkText + ''); - } - } else if (mode === 2) { - line = line.replace(text, ""); - } - } - } - return line; - }; - - checkPunctuationNumber = function(line) { - if (line.match(/^[0-9]+\.$/)) { - if (mode === 1) { - line = '
'; - } - } - return line; - }; - - checkPunctuationSymbol = function(line) { - if (line.match(/^[-*ー*]+\.$/)) { - if (mode === 1) { - line = '
'; - } - } - return line; - }; - - checkNextLine = function(line) { - if (line.match(/[ \s]{3,}$/)) { - line = line + "
"; - } - return line; - }; - - return NML; - - })(); - -}).call(this); - -},{}]},{},[1]); diff --git a/gulpfile.coffee b/gulpfile.coffee deleted file mode 100644 index d18d80c..0000000 --- a/gulpfile.coffee +++ /dev/null @@ -1,19 +0,0 @@ -gulp = require('gulp') -coffee = require('gulp-coffee') -plumber = require 'gulp-plumber' -concat = require 'gulp-concat' -watch = require 'gulp-watch' -notify = require 'gulp-notify' - -gulp.task 'nml', -> - gulp.src 'src/*.coffee' - .pipe(plumber()) - .pipe(coffee()) - .pipe(concat('nml.js')) - .pipe(gulp.dest('out')) - .pipe notify 'nml.js done!!!', {onLast: true} - -gulp.task 'watch', ['default'], -> - watch(['src/*.coffee'], (e)-> gulp.start 'nml') - -gulp.task 'default', ['nml'] diff --git a/src/nml.coffee b/src/nml.coffee deleted file mode 100644 index ad0a389..0000000 --- a/src/nml.coffee +++ /dev/null @@ -1,213 +0,0 @@ -module.exports = class @NML - - mode = 0 - # mode - # 1:html - # 2:plain - multi_line = "" - multi_line_mode = 0 - # mode - # 0:not multi line - # 1:html - # 2:plain - - constructor: (@text) -> - - to: (t) -> - switch t - when "html" - mode = 1 - s = '' - body = @text.split('\n') - body.forEach (@text) -> - s = s + checkLine(@text) + '\n' - return '
' + s + '
' - when "plain" - mode = 2 - s = '' - body = @text.split('\n') - body.forEach (@text) -> - s = s + checkLine(@text) + '\n' - return s - else - "Error!" - - checkLine = (line) -> - line = checkSpace(line) - line = checkReturn(line) - line = checkRuby(line) - line = checkNewPage(line) - line = checkSharp(line) - line = checkStrikethrough(line) - line = checkItalic(line) - line = checkBold(line) - line = checkBlockquotes(line) - line = checkLink(line) - line = checkPunctuationNumber(line) - line = checkPunctuationSymbol(line) - line = checkNextLine(line) - line - - #形式段落 - checkSpace = (line) -> - if line.match(/^[ \s]/) - if mode is 1 - line = '

' + line + '

' - line - - #意味段落 - checkReturn = (line) -> - if line is '' - if mode is 1 - line = '
' - line - - #ルビ - checkRuby = (line) -> - myRe = /[\||].*?[\((].*?[\))]/g - myArray = undefined - while (myArray = myRe.exec(line)) != null - text = myArray[0] - if mode is 1 - moji = text.match(/[\||].*?[\((]/)[0] - moji = moji.substring(1, moji.length - 1) - ruby = text.match(/[\((].*?[\))]/)[0] - ruby = ruby.substring(1, ruby.length - 1) - line = line.replace(text, '' + moji + '' + ruby + '') - else - moji = text.match(/[\||].*?[\((]/)[0] - moji = moji.substring(1, moji.length - 1) - line = line.replace(text, moji) - line - - #改ページ - checkNewPage = (line) -> - if line.match(/^[-ーis]{3,}$/) - if mode is 1 - line = '
' - else if mode is 2 - line = '' - line - - #見出し - checkSharp = (line) -> - if mode is 1 - md = undefined - if (md = line.match(/^[##]*/)[0]) != '' - count = if md.length > 6 then 6 else md.length - line = line.replace(/^[##]*/, '') - line = '' + line + '' - else if mode is 2 - line = line.replace(/^[##]*/, '') - line - - #打ち消し線 - checkStrikethrough = (line) -> - myRe = /[\~〜]{2}.*?[\~〜]{2}/g - myArray = undefined - while (myArray = myRe.exec(line)) != null - text = myArray[0] - if mode is 1 - line = line.replace(text, '' + text.substring(2, text.length - 2) + '') - else if mode is 2 - line = line.replace(text, text.substring(2, text.length - 2)) - line - - #斜体 - - checkItalic = (line) -> - myRe = /[\__**]{1}.*?[\__**]{1}/g - myArray = undefined - while (myArray = myRe.exec(line)) != null - text = myArray[0] - if mode is 1 - if !text.match(/^[\__**]{2}$/) - line = line.replace(text, '' + text.substring(1, text.length - 1) + '') - else if mode is 2 - if !text.match(/^[\__**]{2}$/) - line = line.replace(text, text.substring(1, text.length - 1)) - line - - #太字 - checkBold = (line) -> - myRe = /[\__**]{2}.*?[\__**]{2}/g - myArray = undefined - while (myArray = myRe.exec(line)) != null - text = myArray[0] - if mode is 1 - line = line.replace(text, '' + text.substring(2, text.length - 2) + '') - else if mode is 2 - line = line.replace(text, text.substring(2, text.length - 2)) - line - - #引用 - checkBlockquotes = (line) -> - if line.match(/^[>>]/) - if mode is 1 - line = '
' + line.substring(1) + '
' - line - - #リンク/画像 - checkLink = (line) -> - myRe = /[!!]*\[.*?\][\((].*?[\))]/g - myArray = undefined - while (myArray = myRe.exec(line)) != null - text = myArray[0] - if text.match(/[!!]{1,}\[.*?\][\((].*?[\))]/) - if mode is 1 - if text.match(/\".*\"/) - linkText = line.match(/\[.*?\]/)[0] - url = line.match(/[\((].*?[\"]/)[0].replace(RegExp(' ', 'g'), '') - name = line.match(/[\"].*?[\"]/)[0] - linkText = linkText.substring(1, linkText.length - 1) - url = url.substring(1, url.length - 1) - name = name.substring(1, name.length - 1) - line = line.replace(text, '' + linkText + '') - else - linkText = line.match(/\[.*?\]/)[0] - url = line.match(/[\((].*?[\))]/)[0].replace(RegExp(' ', 'g'), '') - linkText = linkText.substring(1, linkText.length - 1) - url = url.substring(1, url.length - 1) - line = line.replace(text, '' + linkText + '') - else if mode is 2 - line = line.replace(text, "") - - else - if mode is 1 - if text.match(/\".*\"/) - linkText = line.match(/\[.*?\]/)[0] - url = line.match(/[\((].*?[\"]/)[0].replace(RegExp(' ', 'g'), '') - name = line.match(/[\"].*?[\"]/)[0] - linkText = linkText.substring(1, linkText.length - 1) - url = url.substring(1, url.length - 1) - name = name.substring(1, name.length - 1) - line = line.replace(text, '' + linkText + '') - else - linkText = line.match(/\[.*?\]/)[0] - url = line.match(/[\((].*?[\))]/)[0].replace(RegExp(' ', 'g'), '') - linkText = linkText.substring(1, linkText.length - 1) - url = url.substring(1, url.length - 1) - line = line.replace(text, '' + linkText + '') - else if mode is 2 - line = line.replace(text, "") - line - - #数字区切り - checkPunctuationNumber = (line) -> - if line.match(/^[0-9]+\.$/) - if mode is 1 - line = '
' - line - - #記号区切り - checkPunctuationSymbol = (line) -> - if line.match(/^[-*ー*]+\.$/) - if mode is 1 - line = '
' - line - - #改行 - checkNextLine = (line) -> - if line.match(/[ \s]{3,}$/) - line = line + "
" - line From 74dbcca7caf45738fee8753f873a70c46a9420c3 Mon Sep 17 00:00:00 2001 From: Ritsuki Goto Date: Fri, 20 May 2016 21:03:04 +0900 Subject: [PATCH 2/3] [fix] gitignore --- .gitignore | 2 ++ main.js | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index d543800..225e7c1 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ node_modules out bower_components +bundle.js +nml.js diff --git a/main.js b/main.js index 240af87..554cc26 100644 --- a/main.js +++ b/main.js @@ -1,4 +1,4 @@ -NML = require("./out/nml") +NML = require('nml-converter') window.convert = function() { From 17bb74c7b3e83cfe0f21dff61656a72638456ab3 Mon Sep 17 00:00:00 2001 From: Ritsuki Goto Date: Tue, 26 Jul 2016 21:28:35 +0900 Subject: [PATCH 3/3] [fix] add bundle.js --- .gitignore | 2 - README.md | 8 ++ bundle.js | 372 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 380 insertions(+), 2 deletions(-) create mode 100644 README.md create mode 100644 bundle.js diff --git a/.gitignore b/.gitignore index 225e7c1..d543800 100644 --- a/.gitignore +++ b/.gitignore @@ -2,5 +2,3 @@ node_modules out bower_components -bundle.js -nml.js diff --git a/README.md b/README.md new file mode 100644 index 0000000..fb9896a --- /dev/null +++ b/README.md @@ -0,0 +1,8 @@ +# NML-Converter + +## How to build + +``` +$ npm install nml-converter +$ browserify main.js -o bundle.js +``` diff --git a/bundle.js b/bundle.js new file mode 100644 index 0000000..200544a --- /dev/null +++ b/bundle.js @@ -0,0 +1,372 @@ +(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o" + novel.to("html") + "
"); + }else if (mode.options[mode.selectedIndex].value === "html"){ + var text = novel.to(mode.options[mode.selectedIndex].value); + text = text.replace( /\n/g , "" ) ; + $("#output").replaceWith(""); + var pre = document.querySelectorAll('pre'); + for(var i = 0; i < pre.length; i++) { + pre[i].innerHTML = escapeHtml(pre[i].innerHTML); + } + }else{ + $("#output").replaceWith("
" + "
" + novel.to(mode.options[mode.selectedIndex].value) + "
" + "
"); + } +} +function spaces(len) +{ + var s = ''; + var indent = len*4; + for (i=0;i)(<)(\/*)/g,"$1\r$2$3"); + + // add indents + var pad = 0; + var indent; + var node; + + // split the string + var strArr = str.split("\r"); + + // check the various tag states + for (var i = 0; i < strArr.length; i++) { + indent = 0; + node = strArr[i]; + + if(node.match(/.+<\/\w[^>]*>$/)){ //open and closing in the same line + indent = 0; + } else if(node.match(/^<\/\w/)){ // closing tag + if (pad > 0){pad -= 1;} + } else if (node.match(/^<\w[^>]*[^\/]>.*$/)){ //opening tag + indent = 1; + } else + indent = 0; + //} + + xml += spaces(pad) + node + "\r"; + pad += indent; + } + + return xml; +} + +var escapeHtml = (function (String) { + var escapeMap = { + '&': '&', + "'": ''', + '`': '`', + '"': '"', + '<': '<', + '>': '>' + }; + var escapeReg = '['; + var reg; + for (var p in escapeMap) { + if (escapeMap.hasOwnProperty(p)) { + escapeReg += p; + } + } + escapeReg += ']'; + reg = new RegExp(escapeReg, 'g'); + return function escapeHtml (str) { + str = (str === null || str === undefined) ? '' : '' + str; + return str.replace(reg, function (match) { + return escapeMap[match]; + }); + }; +}(String)); + + +$(function(){ + convert(); +}); + +$(function(){ + $("#textarea").bind("keyup", function(){ + convert(); + }); +}); + +},{"nml-converter":2}],2:[function(require,module,exports){ +(function() { + module.exports = this.NML = (function() { + var checkBlockquotes, checkBold, checkItalic, checkLine, checkLink, checkNewPage, checkNextLine, checkPunctuationNumber, checkPunctuationSymbol, checkReturn, checkRuby, checkSharp, checkSpace, checkStrikethrough, mode, multi_line, multi_line_mode; + + mode = 0; + + multi_line = ""; + + multi_line_mode = 0; + + function NML(text1) { + this.text = text1; + } + + NML.prototype.to = function(t) { + var body, s; + switch (t) { + case "html": + mode = 1; + s = ''; + body = this.text.split('\n'); + body.forEach(function(text1) { + this.text = text1; + return s = s + checkLine(this.text) + '\n'; + }); + return '
' + s + '
'; + case "plain": + mode = 2; + s = ''; + body = this.text.split('\n'); + body.forEach(function(text1) { + this.text = text1; + return s = s + checkLine(this.text) + '\n'; + }); + return s; + default: + return "Error!"; + } + }; + + checkLine = function(line) { + line = checkSpace(line); + line = checkReturn(line); + line = checkRuby(line); + line = checkNewPage(line); + line = checkSharp(line); + line = checkStrikethrough(line); + line = checkItalic(line); + line = checkBold(line); + line = checkBlockquotes(line); + line = checkLink(line); + line = checkPunctuationNumber(line); + line = checkPunctuationSymbol(line); + line = checkNextLine(line); + return line; + }; + + checkSpace = function(line) { + if (line.match(/^[ \s]/)) { + if (mode === 1) { + line = '

' + line + '

'; + } + } + return line; + }; + + checkReturn = function(line) { + if (line === '') { + if (mode === 1) { + line = '
'; + } + } + return line; + }; + + checkRuby = function(line) { + var moji, myArray, myRe, ruby, text; + myRe = /[\||].*?[\((].*?[\))]/g; + myArray = void 0; + while ((myArray = myRe.exec(line)) !== null) { + text = myArray[0]; + if (mode === 1) { + moji = text.match(/[\||].*?[\((]/)[0]; + moji = moji.substring(1, moji.length - 1); + ruby = text.match(/[\((].*?[\))]/)[0]; + ruby = ruby.substring(1, ruby.length - 1); + line = line.replace(text, '' + moji + '' + ruby + ''); + } else { + moji = text.match(/[\||].*?[\((]/)[0]; + moji = moji.substring(1, moji.length - 1); + line = line.replace(text, moji); + } + } + return line; + }; + + checkNewPage = function(line) { + if (line.match(/^[-ーis]{3,}$/)) { + if (mode === 1) { + line = '
'; + } else if (mode === 2) { + line = ''; + } + } + return line; + }; + + checkSharp = function(line) { + var count, md; + if (mode === 1) { + md = void 0; + if ((md = line.match(/^[##]*/)[0]) !== '') { + count = md.length > 6 ? 6 : md.length; + line = line.replace(/^[##]*/, ''); + line = '' + line + ''; + } + } else if (mode === 2) { + line = line.replace(/^[##]*/, ''); + } + return line; + }; + + checkStrikethrough = function(line) { + var myArray, myRe, text; + myRe = /[\~〜]{2}.*?[\~〜]{2}/g; + myArray = void 0; + while ((myArray = myRe.exec(line)) !== null) { + text = myArray[0]; + if (mode === 1) { + line = line.replace(text, '' + text.substring(2, text.length - 2) + ''); + } else if (mode === 2) { + line = line.replace(text, text.substring(2, text.length - 2)); + } + } + return line; + }; + + checkItalic = function(line) { + var myArray, myRe, text; + myRe = /[\__**]{1}.*?[\__**]{1}/g; + myArray = void 0; + while ((myArray = myRe.exec(line)) !== null) { + text = myArray[0]; + if (mode === 1) { + if (!text.match(/^[\__**]{2}$/)) { + line = line.replace(text, '' + text.substring(1, text.length - 1) + ''); + } + } else if (mode === 2) { + if (!text.match(/^[\__**]{2}$/)) { + line = line.replace(text, text.substring(1, text.length - 1)); + } + } + } + return line; + }; + + checkBold = function(line) { + var myArray, myRe, text; + myRe = /[\__**]{2}.*?[\__**]{2}/g; + myArray = void 0; + while ((myArray = myRe.exec(line)) !== null) { + text = myArray[0]; + if (mode === 1) { + line = line.replace(text, '' + text.substring(2, text.length - 2) + ''); + } else if (mode === 2) { + line = line.replace(text, text.substring(2, text.length - 2)); + } + } + return line; + }; + + checkBlockquotes = function(line) { + if (line.match(/^[>>]/)) { + if (mode === 1) { + line = '
' + line.substring(1) + '
'; + } + } + return line; + }; + + checkLink = function(line) { + var linkText, myArray, myRe, name, text, url; + myRe = /[!!]*\[.*?\][\((].*?[\))]/g; + myArray = void 0; + while ((myArray = myRe.exec(line)) !== null) { + text = myArray[0]; + if (text.match(/[!!]{1,}\[.*?\][\((].*?[\))]/)) { + if (mode === 1) { + if (text.match(/\".*\"/)) { + linkText = line.match(/\[.*?\]/)[0]; + url = line.match(/[\((].*?[\"]/)[0].replace(RegExp(' ', 'g'), ''); + name = line.match(/[\"].*?[\"]/)[0]; + linkText = linkText.substring(1, linkText.length - 1); + url = url.substring(1, url.length - 1); + name = name.substring(1, name.length - 1); + line = line.replace(text, '' + linkText + ''); + } else { + linkText = line.match(/\[.*?\]/)[0]; + url = line.match(/[\((].*?[\))]/)[0].replace(RegExp(' ', 'g'), ''); + linkText = linkText.substring(1, linkText.length - 1); + url = url.substring(1, url.length - 1); + line = line.replace(text, '' + linkText + ''); + } + } else if (mode === 2) { + line = line.replace(text, ""); + } + } else { + if (mode === 1) { + if (text.match(/\".*\"/)) { + linkText = line.match(/\[.*?\]/)[0]; + url = line.match(/[\((].*?[\"]/)[0].replace(RegExp(' ', 'g'), ''); + name = line.match(/[\"].*?[\"]/)[0]; + linkText = linkText.substring(1, linkText.length - 1); + url = url.substring(1, url.length - 1); + name = name.substring(1, name.length - 1); + line = line.replace(text, '' + linkText + ''); + } else { + linkText = line.match(/\[.*?\]/)[0]; + url = line.match(/[\((].*?[\))]/)[0].replace(RegExp(' ', 'g'), ''); + linkText = linkText.substring(1, linkText.length - 1); + url = url.substring(1, url.length - 1); + line = line.replace(text, '' + linkText + ''); + } + } else if (mode === 2) { + line = line.replace(text, ""); + } + } + } + return line; + }; + + checkPunctuationNumber = function(line) { + if (line.match(/^[0-9]+\.$/)) { + if (mode === 1) { + line = '
'; + } + } + return line; + }; + + checkPunctuationSymbol = function(line) { + if (line.match(/^[-*ー*]+\.$/)) { + if (mode === 1) { + line = '
'; + } + } + return line; + }; + + checkNextLine = function(line) { + if (line.match(/[ \s]{3,}$/)) { + line = line + "
"; + } + return line; + }; + + return NML; + + })(); + +}).call(this); + +},{}]},{},[1]);