diff --git a/README.md b/README.md index eb33ba6..fb9896a 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,8 @@ -# NML-JavaScript -NML to HTML/PlainText for JavaScript by @kawakawaritsuki +# NML-Converter -NMLをいろいろと変換するためのnpmパッケージ。 +## How to build -このリンクから試せます。 -http://writerlighter.github.io/NML-JavaScript/ +``` +$ npm install nml-converter +$ browserify main.js -o bundle.js +``` diff --git a/bundle.js b/bundle.js index d29c491..200544a 100644 --- a/bundle.js +++ b/bundle.js @@ -1,5 +1,5 @@ (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 - 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/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() { 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