From e3156431586854a9a68941df2f9d6792291d89cf Mon Sep 17 00:00:00 2001 From: Sergey Belov Date: Fri, 3 Dec 2010 14:01:32 +0300 Subject: [PATCH 1/7] Remove BOM from input, fixed help, added verbose flag --- lib/2html.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/2html.js b/lib/2html.js index 78f283c..0eec8b1 100644 --- a/lib/2html.js +++ b/lib/2html.js @@ -12,11 +12,12 @@ exports.main = function() { case '-h': case '--help': sys.puts([ - 'Usage: ohl2html [options]', + 'Usage: shmakowiki2html [options]', '', 'Options:', ' -i, --input : pecifies filename to read the input source, if omit use STDIN', ' -o, --output : specifies filename to write the output, if omit use STDOUT', + ' -v, --verbose : verbose output to STDERR', ' -h, --help : Output help information' ].join('\n')); process.exit(1); @@ -29,6 +30,10 @@ exports.main = function() { case '--output': options.output = args.shift(); break; + case '-v': + case '--verbose': + options.verbose = true; + break; } } @@ -47,6 +52,8 @@ exports.main = function() { .on('data', function(s) { input += s }) .on('end', function() { inputFn(input) }); })(function(input){ + // remove BOM if present + if (input.charCodeAt(0) == 65279) input = input.slice(1); try { var shmakowiki = require('shmakowiki'), result = shmakowiki.ShmakoWikiToHtml.match( @@ -56,7 +63,7 @@ exports.main = function() { options.output ? fs.writeFile(options.output, result, 'utf8', function(err) { if (err) throw err; - sys.error(' create : ' + options.output); + if (options.verbose) sys.error(' create : ' + options.output); }) : process.stdout.write(result); } catch (e) { From 7acb148a7331cd2673876227c74233957b3adea7 Mon Sep 17 00:00:00 2001 From: Sergey Belov Date: Sat, 13 Aug 2011 18:33:06 +0300 Subject: [PATCH 2/7] shmakowiki2bemjson MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit — shmakowiki2bemjson utility — ShmakoWikiToBemjson OMetaJS translator — tests.js updates --- GNUmakefile | 1 + bin/shmakowiki2bemjson | 3 + lib/2bemjson.js | 79 +++++++++++++++++++++++ lib/2html.js | 2 +- lib/shmakowiki.js | 41 +++++++++++- src/shmakowiki.ometajs.js | 4 +- src/shmakowiki2bemjson.ometajs | 102 ++++++++++++++++++++++++++++++ src/shmakowiki2bemjson.ometajs.js | 35 ++++++++++ src/shmakowiki2html.ometajs.js | 2 +- tests/tests.js | 5 +- 10 files changed, 266 insertions(+), 8 deletions(-) create mode 100755 bin/shmakowiki2bemjson create mode 100644 lib/2bemjson.js create mode 100644 src/shmakowiki2bemjson.ometajs create mode 100644 src/shmakowiki2bemjson.ometajs.js diff --git a/GNUmakefile b/GNUmakefile index ac9c290..340a8de 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -14,6 +14,7 @@ lib/shmakowiki.js: src shmakowiki.js \ shmakowiki.ometajs.js \ shmakowiki2html.ometajs.js \ + shmakowiki2bemjson.ometajs.js \ ; do \ cat $> $@ \ ; done diff --git a/bin/shmakowiki2bemjson b/bin/shmakowiki2bemjson new file mode 100755 index 0000000..85ba6c3 --- /dev/null +++ b/bin/shmakowiki2bemjson @@ -0,0 +1,3 @@ +#!/usr/bin/env node + +require('../lib/2bemjson').main(); diff --git a/lib/2bemjson.js b/lib/2bemjson.js new file mode 100644 index 0000000..b3fb672 --- /dev/null +++ b/lib/2bemjson.js @@ -0,0 +1,79 @@ +exports.main = function() { + + var sys = require('sys'), + fs = require('fs'), + args = process.argv.slice(2), + arg, + options = {}; + + while(args.length) { + arg = args.shift(); + switch (arg) { + case '-h': + case '--help': + sys.puts([ + 'Usage: shmakowiki2bemjson [options]', + '', + 'Options:', + ' -i, --input : pecifies filename to read the input source, if omit use STDIN', + ' -o, --output : specifies filename to write the output, if omit use STDOUT', + ' -v, --verbose : verbose output to STDERR', + ' -h, --help : Output help information' + ].join('\n')); + process.exit(1); + break; + case '-i': + case '--input': + options.input = args.shift(); + break; + case '-o': + case '--output': + options.output = args.shift(); + break; + case '-v': + case '--verbose': + options.verbose = true; + break; + } + } + + (options.input ? + // if input file + function(inputFn) { + fs.readFile(options.input, 'utf8', function(err, input){ + if (err) throw err; + inputFn(input); + }); + } : + // if STDIN + function(inputFn) { + var input = ''; + process.openStdin() + .on('data', function(s) { input += s }) + .on('end', function() { inputFn(input) }); + })(function(input){ + // remove BOM if present + if (input.charCodeAt(0) == 65279) input = input.slice(1); + try { + var shmakowiki = require('./shmakowiki'), + result = JSON.stringify(shmakowiki.ShmakoWikiToBemjson.match( + shmakowiki.ShmakoWiki.matchAll(input, 'topLevel'), + 'topLevel' + )) + '\n'; + options.output ? + fs.writeFile(options.output, result, 'utf8', function(err) { + if (err) throw err; + if (options.verbose) sys.error(' create : ' + options.output); + }) : + process.stdout.write(result); + } catch (e) { + e.errorPos != undefined && + sys.error( + input.slice(0, e.errorPos) + + "\n--- Parse error ->" + + input.slice(e.errorPos) + '\n'); + throw e + } + }); + +}; diff --git a/lib/2html.js b/lib/2html.js index 0eec8b1..f9384dd 100644 --- a/lib/2html.js +++ b/lib/2html.js @@ -55,7 +55,7 @@ exports.main = function() { // remove BOM if present if (input.charCodeAt(0) == 65279) input = input.slice(1); try { - var shmakowiki = require('shmakowiki'), + var shmakowiki = require('./shmakowiki'), result = shmakowiki.ShmakoWikiToHtml.match( shmakowiki.ShmakoWiki.matchAll(input, 'topLevel'), 'topLevel' diff --git a/lib/shmakowiki.js b/lib/shmakowiki.js index a785898..0c04fce 100644 --- a/lib/shmakowiki.js +++ b/lib/shmakowiki.js @@ -38,7 +38,7 @@ var ometajs = require('ometajs'), "subscript_":function(){var $elf=this,_fromIdx=this.input.idx,c;return (function(){c=this._applyWithArgs("between_","sub");return ["subscript_",c]}).call(this)}, "link":function(){var $elf=this,_fromIdx=this.input.idx,n,nn,c,cc;return (function(){n=this._apply("anything");nn=(function(){this._apply("linkStart");return ShmakoWiki.arrAdd(n,"l")}).call(this);c=this._many1((function(){return (function(){this._not((function(){return this._apply("space")}));this._not((function(){return this._apply("linkEnd")}));return this._apply("char")}).call(this)}));this._apply("spacesNoNl");cc=this._many((function(){return (function(){this._not((function(){return this._applyWithArgs("oneOf",ShmakoWiki.arrCopy(nn))}));return this._applyWithArgs("allInline",nn)}).call(this)}));this._apply("linkEnd");return ["link",c.join(""),cc]}).call(this)}, "link_":function(){var $elf=this,_fromIdx=this.input.idx,c;return this._or((function(){return (function(){this._apply("linkStart");c=this._many1((function(){return (function(){this._not((function(){return this._apply("space")}));return this._apply("char")}).call(this)}));this._or((function(){return this._not((function(){return this._not((function(){return this._apply("space")}))}))}),(function(){return this._not((function(){return this._not((function(){return this._apply("special")}))}))}),(function(){return this._apply("end")}));return ["link_",c.join("")]}).call(this)}),(function(){return (function(){this._apply("linkEnd");return ""}).call(this)}))}, -"mdash":function(){var $elf=this,_fromIdx=this.input.idx;return (function(){this._applyWithArgs("exactly"," ");this._applyWithArgs("exactly","-");this._applyWithArgs("exactly","-");this._applyWithArgs("exactly"," ");" -- ";return " – "}).call(this)}, +"mdash":function(){var $elf=this,_fromIdx=this.input.idx;return (function(){this._applyWithArgs("exactly"," ");this._applyWithArgs("exactly","-");this._applyWithArgs("exactly","-");this._applyWithArgs("exactly"," ");" -- ";return " \u2013 "}).call(this)}, "text":function(){var $elf=this,_fromIdx=this.input.idx,c,c;return this._or((function(){return (function(){c=this._many1((function(){return (function(){this._not((function(){return this._apply("special")}));this._not((function(){return this._apply("escapedChar")}));return this._or((function(){return this._apply("mdash")}),(function(){return this._apply("char")}))}).call(this)}));return c.join("")}).call(this)}),(function(){return (function(){c=this._apply("escaped");return c}).call(this)}))}, "inline":function(){var $elf=this,_fromIdx=this.input.idx,n;return (function(){n=this._apply("anything");return this._or((function(){return this._applyWithArgs("bold",n)}),(function(){return this._applyWithArgs("italic",n)}),(function(){return this._applyWithArgs("underline",n)}),(function(){return this._applyWithArgs("strike",n)}),(function(){return this._applyWithArgs("monospace",n)}),(function(){return this._applyWithArgs("superscript",n)}),(function(){return this._applyWithArgs("subscript",n)}),(function(){return this._applyWithArgs("link",n)}),(function(){return this._apply("lineBreak")}),(function(){return this._apply("text")}))}).call(this)}, "inline_":function(){var $elf=this,_fromIdx=this.input.idx;return this._or((function(){return this._apply("bold_")}),(function(){return this._apply("italic_")}),(function(){return this._apply("underline_")}),(function(){return this._apply("superscript_")}),(function(){return this._apply("subscript_")}),(function(){return this._apply("strike_")}),(function(){return this._apply("monospace_")}),(function(){return this._apply("link_")}))}, @@ -64,7 +64,7 @@ var ometajs = require('ometajs'), "extBlockEnd":function(){var $elf=this,_fromIdx=this.input.idx,t,t;return this._or((function(){return (function(){t=this._apply("anything");this._pred((t["length"] == (0)));this._many((function(){return this._apply("space")}));return this._apply("ext")}).call(this)}),(function(){return (function(){t=this._apply("char");this._pred((t["length"] > (0)));this._many((function(){return this._apply("space")}));this._applyWithArgs("exactly","%");this._applyWithArgs("seq",t);return this._apply("ext")}).call(this)}))}, "extBlock":function(){var $elf=this,_fromIdx=this.input.idx,s,cc,c;return (function(){s=this._apply("extBlockStart");c=(function(){cc=this._many1((function(){return (function(){this._not((function(){return this._applyWithArgs("extBlockEnd",s[(0)])}));return this._apply("char")}).call(this)}));return cc.join("")}).call(this);this._applyWithArgs("extBlockEnd",s[(0)]);this._or((function(){return this._apply("blockEnd")}),(function(){return (function(){switch(this._apply('anything')){case "\n":return "\n";default: throw fail}}).call(this)}));return ["extention",s[(1)],(ShmakoWiki["extentions"].hasOwnProperty(s[(1)])?ShmakoWiki["extentions"][s[(1)]](c,s[(2)]):c),s[(2)]]}).call(this)}, "allBlock":function(){var $elf=this,_fromIdx=this.input.idx,l;return this._or((function(){return this._apply("extBlock")}),(function(){return (function(){l=this._apply("anyList");this._apply("blockEnd");return l}).call(this)}),(function(){return this._apply("header")}),(function(){return this._apply("para")}))}, -"topLevel":function(){var $elf=this,_fromIdx=this.input.idx;return this._many1((function(){return this._apply("allBlock")}))}});(ShmakoWiki["extentions"]=({"ohl": (function (c,p){return OmetaHighlighter.matchAll(c,p)})}));(ShmakoWiki["extentions"]["hl"]=ShmakoWiki["extentions"]["ohl"]);(ShmakoWiki["arrJoin"]=(function (arr1,arr2){var newArr=ShmakoWiki.arrCopy(arr1);for(var i=(0);(i < arr2["length"]);i++){(newArr[newArr["length"]]=arr2[i])};return newArr}));(ShmakoWiki["arrCopy"]=(function (arr){var newArr=[];for(var i=(0);(i < arr["length"]);i++){(newArr[newArr["length"]]=arr[i])};return newArr}));(ShmakoWiki["arrAdd"]=(function (arr,elem){for(var i=(0);(i < arr["length"]);i++){if((arr[i] == elem)){return arr}else{undefined}};(arr[arr["length"]]=elem);return arr}))} +"topLevel":function(){var $elf=this,_fromIdx=this.input.idx;return this._many1((function(){return this._apply("allBlock")}))}});(ShmakoWiki["extentions"]=({"ohl": (function (c,p){return OmetaHighlighter.matchAll(c,p)})}));(ShmakoWiki["extentions"]["hl"]=ShmakoWiki["extentions"]["ohl"]);(ShmakoWiki["arrJoin"]=(function (arr1,arr2){var newArr = ShmakoWiki.arrCopy(arr1);for(var i = (0);(i < arr2["length"]);i++){(newArr[newArr["length"]]=arr2[i])};return newArr}));(ShmakoWiki["arrCopy"]=(function (arr){var newArr = [];for(var i = (0);(i < arr["length"]);i++){(newArr[newArr["length"]]=arr[i])};return newArr}));(ShmakoWiki["arrAdd"]=(function (arr,elem){for(var i = (0);(i < arr["length"]);i++){if((arr[i] == elem)){return arr}else{undefined}};(arr[arr["length"]]=elem);return arr}))} {var ShmakoWikiToHtml=exports.ShmakoWikiToHtml=objectThatDelegatesTo(OMeta,{ "keyword":function(){var $elf=this,_fromIdx=this.input.idx;return (function(){switch(this._apply('anything')){case "para":return "para";case "header1":return "header1";case "header2":return "header2";case "header3":return "header3";case "header4":return "header4";case "header5":return "header5";case "header6":return "header6";case "olist":return "olist";case "ulist":return "ulist";case "olistItem":return "olistItem";case "ulistItem":return "ulistItem";case "bold":return "bold";case "bold_":return "bold_";case "italic":return "italic";case "italic_":return "italic_";case "underline":return "underline";case "underline_":return "underline_";case "strike":return "strike";case "strike_":return "strike_";case "monospace":return "monospace";case "monospace_":return "monospace_";case "superscript":return "superscript";case "superscript_":return "superscript_";case "subscript":return "subscript";case "subscript_":return "subscript_";case "link":return "link";case "link_":return "link_";case "lineBreak":return "lineBreak";case "escaped":return "escaped";case "extention":return "extention";default: throw fail}}).call(this)}, "token":function(){var $elf=this,_fromIdx=this.input.idx,t,ans,c;return this._or((function(){return (function(){this._form((function(){return (function(){t=this._apply("keyword");return ans=this._applyWithArgs("apply",t)}).call(this)}));return ans}).call(this)}),(function(){return (function(){c=this._apply("anything");return ShmakoWikiToHtml._escape(c)}).call(this)}))}, @@ -99,4 +99,39 @@ var ometajs = require('ometajs'), "olistItem":function(){var $elf=this,_fromIdx=this.input.idx,c;return (function(){c=this._apply("tokens");return (("
  • " + c) + "
  • ")}).call(this)}, "ulistItem":function(){var $elf=this,_fromIdx=this.input.idx,c;return (function(){c=this._apply("tokens");return (("
  • " + c) + "
  • ")}).call(this)}, "extention":function(){var $elf=this,_fromIdx=this.input.idx,t,c,p;return (function(){t=this._apply("anything");c=this._apply("anything");p=this._apply("anything");return (ShmakoWikiToHtml["extentions"].hasOwnProperty(t)?ShmakoWikiToHtml["extentions"][t](c,p):(("
    " + ShmakoWikiToHtml._escape(c)) + "
    "))}).call(this)}, -"topLevel":function(){var $elf=this,_fromIdx=this.input.idx,c;return (function(){c=this._apply("tokens");return (("
    " + c) + "
    ")}).call(this)}});(ShmakoWikiToHtml["extentions"]=({"html": (function (c){return c}),"ohl": (function (c,p){return OmetaHighlighterToHtml.match(c,"topLevel")}),"hljs": (function (c,p){return (((("
    ") + ShmakoWikiToHtml._escape(c)) + "
    ")})}));(ShmakoWikiToHtml["extentions"]["hl"]=ShmakoWikiToHtml["extentions"]["ohl"]);(ShmakoWikiToHtml["_escape"]=(function (){{var amp=new RegExp("&","g");var lt=new RegExp("<","g");var gt=new RegExp(">","g");var apos=new RegExp("\'","g");var quot=new RegExp("\"","g")};return (function (s){return String(s).replace(amp,"&").replace(lt,"<").replace(gt,">").replace(apos,"'").replace(quot,""")})})())} +"topLevel":function(){var $elf=this,_fromIdx=this.input.idx,c;return (function(){c=this._apply("tokens");return (("
    " + c) + "
    ")}).call(this)}});(ShmakoWikiToHtml["extentions"]=({"html": (function (c){return c}),"ohl": (function (c,p){return OmetaHighlighterToHtml.match(c,"topLevel")}),"hljs": (function (c,p){return (((("
    ") + ShmakoWikiToHtml._escape(c)) + "
    ")})}));(ShmakoWikiToHtml["extentions"]["hl"]=ShmakoWikiToHtml["extentions"]["ohl"]);(ShmakoWikiToHtml["_escape"]=(function (){var amp = new RegExp("&","g"),lt = new RegExp("<","g"),gt = new RegExp(">","g"),apos = new RegExp("\'","g"),quot = new RegExp("\"","g");return (function (s){return String(s).replace(amp,"&").replace(lt,"<").replace(gt,">").replace(apos,"'").replace(quot,""")})})())} +{var ShmakoWikiToBemjson=exports.ShmakoWikiToBemjson=objectThatDelegatesTo(OMeta,{ +"keyword":function(){var $elf=this,_fromIdx=this.input.idx;return (function(){switch(this._apply('anything')){case "para":return "para";case "header1":return "header1";case "header2":return "header2";case "header3":return "header3";case "header4":return "header4";case "header5":return "header5";case "header6":return "header6";case "olist":return "olist";case "ulist":return "ulist";case "olistItem":return "olistItem";case "ulistItem":return "ulistItem";case "bold":return "bold";case "bold_":return "bold_";case "italic":return "italic";case "italic_":return "italic_";case "underline":return "underline";case "underline_":return "underline_";case "strike":return "strike";case "strike_":return "strike_";case "monospace":return "monospace";case "monospace_":return "monospace_";case "superscript":return "superscript";case "superscript_":return "superscript_";case "subscript":return "subscript";case "subscript_":return "subscript_";case "link":return "link";case "link_":return "link_";case "lineBreak":return "lineBreak";case "escaped":return "escaped";case "extention":return "extention";default: throw fail}}).call(this)}, +"token":function(){var $elf=this,_fromIdx=this.input.idx,t,ans,c;return this._or((function(){return (function(){this._form((function(){return (function(){t=this._apply("keyword");return ans=this._applyWithArgs("apply",t)}).call(this)}));return ans}).call(this)}),(function(){return (function(){c=this._apply("anything");return ShmakoWikiToBemjson._escape(c)}).call(this)}))}, +"tokens":function(){var $elf=this,_fromIdx=this.input.idx,c;return (function(){this._form((function(){return c=this._many((function(){return this._apply("token")}))}));return c}).call(this)}, +"bold":function(){var $elf=this,_fromIdx=this.input.idx,c;return (function(){c=this._apply("tokens");return ({"tag": "b","content": c})}).call(this)}, +"bold_":function(){var $elf=this,_fromIdx=this.input.idx,c;return (function(){c=this._apply("tokens");return ({"tag": "b","content": c})}).call(this)}, +"italic":function(){var $elf=this,_fromIdx=this.input.idx,c;return (function(){c=this._apply("tokens");return ({"tag": "i","content": c})}).call(this)}, +"italic_":function(){var $elf=this,_fromIdx=this.input.idx,c;return (function(){c=this._apply("tokens");return ({"tag": "i","content": c})}).call(this)}, +"underline":function(){var $elf=this,_fromIdx=this.input.idx,c;return (function(){c=this._apply("tokens");return ({"tag": "u","content": c})}).call(this)}, +"underline_":function(){var $elf=this,_fromIdx=this.input.idx,c;return (function(){c=this._apply("tokens");return ({"tag": "u","content": c})}).call(this)}, +"strike":function(){var $elf=this,_fromIdx=this.input.idx,c;return (function(){c=this._apply("tokens");return ({"tag": "s","content": c})}).call(this)}, +"strike_":function(){var $elf=this,_fromIdx=this.input.idx,c;return (function(){c=this._apply("tokens");return ({"tag": "s","content": c})}).call(this)}, +"monospace":function(){var $elf=this,_fromIdx=this.input.idx,c;return (function(){c=this._apply("tokens");return ({"tag": "tt","content": c})}).call(this)}, +"monospace_":function(){var $elf=this,_fromIdx=this.input.idx,c;return (function(){c=this._apply("tokens");return ({"tag": "tt","content": c})}).call(this)}, +"superscript":function(){var $elf=this,_fromIdx=this.input.idx,c;return (function(){c=this._apply("tokens");return ({"tag": "sup","content": c})}).call(this)}, +"superscript_":function(){var $elf=this,_fromIdx=this.input.idx,c;return (function(){c=this._apply("tokens");return ({"tag": "sup","content": c})}).call(this)}, +"subscript":function(){var $elf=this,_fromIdx=this.input.idx,c;return (function(){c=this._apply("tokens");return ({"tag": "sub","content": c})}).call(this)}, +"subscript_":function(){var $elf=this,_fromIdx=this.input.idx,c;return (function(){c=this._apply("tokens");return ({"tag": "sub","content": c})}).call(this)}, +"link":function(){var $elf=this,_fromIdx=this.input.idx,c,c,cc;return this._or((function(){return (function(){c=this._apply("token");this._form((function(){return undefined}));return ({"block": "b-link","url": c,"content": c})}).call(this)}),(function(){return (function(){c=this._apply("token");cc=this._apply("tokens");return ({"block": "b-link","url": c,"content": cc})}).call(this)}))}, +"link_":function(){var $elf=this,_fromIdx=this.input.idx,c;return (function(){c=this._apply("token");return ({"block": "b-link","url": c,"content": c})}).call(this)}, +"lineBreak":function(){var $elf=this,_fromIdx=this.input.idx,c;return (function(){c=this._apply("anything");return ({"tag": "br"})}).call(this)}, +"escaped":function(){var $elf=this,_fromIdx=this.input.idx,c;return (function(){c=this._apply("tokens");return ({"tag": "span","content": c})}).call(this)}, +"para":function(){var $elf=this,_fromIdx=this.input.idx,c;return (function(){c=this._apply("tokens");return ({"elem": "p","content": c})}).call(this)}, +"header1":function(){var $elf=this,_fromIdx=this.input.idx,c;return (function(){c=this._apply("tokens");return ({"elem": "h1","content": c})}).call(this)}, +"header2":function(){var $elf=this,_fromIdx=this.input.idx,c;return (function(){c=this._apply("tokens");return ({"elem": "h2","content": c})}).call(this)}, +"header3":function(){var $elf=this,_fromIdx=this.input.idx,c;return (function(){c=this._apply("tokens");return ({"elem": "h3","content": c})}).call(this)}, +"header4":function(){var $elf=this,_fromIdx=this.input.idx,c;return (function(){c=this._apply("tokens");return ({"elem": "h4","content": c})}).call(this)}, +"header5":function(){var $elf=this,_fromIdx=this.input.idx,c;return (function(){c=this._apply("tokens");return ({"elem": "h5","content": c})}).call(this)}, +"header6":function(){var $elf=this,_fromIdx=this.input.idx,c;return (function(){c=this._apply("tokens");return ({"elem": "h6","content": c})}).call(this)}, +"olist":function(){var $elf=this,_fromIdx=this.input.idx,c;return (function(){c=this._apply("tokens");return ({"elem": "ol","content": c})}).call(this)}, +"ulist":function(){var $elf=this,_fromIdx=this.input.idx,c;return (function(){c=this._apply("tokens");return ({"elem": "ul","content": c})}).call(this)}, +"olistItem":function(){var $elf=this,_fromIdx=this.input.idx,c;return (function(){c=this._apply("tokens");return ({"elem": "li","content": c})}).call(this)}, +"ulistItem":function(){var $elf=this,_fromIdx=this.input.idx,c;return (function(){c=this._apply("tokens");return ({"elem": "li","content": c})}).call(this)}, +"extention":function(){var $elf=this,_fromIdx=this.input.idx,t,c,p;return (function(){t=this._apply("anything");c=this._apply("anything");p=this._apply("anything");return (ShmakoWikiToBemjson["extentions"].hasOwnProperty(t)?ShmakoWikiToBemjson["extentions"][t](c,p):({"tag": "div","content": ShmakoWikiToBemjson._escape(c)}))}).call(this)}, +"topLevel":function(){var $elf=this,_fromIdx=this.input.idx,c;return (function(){c=this._apply("tokens");return ({"block": "b-text","content": c})}).call(this)}});(ShmakoWikiToBemjson["extentions"]=({"html": (function (c){return c}),"ohl": (function (c,p){return OmetaHighlighterToHtml.match(c,"topLevel")}),"hljs": (function (c,p){return ({"tag": "pre","content": (((("") + ShmakoWikiToBemjson._escape(c)) + "")})})}));(ShmakoWikiToBemjson["extentions"]["hl"]=ShmakoWikiToBemjson["extentions"]["ohl"]);(ShmakoWikiToBemjson["_escape"]=(function (){var amp = new RegExp("&","g"),lt = new RegExp("<","g"),gt = new RegExp(">","g"),apos = new RegExp("\'","g"),quot = new RegExp("\"","g");return (function (s){return String(s).replace(amp,"&").replace(lt,"<").replace(gt,">").replace(apos,"'").replace(quot,""")})})())} diff --git a/src/shmakowiki.ometajs.js b/src/shmakowiki.ometajs.js index 63a6877..55ac900 100644 --- a/src/shmakowiki.ometajs.js +++ b/src/shmakowiki.ometajs.js @@ -33,7 +33,7 @@ "subscript_":function(){var $elf=this,_fromIdx=this.input.idx,c;return (function(){c=this._applyWithArgs("between_","sub");return ["subscript_",c]}).call(this)}, "link":function(){var $elf=this,_fromIdx=this.input.idx,n,nn,c,cc;return (function(){n=this._apply("anything");nn=(function(){this._apply("linkStart");return ShmakoWiki.arrAdd(n,"l")}).call(this);c=this._many1((function(){return (function(){this._not((function(){return this._apply("space")}));this._not((function(){return this._apply("linkEnd")}));return this._apply("char")}).call(this)}));this._apply("spacesNoNl");cc=this._many((function(){return (function(){this._not((function(){return this._applyWithArgs("oneOf",ShmakoWiki.arrCopy(nn))}));return this._applyWithArgs("allInline",nn)}).call(this)}));this._apply("linkEnd");return ["link",c.join(""),cc]}).call(this)}, "link_":function(){var $elf=this,_fromIdx=this.input.idx,c;return this._or((function(){return (function(){this._apply("linkStart");c=this._many1((function(){return (function(){this._not((function(){return this._apply("space")}));return this._apply("char")}).call(this)}));this._or((function(){return this._not((function(){return this._not((function(){return this._apply("space")}))}))}),(function(){return this._not((function(){return this._not((function(){return this._apply("special")}))}))}),(function(){return this._apply("end")}));return ["link_",c.join("")]}).call(this)}),(function(){return (function(){this._apply("linkEnd");return ""}).call(this)}))}, -"mdash":function(){var $elf=this,_fromIdx=this.input.idx;return (function(){this._applyWithArgs("exactly"," ");this._applyWithArgs("exactly","-");this._applyWithArgs("exactly","-");this._applyWithArgs("exactly"," ");" -- ";return " – "}).call(this)}, +"mdash":function(){var $elf=this,_fromIdx=this.input.idx;return (function(){this._applyWithArgs("exactly"," ");this._applyWithArgs("exactly","-");this._applyWithArgs("exactly","-");this._applyWithArgs("exactly"," ");" -- ";return " \u2013 "}).call(this)}, "text":function(){var $elf=this,_fromIdx=this.input.idx,c,c;return this._or((function(){return (function(){c=this._many1((function(){return (function(){this._not((function(){return this._apply("special")}));this._not((function(){return this._apply("escapedChar")}));return this._or((function(){return this._apply("mdash")}),(function(){return this._apply("char")}))}).call(this)}));return c.join("")}).call(this)}),(function(){return (function(){c=this._apply("escaped");return c}).call(this)}))}, "inline":function(){var $elf=this,_fromIdx=this.input.idx,n;return (function(){n=this._apply("anything");return this._or((function(){return this._applyWithArgs("bold",n)}),(function(){return this._applyWithArgs("italic",n)}),(function(){return this._applyWithArgs("underline",n)}),(function(){return this._applyWithArgs("strike",n)}),(function(){return this._applyWithArgs("monospace",n)}),(function(){return this._applyWithArgs("superscript",n)}),(function(){return this._applyWithArgs("subscript",n)}),(function(){return this._applyWithArgs("link",n)}),(function(){return this._apply("lineBreak")}),(function(){return this._apply("text")}))}).call(this)}, "inline_":function(){var $elf=this,_fromIdx=this.input.idx;return this._or((function(){return this._apply("bold_")}),(function(){return this._apply("italic_")}),(function(){return this._apply("underline_")}),(function(){return this._apply("superscript_")}),(function(){return this._apply("subscript_")}),(function(){return this._apply("strike_")}),(function(){return this._apply("monospace_")}),(function(){return this._apply("link_")}))}, @@ -59,4 +59,4 @@ "extBlockEnd":function(){var $elf=this,_fromIdx=this.input.idx,t,t;return this._or((function(){return (function(){t=this._apply("anything");this._pred((t["length"] == (0)));this._many((function(){return this._apply("space")}));return this._apply("ext")}).call(this)}),(function(){return (function(){t=this._apply("char");this._pred((t["length"] > (0)));this._many((function(){return this._apply("space")}));this._applyWithArgs("exactly","%");this._applyWithArgs("seq",t);return this._apply("ext")}).call(this)}))}, "extBlock":function(){var $elf=this,_fromIdx=this.input.idx,s,cc,c;return (function(){s=this._apply("extBlockStart");c=(function(){cc=this._many1((function(){return (function(){this._not((function(){return this._applyWithArgs("extBlockEnd",s[(0)])}));return this._apply("char")}).call(this)}));return cc.join("")}).call(this);this._applyWithArgs("extBlockEnd",s[(0)]);this._or((function(){return this._apply("blockEnd")}),(function(){return (function(){switch(this._apply('anything')){case "\n":return "\n";default: throw fail}}).call(this)}));return ["extention",s[(1)],(ShmakoWiki["extentions"].hasOwnProperty(s[(1)])?ShmakoWiki["extentions"][s[(1)]](c,s[(2)]):c),s[(2)]]}).call(this)}, "allBlock":function(){var $elf=this,_fromIdx=this.input.idx,l;return this._or((function(){return this._apply("extBlock")}),(function(){return (function(){l=this._apply("anyList");this._apply("blockEnd");return l}).call(this)}),(function(){return this._apply("header")}),(function(){return this._apply("para")}))}, -"topLevel":function(){var $elf=this,_fromIdx=this.input.idx;return this._many1((function(){return this._apply("allBlock")}))}});(ShmakoWiki["extentions"]=({"ohl": (function (c,p){return OmetaHighlighter.matchAll(c,p)})}));(ShmakoWiki["extentions"]["hl"]=ShmakoWiki["extentions"]["ohl"]);(ShmakoWiki["arrJoin"]=(function (arr1,arr2){var newArr=ShmakoWiki.arrCopy(arr1);for(var i=(0);(i < arr2["length"]);i++){(newArr[newArr["length"]]=arr2[i])};return newArr}));(ShmakoWiki["arrCopy"]=(function (arr){var newArr=[];for(var i=(0);(i < arr["length"]);i++){(newArr[newArr["length"]]=arr[i])};return newArr}));(ShmakoWiki["arrAdd"]=(function (arr,elem){for(var i=(0);(i < arr["length"]);i++){if((arr[i] == elem)){return arr}else{undefined}};(arr[arr["length"]]=elem);return arr}))} +"topLevel":function(){var $elf=this,_fromIdx=this.input.idx;return this._many1((function(){return this._apply("allBlock")}))}});(ShmakoWiki["extentions"]=({"ohl": (function (c,p){return OmetaHighlighter.matchAll(c,p)})}));(ShmakoWiki["extentions"]["hl"]=ShmakoWiki["extentions"]["ohl"]);(ShmakoWiki["arrJoin"]=(function (arr1,arr2){var newArr = ShmakoWiki.arrCopy(arr1);for(var i = (0);(i < arr2["length"]);i++){(newArr[newArr["length"]]=arr2[i])};return newArr}));(ShmakoWiki["arrCopy"]=(function (arr){var newArr = [];for(var i = (0);(i < arr["length"]);i++){(newArr[newArr["length"]]=arr[i])};return newArr}));(ShmakoWiki["arrAdd"]=(function (arr,elem){for(var i = (0);(i < arr["length"]);i++){if((arr[i] == elem)){return arr}else{undefined}};(arr[arr["length"]]=elem);return arr}))} diff --git a/src/shmakowiki2bemjson.ometajs b/src/shmakowiki2bemjson.ometajs new file mode 100644 index 0000000..4093561 --- /dev/null +++ b/src/shmakowiki2bemjson.ometajs @@ -0,0 +1,102 @@ +ometa ShmakoWikiToBemjson { + keyword = 'para' + | 'header1' | 'header2' | 'header3' + | 'header4' | 'header5' | 'header6' + | 'olist' | 'ulist' | 'olistItem' | 'ulistItem' + | 'bold' | 'bold_' + | 'italic' | 'italic_' + | 'underline' | 'underline_' + | 'strike' | 'strike_' + | 'monospace' | 'monospace_' + | 'superscript' | 'superscript_' + | 'subscript' | 'subscript_' + | 'link' | 'link_' + | 'lineBreak' + | 'escaped' + | 'extention', + + token = [keyword:t apply(t):ans] -> ans + | :c -> ShmakoWikiToBemjson._escape(c), + tokens = [token*:c] -> c, + + + bold tokens:c -> { tag: 'b', content: c }, + bold_ tokens:c -> { tag: 'b', content: c }, + + italic tokens:c -> { tag: 'i', content: c }, + italic_ tokens:c -> { tag: 'i', content: c }, + + underline tokens:c -> { tag: 'u', content: c }, + underline_ tokens:c -> { tag: 'u', content: c }, + + strike tokens:c -> { tag: 's', content: c }, + strike_ tokens:c -> { tag: 's', content: c }, + + monospace tokens:c -> { tag: 'tt', content: c }, + monospace_ tokens:c -> { tag: 'tt', content: c }, + + superscript tokens:c -> { tag: 'sup', content: c }, + superscript_ tokens:c -> { tag: 'sup', content: c }, + + subscript tokens:c -> { tag: 'sub', content: c }, + subscript_ tokens:c -> { tag: 'sub', content: c }, + + link token:c [] -> { block: 'b-link', url: c, content: c }, + link token:c tokens:cc -> { block: 'b-link', url: c, content: cc }, + link_ token:c -> { block: 'b-link', url: c, content: c }, + + lineBreak :c -> { tag: 'br' }, + + escaped tokens:c -> { tag: 'span', content: c }, + + para tokens:c -> { elem: 'p', content: c }, + + header1 tokens:c -> { elem: 'h1', content: c }, + header2 tokens:c -> { elem: 'h2', content: c }, + header3 tokens:c -> { elem: 'h3', content: c }, + header4 tokens:c -> { elem: 'h4', content: c }, + header5 tokens:c -> { elem: 'h5', content: c }, + header6 tokens:c -> { elem: 'h6', content: c }, + + olist tokens:c -> { elem: 'ol', content: c }, + ulist tokens:c -> { elem: 'ul', content: c }, + olistItem tokens:c -> { elem: 'li', content: c }, + ulistItem tokens:c -> { elem: 'li', content: c }, + + extention :t :c :p -> (ShmakoWikiToBemjson.extentions.hasOwnProperty(t) ? + ShmakoWikiToBemjson.extentions[t](c, p) : + { tag: 'div', content: ShmakoWikiToBemjson._escape(c) }), + + topLevel = tokens:c -> { block: 'b-text', content: c } +} + +ShmakoWikiToBemjson.extentions = { + 'html': function(c) { return c }, + 'ohl': function(c, p) { return OmetaHighlighterToHtml.match(c, 'topLevel') }, + 'hljs': function(c, p) { + return { + tag: 'pre', + content: '' + + ShmakoWikiToBemjson._escape(c) + + '' + }; + } +}; +ShmakoWikiToBemjson.extentions.hl = ShmakoWikiToBemjson.extentions.ohl; + +ShmakoWikiToBemjson._escape = (function() { + var amp = new RegExp('&', 'g'), + lt = new RegExp('<', 'g'), + gt = new RegExp('>', 'g'), + apos = new RegExp("'", 'g'), + quot = new RegExp('"', 'g'); + + return function(s) { + return String(s) + .replace(amp, '&') + .replace(lt, '<') + .replace(gt, '>') + .replace(apos, ''') + .replace(quot, '"'); + } +})(); diff --git a/src/shmakowiki2bemjson.ometajs.js b/src/shmakowiki2bemjson.ometajs.js new file mode 100644 index 0000000..f6629ca --- /dev/null +++ b/src/shmakowiki2bemjson.ometajs.js @@ -0,0 +1,35 @@ +{var ShmakoWikiToBemjson=exports.ShmakoWikiToBemjson=objectThatDelegatesTo(OMeta,{ +"keyword":function(){var $elf=this,_fromIdx=this.input.idx;return (function(){switch(this._apply('anything')){case "para":return "para";case "header1":return "header1";case "header2":return "header2";case "header3":return "header3";case "header4":return "header4";case "header5":return "header5";case "header6":return "header6";case "olist":return "olist";case "ulist":return "ulist";case "olistItem":return "olistItem";case "ulistItem":return "ulistItem";case "bold":return "bold";case "bold_":return "bold_";case "italic":return "italic";case "italic_":return "italic_";case "underline":return "underline";case "underline_":return "underline_";case "strike":return "strike";case "strike_":return "strike_";case "monospace":return "monospace";case "monospace_":return "monospace_";case "superscript":return "superscript";case "superscript_":return "superscript_";case "subscript":return "subscript";case "subscript_":return "subscript_";case "link":return "link";case "link_":return "link_";case "lineBreak":return "lineBreak";case "escaped":return "escaped";case "extention":return "extention";default: throw fail}}).call(this)}, +"token":function(){var $elf=this,_fromIdx=this.input.idx,t,ans,c;return this._or((function(){return (function(){this._form((function(){return (function(){t=this._apply("keyword");return ans=this._applyWithArgs("apply",t)}).call(this)}));return ans}).call(this)}),(function(){return (function(){c=this._apply("anything");return ShmakoWikiToBemjson._escape(c)}).call(this)}))}, +"tokens":function(){var $elf=this,_fromIdx=this.input.idx,c;return (function(){this._form((function(){return c=this._many((function(){return this._apply("token")}))}));return c}).call(this)}, +"bold":function(){var $elf=this,_fromIdx=this.input.idx,c;return (function(){c=this._apply("tokens");return ({"tag": "b","content": c})}).call(this)}, +"bold_":function(){var $elf=this,_fromIdx=this.input.idx,c;return (function(){c=this._apply("tokens");return ({"tag": "b","content": c})}).call(this)}, +"italic":function(){var $elf=this,_fromIdx=this.input.idx,c;return (function(){c=this._apply("tokens");return ({"tag": "i","content": c})}).call(this)}, +"italic_":function(){var $elf=this,_fromIdx=this.input.idx,c;return (function(){c=this._apply("tokens");return ({"tag": "i","content": c})}).call(this)}, +"underline":function(){var $elf=this,_fromIdx=this.input.idx,c;return (function(){c=this._apply("tokens");return ({"tag": "u","content": c})}).call(this)}, +"underline_":function(){var $elf=this,_fromIdx=this.input.idx,c;return (function(){c=this._apply("tokens");return ({"tag": "u","content": c})}).call(this)}, +"strike":function(){var $elf=this,_fromIdx=this.input.idx,c;return (function(){c=this._apply("tokens");return ({"tag": "s","content": c})}).call(this)}, +"strike_":function(){var $elf=this,_fromIdx=this.input.idx,c;return (function(){c=this._apply("tokens");return ({"tag": "s","content": c})}).call(this)}, +"monospace":function(){var $elf=this,_fromIdx=this.input.idx,c;return (function(){c=this._apply("tokens");return ({"tag": "tt","content": c})}).call(this)}, +"monospace_":function(){var $elf=this,_fromIdx=this.input.idx,c;return (function(){c=this._apply("tokens");return ({"tag": "tt","content": c})}).call(this)}, +"superscript":function(){var $elf=this,_fromIdx=this.input.idx,c;return (function(){c=this._apply("tokens");return ({"tag": "sup","content": c})}).call(this)}, +"superscript_":function(){var $elf=this,_fromIdx=this.input.idx,c;return (function(){c=this._apply("tokens");return ({"tag": "sup","content": c})}).call(this)}, +"subscript":function(){var $elf=this,_fromIdx=this.input.idx,c;return (function(){c=this._apply("tokens");return ({"tag": "sub","content": c})}).call(this)}, +"subscript_":function(){var $elf=this,_fromIdx=this.input.idx,c;return (function(){c=this._apply("tokens");return ({"tag": "sub","content": c})}).call(this)}, +"link":function(){var $elf=this,_fromIdx=this.input.idx,c,c,cc;return this._or((function(){return (function(){c=this._apply("token");this._form((function(){return undefined}));return ({"block": "b-link","url": c,"content": c})}).call(this)}),(function(){return (function(){c=this._apply("token");cc=this._apply("tokens");return ({"block": "b-link","url": c,"content": cc})}).call(this)}))}, +"link_":function(){var $elf=this,_fromIdx=this.input.idx,c;return (function(){c=this._apply("token");return ({"block": "b-link","url": c,"content": c})}).call(this)}, +"lineBreak":function(){var $elf=this,_fromIdx=this.input.idx,c;return (function(){c=this._apply("anything");return ({"tag": "br"})}).call(this)}, +"escaped":function(){var $elf=this,_fromIdx=this.input.idx,c;return (function(){c=this._apply("tokens");return ({"tag": "span","content": c})}).call(this)}, +"para":function(){var $elf=this,_fromIdx=this.input.idx,c;return (function(){c=this._apply("tokens");return ({"elem": "p","content": c})}).call(this)}, +"header1":function(){var $elf=this,_fromIdx=this.input.idx,c;return (function(){c=this._apply("tokens");return ({"elem": "h1","content": c})}).call(this)}, +"header2":function(){var $elf=this,_fromIdx=this.input.idx,c;return (function(){c=this._apply("tokens");return ({"elem": "h2","content": c})}).call(this)}, +"header3":function(){var $elf=this,_fromIdx=this.input.idx,c;return (function(){c=this._apply("tokens");return ({"elem": "h3","content": c})}).call(this)}, +"header4":function(){var $elf=this,_fromIdx=this.input.idx,c;return (function(){c=this._apply("tokens");return ({"elem": "h4","content": c})}).call(this)}, +"header5":function(){var $elf=this,_fromIdx=this.input.idx,c;return (function(){c=this._apply("tokens");return ({"elem": "h5","content": c})}).call(this)}, +"header6":function(){var $elf=this,_fromIdx=this.input.idx,c;return (function(){c=this._apply("tokens");return ({"elem": "h6","content": c})}).call(this)}, +"olist":function(){var $elf=this,_fromIdx=this.input.idx,c;return (function(){c=this._apply("tokens");return ({"elem": "ol","content": c})}).call(this)}, +"ulist":function(){var $elf=this,_fromIdx=this.input.idx,c;return (function(){c=this._apply("tokens");return ({"elem": "ul","content": c})}).call(this)}, +"olistItem":function(){var $elf=this,_fromIdx=this.input.idx,c;return (function(){c=this._apply("tokens");return ({"elem": "li","content": c})}).call(this)}, +"ulistItem":function(){var $elf=this,_fromIdx=this.input.idx,c;return (function(){c=this._apply("tokens");return ({"elem": "li","content": c})}).call(this)}, +"extention":function(){var $elf=this,_fromIdx=this.input.idx,t,c,p;return (function(){t=this._apply("anything");c=this._apply("anything");p=this._apply("anything");return (ShmakoWikiToBemjson["extentions"].hasOwnProperty(t)?ShmakoWikiToBemjson["extentions"][t](c,p):({"tag": "div","content": ShmakoWikiToBemjson._escape(c)}))}).call(this)}, +"topLevel":function(){var $elf=this,_fromIdx=this.input.idx,c;return (function(){c=this._apply("tokens");return ({"block": "b-text","content": c})}).call(this)}});(ShmakoWikiToBemjson["extentions"]=({"html": (function (c){return c}),"ohl": (function (c,p){return OmetaHighlighterToHtml.match(c,"topLevel")}),"hljs": (function (c,p){return ({"tag": "pre","content": (((("") + ShmakoWikiToBemjson._escape(c)) + "")})})}));(ShmakoWikiToBemjson["extentions"]["hl"]=ShmakoWikiToBemjson["extentions"]["ohl"]);(ShmakoWikiToBemjson["_escape"]=(function (){var amp = new RegExp("&","g"),lt = new RegExp("<","g"),gt = new RegExp(">","g"),apos = new RegExp("\'","g"),quot = new RegExp("\"","g");return (function (s){return String(s).replace(amp,"&").replace(lt,"<").replace(gt,">").replace(apos,"'").replace(quot,""")})})())} diff --git a/src/shmakowiki2html.ometajs.js b/src/shmakowiki2html.ometajs.js index 6771ef3..193bb28 100644 --- a/src/shmakowiki2html.ometajs.js +++ b/src/shmakowiki2html.ometajs.js @@ -32,4 +32,4 @@ "olistItem":function(){var $elf=this,_fromIdx=this.input.idx,c;return (function(){c=this._apply("tokens");return (("
  • " + c) + "
  • ")}).call(this)}, "ulistItem":function(){var $elf=this,_fromIdx=this.input.idx,c;return (function(){c=this._apply("tokens");return (("
  • " + c) + "
  • ")}).call(this)}, "extention":function(){var $elf=this,_fromIdx=this.input.idx,t,c,p;return (function(){t=this._apply("anything");c=this._apply("anything");p=this._apply("anything");return (ShmakoWikiToHtml["extentions"].hasOwnProperty(t)?ShmakoWikiToHtml["extentions"][t](c,p):(("
    " + ShmakoWikiToHtml._escape(c)) + "
    "))}).call(this)}, -"topLevel":function(){var $elf=this,_fromIdx=this.input.idx,c;return (function(){c=this._apply("tokens");return (("
    " + c) + "
    ")}).call(this)}});(ShmakoWikiToHtml["extentions"]=({"html": (function (c){return c}),"ohl": (function (c,p){return OmetaHighlighterToHtml.match(c,"topLevel")}),"hljs": (function (c,p){return (((("
    ") + ShmakoWikiToHtml._escape(c)) + "
    ")})}));(ShmakoWikiToHtml["extentions"]["hl"]=ShmakoWikiToHtml["extentions"]["ohl"]);(ShmakoWikiToHtml["_escape"]=(function (){{var amp=new RegExp("&","g");var lt=new RegExp("<","g");var gt=new RegExp(">","g");var apos=new RegExp("\'","g");var quot=new RegExp("\"","g")};return (function (s){return String(s).replace(amp,"&").replace(lt,"<").replace(gt,">").replace(apos,"'").replace(quot,""")})})())} +"topLevel":function(){var $elf=this,_fromIdx=this.input.idx,c;return (function(){c=this._apply("tokens");return (("
    " + c) + "
    ")}).call(this)}});(ShmakoWikiToHtml["extentions"]=({"html": (function (c){return c}),"ohl": (function (c,p){return OmetaHighlighterToHtml.match(c,"topLevel")}),"hljs": (function (c,p){return (((("
    ") + ShmakoWikiToHtml._escape(c)) + "
    ")})}));(ShmakoWikiToHtml["extentions"]["hl"]=ShmakoWikiToHtml["extentions"]["ohl"]);(ShmakoWikiToHtml["_escape"]=(function (){var amp = new RegExp("&","g"),lt = new RegExp("<","g"),gt = new RegExp(">","g"),apos = new RegExp("\'","g"),quot = new RegExp("\"","g");return (function (s){return String(s).replace(amp,"&").replace(lt,"<").replace(gt,">").replace(apos,"'").replace(quot,""")})})())} diff --git a/tests/tests.js b/tests/tests.js index 5b54679..db1aab0 100644 --- a/tests/tests.js +++ b/tests/tests.js @@ -145,7 +145,7 @@ var tests = [ }, ]; -var shmakowiki = require('shmakowiki'), +var shmakowiki = require('..'), totalFail = 0; for (var i = 0; i < tests.length; i++) { @@ -164,6 +164,9 @@ for (var i = 0; i < tests.length; i++) { test.html = shmakowiki.ShmakoWikiToHtml.match(test.res, 'topLevel'); console.log('Test html:\n' + test.html); + test.bemjson = shmakowiki.ShmakoWikiToBemjson.match(test.res, 'topLevel'); + console.log('Test bemjson:\n' + JSON.stringify(test.bemjson)); + console.log('-----------------------------------------------------'); } console.log('\n' + (totalFail ? 'Total FAIL: ' + totalFail : 'All Ok')); From 10433a4c7142a6acd2700c8bf0ba07da699f2d02 Mon Sep 17 00:00:00 2001 From: Sergey Belov Date: Sat, 13 Aug 2011 19:46:33 +0300 Subject: [PATCH 3/7] Added shmakowiki2bemjson to package.json bin --- package.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 07e0312..2790bf7 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,10 @@ }, "main": "./lib/shmakowiki", "directories" : { "lib" : "./lib" }, - "bin" : { "shmakowiki2html" : "./bin/shmakowiki2html" }, + "bin" : { + "shmakowiki2html" : "./bin/shmakowiki2html", + "shmakowiki2bemjson" : "./bin/shmakowiki2bemjson" + }, "dependencies" : { "ometajs" : ">= 2.0.1", "ometa-highlighter" : ">= 0.1.1" From 341b26e1db0fd53924c2e0f9289959bf646deda3 Mon Sep 17 00:00:00 2001 From: Sergey Belov Date: Tue, 16 Aug 2011 19:11:24 +0300 Subject: [PATCH 4/7] Use OmetaHighlighterToBemjson in ShmakoWikiToBemjson for code highlighting --- lib/shmakowiki.js | 3 ++- src/shmakowiki.js | 1 + src/shmakowiki.ometajs | 4 ++-- src/shmakowiki2bemjson.ometajs | 9 ++++----- src/shmakowiki2bemjson.ometajs.js | 2 +- 5 files changed, 10 insertions(+), 9 deletions(-) diff --git a/lib/shmakowiki.js b/lib/shmakowiki.js index 0c04fce..b2080d7 100644 --- a/lib/shmakowiki.js +++ b/lib/shmakowiki.js @@ -3,6 +3,7 @@ var ometajs = require('ometajs'), ohl = require('ometa-highlighter'), OmetaHighlighter = ohl.OmetaHighlighter, OmetaHighlighterToHtml = ohl.OmetaHighlighterToHtml; + OmetaHighlighterToBemjson = ohl.OmetaHighlighterToBemjson; {var ShmakoWiki=exports.ShmakoWiki=objectThatDelegatesTo(OMeta,{ "oneOf":function(){var $elf=this,_fromIdx=this.input.idx,a,a;return this._or((function(){return (function(){a=this._apply("anything");this._pred((a["length"] == (1)));return this._applyWithArgs("apply",a.pop())}).call(this)}),(function(){return (function(){a=this._apply("anything");this._pred((a["length"] > (1)));return this._or((function(){return this._applyWithArgs("apply",a.pop())}),(function(){return this._applyWithArgs("oneOf",a)}))}).call(this)}))}, "escapedChar":function(){var $elf=this,_fromIdx=this.input.idx,c;return (function(){this._applyWithArgs("exactly","~");c=this._apply("char");return c}).call(this)}, @@ -134,4 +135,4 @@ var ometajs = require('ometajs'), "olistItem":function(){var $elf=this,_fromIdx=this.input.idx,c;return (function(){c=this._apply("tokens");return ({"elem": "li","content": c})}).call(this)}, "ulistItem":function(){var $elf=this,_fromIdx=this.input.idx,c;return (function(){c=this._apply("tokens");return ({"elem": "li","content": c})}).call(this)}, "extention":function(){var $elf=this,_fromIdx=this.input.idx,t,c,p;return (function(){t=this._apply("anything");c=this._apply("anything");p=this._apply("anything");return (ShmakoWikiToBemjson["extentions"].hasOwnProperty(t)?ShmakoWikiToBemjson["extentions"][t](c,p):({"tag": "div","content": ShmakoWikiToBemjson._escape(c)}))}).call(this)}, -"topLevel":function(){var $elf=this,_fromIdx=this.input.idx,c;return (function(){c=this._apply("tokens");return ({"block": "b-text","content": c})}).call(this)}});(ShmakoWikiToBemjson["extentions"]=({"html": (function (c){return c}),"ohl": (function (c,p){return OmetaHighlighterToHtml.match(c,"topLevel")}),"hljs": (function (c,p){return ({"tag": "pre","content": (((("") + ShmakoWikiToBemjson._escape(c)) + "")})})}));(ShmakoWikiToBemjson["extentions"]["hl"]=ShmakoWikiToBemjson["extentions"]["ohl"]);(ShmakoWikiToBemjson["_escape"]=(function (){var amp = new RegExp("&","g"),lt = new RegExp("<","g"),gt = new RegExp(">","g"),apos = new RegExp("\'","g"),quot = new RegExp("\"","g");return (function (s){return String(s).replace(amp,"&").replace(lt,"<").replace(gt,">").replace(apos,"'").replace(quot,""")})})())} +"topLevel":function(){var $elf=this,_fromIdx=this.input.idx,c;return (function(){c=this._apply("tokens");return ({"block": "b-text","content": c})}).call(this)}});(ShmakoWikiToBemjson["extentions"]=({"html": (function (c){return c}),"ohl": (function (c,p){return OmetaHighlighterToBemjson.match(c,"topLevel")}),"hljs": (function (c,p){return ({"block": "b-code","cls": p,"content": ShmakoWikiToBemjson._escape(c)})})}));(ShmakoWikiToBemjson["extentions"]["hl"]=ShmakoWikiToBemjson["extentions"]["ohl"]);(ShmakoWikiToBemjson["_escape"]=(function (){var amp = new RegExp("&","g"),lt = new RegExp("<","g"),gt = new RegExp(">","g"),apos = new RegExp("\'","g"),quot = new RegExp("\"","g");return (function (s){return String(s).replace(amp,"&").replace(lt,"<").replace(gt,">").replace(apos,"'").replace(quot,""")})})())} diff --git a/src/shmakowiki.js b/src/shmakowiki.js index c55f1f3..c8d871f 100644 --- a/src/shmakowiki.js +++ b/src/shmakowiki.js @@ -3,3 +3,4 @@ var ometajs = require('ometajs'), ohl = require('ometa-highlighter'), OmetaHighlighter = ohl.OmetaHighlighter, OmetaHighlighterToHtml = ohl.OmetaHighlighterToHtml; + OmetaHighlighterToBemjson = ohl.OmetaHighlighterToBemjson; diff --git a/src/shmakowiki.ometajs b/src/shmakowiki.ometajs index 1ae1361..9e16e97 100644 --- a/src/shmakowiki.ometajs +++ b/src/shmakowiki.ometajs @@ -116,8 +116,8 @@ ometa ShmakoWiki { ShmakoWiki.extentions = { 'ohl': function(c, p) { - return OmetaHighlighter.matchAll(c, p); - } + return OmetaHighlighter.matchAll(c, p); + } }; ShmakoWiki.extentions.hl = ShmakoWiki.extentions.ohl; diff --git a/src/shmakowiki2bemjson.ometajs b/src/shmakowiki2bemjson.ometajs index 4093561..1382170 100644 --- a/src/shmakowiki2bemjson.ometajs +++ b/src/shmakowiki2bemjson.ometajs @@ -72,13 +72,12 @@ ometa ShmakoWikiToBemjson { ShmakoWikiToBemjson.extentions = { 'html': function(c) { return c }, - 'ohl': function(c, p) { return OmetaHighlighterToHtml.match(c, 'topLevel') }, + 'ohl': function(c, p) { return OmetaHighlighterToBemjson.match(c, 'topLevel') }, 'hljs': function(c, p) { return { - tag: 'pre', - content: '' + - ShmakoWikiToBemjson._escape(c) + - '' + block: 'b-code', + cls: p, + content: ShmakoWikiToBemjson._escape(c) }; } }; diff --git a/src/shmakowiki2bemjson.ometajs.js b/src/shmakowiki2bemjson.ometajs.js index f6629ca..087c990 100644 --- a/src/shmakowiki2bemjson.ometajs.js +++ b/src/shmakowiki2bemjson.ometajs.js @@ -32,4 +32,4 @@ "olistItem":function(){var $elf=this,_fromIdx=this.input.idx,c;return (function(){c=this._apply("tokens");return ({"elem": "li","content": c})}).call(this)}, "ulistItem":function(){var $elf=this,_fromIdx=this.input.idx,c;return (function(){c=this._apply("tokens");return ({"elem": "li","content": c})}).call(this)}, "extention":function(){var $elf=this,_fromIdx=this.input.idx,t,c,p;return (function(){t=this._apply("anything");c=this._apply("anything");p=this._apply("anything");return (ShmakoWikiToBemjson["extentions"].hasOwnProperty(t)?ShmakoWikiToBemjson["extentions"][t](c,p):({"tag": "div","content": ShmakoWikiToBemjson._escape(c)}))}).call(this)}, -"topLevel":function(){var $elf=this,_fromIdx=this.input.idx,c;return (function(){c=this._apply("tokens");return ({"block": "b-text","content": c})}).call(this)}});(ShmakoWikiToBemjson["extentions"]=({"html": (function (c){return c}),"ohl": (function (c,p){return OmetaHighlighterToHtml.match(c,"topLevel")}),"hljs": (function (c,p){return ({"tag": "pre","content": (((("") + ShmakoWikiToBemjson._escape(c)) + "")})})}));(ShmakoWikiToBemjson["extentions"]["hl"]=ShmakoWikiToBemjson["extentions"]["ohl"]);(ShmakoWikiToBemjson["_escape"]=(function (){var amp = new RegExp("&","g"),lt = new RegExp("<","g"),gt = new RegExp(">","g"),apos = new RegExp("\'","g"),quot = new RegExp("\"","g");return (function (s){return String(s).replace(amp,"&").replace(lt,"<").replace(gt,">").replace(apos,"'").replace(quot,""")})})())} +"topLevel":function(){var $elf=this,_fromIdx=this.input.idx,c;return (function(){c=this._apply("tokens");return ({"block": "b-text","content": c})}).call(this)}});(ShmakoWikiToBemjson["extentions"]=({"html": (function (c){return c}),"ohl": (function (c,p){return OmetaHighlighterToBemjson.match(c,"topLevel")}),"hljs": (function (c,p){return ({"block": "b-code","cls": p,"content": ShmakoWikiToBemjson._escape(c)})})}));(ShmakoWikiToBemjson["extentions"]["hl"]=ShmakoWikiToBemjson["extentions"]["ohl"]);(ShmakoWikiToBemjson["_escape"]=(function (){var amp = new RegExp("&","g"),lt = new RegExp("<","g"),gt = new RegExp(">","g"),apos = new RegExp("\'","g"),quot = new RegExp("\"","g");return (function (s){return String(s).replace(amp,"&").replace(lt,"<").replace(gt,">").replace(apos,"'").replace(quot,""")})})())} From 86a8edcad763c7d0562d75775b80f99819d303ae Mon Sep 17 00:00:00 2001 From: Sergey Belov Date: Thu, 1 Sep 2011 15:58:50 +0400 Subject: [PATCH 5/7] Added shmakowiki utility, removed shmakowiki2html and shmakowiki2bemjson utilities --- bin/shmakowiki | 3 ++ bin/shmakowiki2bemjson | 3 -- bin/shmakowiki2html | 3 -- lib/2bemjson.js | 79 ----------------------------------- lib/2html.js | 79 ----------------------------------- lib/cli.js | 95 ++++++++++++++++++++++++++++++++++++++++++ package.json | 8 ++-- 7 files changed, 102 insertions(+), 168 deletions(-) create mode 100755 bin/shmakowiki delete mode 100755 bin/shmakowiki2bemjson delete mode 100755 bin/shmakowiki2html delete mode 100644 lib/2bemjson.js delete mode 100644 lib/2html.js create mode 100644 lib/cli.js diff --git a/bin/shmakowiki b/bin/shmakowiki new file mode 100755 index 0000000..f34b312 --- /dev/null +++ b/bin/shmakowiki @@ -0,0 +1,3 @@ +#!/usr/bin/env node + +require('../lib/cli').main(); diff --git a/bin/shmakowiki2bemjson b/bin/shmakowiki2bemjson deleted file mode 100755 index 85ba6c3..0000000 --- a/bin/shmakowiki2bemjson +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env node - -require('../lib/2bemjson').main(); diff --git a/bin/shmakowiki2html b/bin/shmakowiki2html deleted file mode 100755 index 090c9fd..0000000 --- a/bin/shmakowiki2html +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env node - -require('../lib/2html').main(); diff --git a/lib/2bemjson.js b/lib/2bemjson.js deleted file mode 100644 index b3fb672..0000000 --- a/lib/2bemjson.js +++ /dev/null @@ -1,79 +0,0 @@ -exports.main = function() { - - var sys = require('sys'), - fs = require('fs'), - args = process.argv.slice(2), - arg, - options = {}; - - while(args.length) { - arg = args.shift(); - switch (arg) { - case '-h': - case '--help': - sys.puts([ - 'Usage: shmakowiki2bemjson [options]', - '', - 'Options:', - ' -i, --input : pecifies filename to read the input source, if omit use STDIN', - ' -o, --output : specifies filename to write the output, if omit use STDOUT', - ' -v, --verbose : verbose output to STDERR', - ' -h, --help : Output help information' - ].join('\n')); - process.exit(1); - break; - case '-i': - case '--input': - options.input = args.shift(); - break; - case '-o': - case '--output': - options.output = args.shift(); - break; - case '-v': - case '--verbose': - options.verbose = true; - break; - } - } - - (options.input ? - // if input file - function(inputFn) { - fs.readFile(options.input, 'utf8', function(err, input){ - if (err) throw err; - inputFn(input); - }); - } : - // if STDIN - function(inputFn) { - var input = ''; - process.openStdin() - .on('data', function(s) { input += s }) - .on('end', function() { inputFn(input) }); - })(function(input){ - // remove BOM if present - if (input.charCodeAt(0) == 65279) input = input.slice(1); - try { - var shmakowiki = require('./shmakowiki'), - result = JSON.stringify(shmakowiki.ShmakoWikiToBemjson.match( - shmakowiki.ShmakoWiki.matchAll(input, 'topLevel'), - 'topLevel' - )) + '\n'; - options.output ? - fs.writeFile(options.output, result, 'utf8', function(err) { - if (err) throw err; - if (options.verbose) sys.error(' create : ' + options.output); - }) : - process.stdout.write(result); - } catch (e) { - e.errorPos != undefined && - sys.error( - input.slice(0, e.errorPos) + - "\n--- Parse error ->" + - input.slice(e.errorPos) + '\n'); - throw e - } - }); - -}; diff --git a/lib/2html.js b/lib/2html.js deleted file mode 100644 index f9384dd..0000000 --- a/lib/2html.js +++ /dev/null @@ -1,79 +0,0 @@ -exports.main = function() { - - var sys = require('sys'), - fs = require('fs'), - args = process.argv.slice(2), - arg, - options = {}; - - while(args.length) { - arg = args.shift(); - switch (arg) { - case '-h': - case '--help': - sys.puts([ - 'Usage: shmakowiki2html [options]', - '', - 'Options:', - ' -i, --input : pecifies filename to read the input source, if omit use STDIN', - ' -o, --output : specifies filename to write the output, if omit use STDOUT', - ' -v, --verbose : verbose output to STDERR', - ' -h, --help : Output help information' - ].join('\n')); - process.exit(1); - break; - case '-i': - case '--input': - options.input = args.shift(); - break; - case '-o': - case '--output': - options.output = args.shift(); - break; - case '-v': - case '--verbose': - options.verbose = true; - break; - } - } - - (options.input ? - // if input file - function(inputFn) { - fs.readFile(options.input, 'utf8', function(err, input){ - if (err) throw err; - inputFn(input); - }); - } : - // if STDIN - function(inputFn) { - var input = ''; - process.openStdin() - .on('data', function(s) { input += s }) - .on('end', function() { inputFn(input) }); - })(function(input){ - // remove BOM if present - if (input.charCodeAt(0) == 65279) input = input.slice(1); - try { - var shmakowiki = require('./shmakowiki'), - result = shmakowiki.ShmakoWikiToHtml.match( - shmakowiki.ShmakoWiki.matchAll(input, 'topLevel'), - 'topLevel' - ) + '\n'; - options.output ? - fs.writeFile(options.output, result, 'utf8', function(err) { - if (err) throw err; - if (options.verbose) sys.error(' create : ' + options.output); - }) : - process.stdout.write(result); - } catch (e) { - e.errorPos != undefined && - sys.error( - input.slice(0, e.errorPos) + - "\n--- Parse error ->" + - input.slice(e.errorPos) + '\n'); - throw e - } - }); - -}; diff --git a/lib/cli.js b/lib/cli.js new file mode 100644 index 0000000..a2c4216 --- /dev/null +++ b/lib/cli.js @@ -0,0 +1,95 @@ +exports.main = function () { + + var sys = require('sys'), + fs = require('fs'); + + require('coa').Cmd() + .name(process.argv[1]) + .title('Shmakowiki command line utility') + .helpful() + .opt() + .name('version') + .title('Show version') + .long('version') + .flag() + .act(function(opts) { + this.exit( + JSON.parse(require('fs').readFileSync(__dirname + '/../package.json')) + .version); + }) + .end() + .opt() + .name('input') + .title('Input file. Defaults to stdin') + .short('i') + .long('input') + .end() + .opt() + .name('output') + .title('Output file. Defaults to stdout') + .short('o') + .long('output') + .end() + .opt() + .name('format') + .title('Output format: html, bemjson. Defaults to html') + .short('f') + .long('format') + .def('html') + .val(function(value) { + // FIXME: don't use private API _usage() + !value && this.end().errorExit("Missing required option value\n" + this._usage()); + (['html', 'bemjson'].indexOf(value) == -1) && this.end() + .errorExit('Wrong output format "' + value + '" specified, must be one of "html" or "bemjson"'); + return value; + }) + .end() + .opt() + .name('verbose') + .title('Show verbose output') + .long('verbose') + .short('v') + .flag() + .end() + .act(function(opts) { + (opts.input ? + // if input file + function(inputFn) { + fs.readFile(opts.input, 'utf8', function(err, input){ + if (err) throw err; + inputFn(input); + }); + } : + // if STDIN + function(inputFn) { + var input = ''; + process.openStdin() + .on('data', function(s) { input += s }) + .on('end', function() { inputFn(input) }); + })(function(input){ + // remove BOM if present + if (input.charCodeAt(0) === 0xFEFF) input = input.slice(1); + try { + var shmakowiki = require('./shmakowiki'), + ast = shmakowiki.ShmakoWiki.matchAll(input, 'topLevel'), + result = (opts.format == 'html' ? + shmakowiki.ShmakoWikiToHtml.match(ast, 'topLevel') : + JSON.stringify(shmakowiki.ShmakoWikiToBemjson.match(ast, 'topLevel'), null, 4)) + '\n'; + opts.output ? + fs.writeFile(opts.output, result, 'utf8', function(err) { + if (err) throw err; + opts.verbose && sys.error(' create : ' + opts.output); + }) : + process.stdout.write(result); + } catch (e) { + e.errorPos != undefined && + sys.error( + input.slice(0, e.errorPos) + + "\n--- Parse error ->" + + input.slice(e.errorPos) + '\n'); + throw e; + } + }); + }) + .parse(process.argv.slice(2)); +}; diff --git a/package.json b/package.json index 2790bf7..3a2ee47 100644 --- a/package.json +++ b/package.json @@ -11,13 +11,13 @@ "main": "./lib/shmakowiki", "directories" : { "lib" : "./lib" }, "bin" : { - "shmakowiki2html" : "./bin/shmakowiki2html", - "shmakowiki2bemjson" : "./bin/shmakowiki2bemjson" + "shmakowiki" : "./bin/shmakowiki" }, "dependencies" : { "ometajs" : ">= 2.0.1", - "ometa-highlighter" : ">= 0.1.1" + "ometa-highlighter" : ">= 0.2.0", + "coa" : ">= 0.0.5" }, - "engines" : { "node" : ">=0.2.0" }, + "engines" : { "node" : ">=0.4.0" }, "licenses" : [ { "type" : "AS IS" } ] } From 99aed6978631dbbf575382f0cfb21f1918649f81 Mon Sep 17 00:00:00 2001 From: Sergey Belov Date: Thu, 1 Sep 2011 15:59:01 +0400 Subject: [PATCH 6/7] Version bump to 0.2.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 3a2ee47..cbd2340 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "shmakowiki", "description": "Yet another wiki dialect, inspired by WackoWiki and WikiCreole", - "version" : "0.1.4", + "version" : "0.2.0", "homepage": "http://github.com/veged/shmakowiki", "author" : "Sergey Berezhnoy (http://github.com/veged)", "repository" : { From c24123cee0139a743a221f570973bbb822dfe884 Mon Sep 17 00:00:00 2001 From: Sergey Belov Date: Thu, 1 Sep 2011 16:53:17 +0400 Subject: [PATCH 7/7] Added shmakowiki2html as an alias to shmakowiki --format html --- bin/shmakowiki2html | 3 +++ package.json | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100755 bin/shmakowiki2html diff --git a/bin/shmakowiki2html b/bin/shmakowiki2html new file mode 100755 index 0000000..c23b077 --- /dev/null +++ b/bin/shmakowiki2html @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +$(dirname $0)/shmakowiki --format html $* diff --git a/package.json b/package.json index cbd2340..65e621c 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,8 @@ "main": "./lib/shmakowiki", "directories" : { "lib" : "./lib" }, "bin" : { - "shmakowiki" : "./bin/shmakowiki" + "shmakowiki" : "./bin/shmakowiki", + "shmakowiki2html" : "./bin/shmakowiki2html" }, "dependencies" : { "ometajs" : ">= 2.0.1",