Permalink
Browse files

Merge pull request #11 from arikon/nodejs

Extensions as modules
  • Loading branch information...
2 parents 9d84227 + d267a98 commit fe92368d6e0e3f7dce8f697affd31f44cb7887a6 @arikon arikon committed Mar 12, 2012
View
2 .gitignore
@@ -1,2 +1,4 @@
+.idea/
+*.iml
node_modules
*.swp
View
1 GNUmakefile
@@ -13,6 +13,7 @@ lib/_shmakowiki.js: src
for i in \
shmakowiki.js \
shmakowiki.ometajs.js \
+ transform.ometajs.js \
shmakowiki2html.ometajs.js \
shmakowiki2bemjson.ometajs.js \
shmakowiki2plain.ometajs.js \
View
1,862 lib/_shmakowiki.js
@@ -1,10 +1,6 @@
var ometajs = require('ometajs'),
OMeta = ometajs.OMeta,
- ohl = require('ometa-highlighter'),
- utils = require('./utils.js'),
- OmetaHighlighter = ohl.OmetaHighlighter,
- OmetaHighlighterToHtml = ohl.OmetaHighlighterToHtml,
- OmetaHighlighterToBemjson = ohl.OmetaHighlighterToBemjson;
+ utils = require('./utils.js');
var ometajs_ = require('ometajs').globals || global;var StringBuffer = ometajs_.StringBuffer;
var objectThatDelegatesTo = ometajs_.objectThatDelegatesTo;
var isImmutable = ometajs_.isImmutable;
@@ -664,7 +660,7 @@ if (global === ometajs_) {
anchor = this._apply("headerAnchor");
this._apply("headerEnd");
return function() {
- var hAST = ShmakoWiki.matchAll(c, "topLevel"), hAnchor = utils.transliterate("ru", anchor["length"] ? anchor : ShmakoWikiToPlain.match(hAST, "topLevel"));
+ var hAST = ShmakoWiki.matchAll(c, "topInline"), hAnchor = utils.transliterate("ru", anchor["length"] ? anchor : ShmakoWikiToPlain.match(hAST, "topLevel"));
return [ "header" + (l <= 6 ? l : 6), hAST, hAnchor ];
}.call(this);
}.call(this);
@@ -956,7 +952,7 @@ if (global === ometajs_) {
}
}.call(this);
});
- return [ "extension", s[1], ShmakoWiki["extensions"].hasOwnProperty(s[1]) ? ShmakoWiki["extensions"][s[1]](c, s[2]) : c, s[2] ];
+ return [ "extension", s[1], utils.getExtension(s[1], "shmakowikiToAst")(c, s[2]), s[2] ];
}.call(this);
},
allBlock: function() {
@@ -976,21 +972,21 @@ if (global === ometajs_) {
});
},
topLevel: function() {
- var $elf = this, _fromIdx = this.input.idx;
- return this._many1(function() {
- return this._apply("allBlock");
- });
+ var $elf = this, _fromIdx = this.input.idx, t;
+ return function() {
+ this._many(function() {
+ return function() {
+ this._apply("spacesNoNl");
+ return this._applyWithArgs("exactly", "\n");
+ }.call(this);
+ });
+ t = this._many1(function() {
+ return this._apply("allBlock");
+ });
+ return t;
+ }.call(this);
}
});
- ShmakoWiki["extensions"] = {
- ohl: function(c, p) {
- return OmetaHighlighter.matchAll(c, p);
- },
- toc: function(c, p) {
- return ShmakoWiki.matchAll(c, "topLevel");
- }
- };
- ShmakoWiki["extensions"]["hl"] = ShmakoWiki["extensions"]["ohl"];
ShmakoWiki["arrJoin"] = function(arr1, arr2) {
var newArr = ShmakoWiki.arrCopy(arr1);
for (var i = 0; i < arr2["length"]; i++) {
@@ -1048,881 +1044,993 @@ if (global === ometajs_) {
return function() { return fail };
})(fail);
OMeta = require('ometajs').OMeta;
-}{
- var ShmakoWikiToHtml = exports.ShmakoWikiToHtml = objectThatDelegatesTo(OMeta, {
- keyword: function() {
- var $elf = this, _fromIdx = this.input.idx;
+}var Transform = exports.Transform = objectThatDelegatesTo(OMeta, {
+ keyword: function() {
+ var $elf = this, _fromIdx = this.input.idx;
+ return function() {
+ switch (this._apply("anything")) {
+ case "underline_":
+ return "underline_";
+ case "strike":
+ return "strike";
+ case "header4":
+ return "header4";
+ case "italic_":
+ return "italic_";
+ case "bold_":
+ return "bold_";
+ case "underline":
+ return "underline";
+ case "header5":
+ return "header5";
+ case "subscript":
+ return "subscript";
+ case "superscript":
+ return "superscript";
+ case "monospace_":
+ return "monospace_";
+ case "header6":
+ return "header6";
+ case "monospace":
+ return "monospace";
+ case "strike_":
+ return "strike_";
+ case "italic":
+ return "italic";
+ case "para":
+ return "para";
+ case "header1":
+ return "header1";
+ case "header2":
+ return "header2";
+ case "header3":
+ return "header3";
+ case "subscript_":
+ return "subscript_";
+ case "superscript_":
+ return "superscript_";
+ case "bold":
+ return "bold";
+ default:
+ throw fail();
+ }
+ }.call(this);
+ },
+ token: function() {
+ var $elf = this, _fromIdx = this.input.idx, t, ans, c;
+ return this._or(function() {
return function() {
- switch (this._apply("anything")) {
- case "monospace":
- return "monospace";
- case "strike":
- return "strike";
- case "header6":
- return "header6";
- case "header3":
- return "header3";
- case "para":
- return "para";
- case "italic":
- return "italic";
- case "underline_":
- return "underline_";
- case "header2":
- return "header2";
- case "header4":
- return "header4";
- case "italic_":
- return "italic_";
- case "underline":
- return "underline";
- case "header5":
- return "header5";
- case "strike_":
- return "strike_";
- case "link_":
- return "link_";
- case "subscript":
- return "subscript";
- case "escaped":
- return "escaped";
- case "superscript":
- return "superscript";
- case "ulistItem":
- return "ulistItem";
- case "olistItem":
- return "olistItem";
- case "header1":
- return "header1";
- case "subscript_":
- return "subscript_";
- case "bold_":
- return "bold_";
- case "monospace_":
- return "monospace_";
- case "olist":
- return "olist";
- case "ulist":
- return "ulist";
- case "lineBreak":
- return "lineBreak";
- case "superscript_":
- return "superscript_";
- case "link":
- return "link";
- case "extension":
- return "extension";
- case "bold":
- return "bold";
- default:
- throw fail();
- }
+ this._form(function() {
+ return function() {
+ t = this._apply("keyword");
+ return ans = this._apply("tokens");
+ }.call(this);
+ });
+ return [ t, ans ];
}.call(this);
- },
- token: function() {
- var $elf = this, _fromIdx = this.input.idx, t, ans, c;
- return this._or(function() {
+ }, function() {
+ return this._apply("escaped");
+ }, function() {
+ return this._apply("extension");
+ }, function() {
+ return c = this._apply("anything");
+ });
+ },
+ 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);
+ },
+ escaped: function() {
+ var $elf = this, _fromIdx = this.input.idx, t, c;
+ return function() {
+ this._form(function() {
return function() {
- this._form(function() {
- return function() {
- t = this._apply("keyword");
- return ans = this._applyWithArgs("apply", t);
- }.call(this);
- });
- return ans;
+ t = this._applyWithArgs("exactly", "escaped");
+ return c = this._apply("anything");
}.call(this);
- }, function() {
+ });
+ return [ t, c ];
+ }.call(this);
+ },
+ extension: function() {
+ var $elf = this, _fromIdx = this.input.idx, t, tt, c, p;
+ return function() {
+ this._form(function() {
return function() {
+ t = this._applyWithArgs("exactly", "extension");
+ tt = this._apply("anything");
c = this._apply("anything");
- return ShmakoWikiToHtml._escape(c);
+ return p = this._apply("anything");
}.call(this);
});
- },
- tokens: function() {
- var $elf = this, _fromIdx = this.input.idx, c;
+ return [ t, tt, utils.getExtension(tt, "transformAst")(c, p), p ];
+ }.call(this);
+ },
+ topLevel: function() {
+ var $elf = this, _fromIdx = this.input.idx, c;
+ return function() {
+ c = this._apply("tokens");
+ return c;
+ }.call(this);
+ }
+});var ometajs_ = require('ometajs').globals || global;var StringBuffer = ometajs_.StringBuffer;
+var objectThatDelegatesTo = ometajs_.objectThatDelegatesTo;
+var isImmutable = ometajs_.isImmutable;
+var digitValue = ometajs_.digitValue;
+var isSequenceable = ometajs_.isSequenceable;
+var escapeChar = ometajs_.escapeChar;
+var unescape = ometajs_.unescape;
+var getTag = ometajs_.getTag;
+var inspect = ometajs_.inspect;
+var lift = ometajs_.lift;
+var clone = ometajs_.clone;
+var Parser = ometajs_.Parser;
+var fail = ometajs_.fail;
+var OMeta = ometajs_.OMeta;
+var BSNullOptimization = ometajs_.BSNullOptimization;
+var BSAssociativeOptimization = ometajs_.BSAssociativeOptimization;
+var BSSeqInliner = ometajs_.BSSeqInliner;
+var BSJumpTableOptimization = ometajs_.BSJumpTableOptimization;
+var BSOMetaOptimizer = ometajs_.BSOMetaOptimizer;
+var BSOMetaParser = ometajs_.BSOMetaParser;
+var BSOMetaTranslator = ometajs_.BSOMetaTranslator;
+var BSJSParser = ometajs_.BSJSParser;
+var BSSemActionParser = ometajs_.BSSemActionParser;
+var BSJSIdentity = ometajs_.BSJSIdentity;
+var BSJSTranslator = ometajs_.BSJSTranslator;
+var BSOMetaJSParser = ometajs_.BSOMetaJSParser;
+var BSOMetaJSTranslator = ometajs_.BSOMetaJSTranslator;
+if (global === ometajs_) {
+ fail = (function(fail) {
+ return function() { return fail };
+ })(fail);
+ OMeta = require('ometajs').OMeta;
+}var ShmakoWikiToHtml = exports.ShmakoWikiToHtml = objectThatDelegatesTo(OMeta, {
+ keyword: function() {
+ var $elf = this, _fromIdx = this.input.idx;
+ return function() {
+ switch (this._apply("anything")) {
+ case "olistItem":
+ return "olistItem";
+ case "underline_":
+ return "underline_";
+ case "strike":
+ return "strike";
+ case "header4":
+ return "header4";
+ case "link_":
+ return "link_";
+ case "escaped":
+ return "escaped";
+ case "lineBreak":
+ return "lineBreak";
+ case "italic_":
+ return "italic_";
+ case "bold_":
+ return "bold_";
+ case "underline":
+ return "underline";
+ case "header5":
+ return "header5";
+ case "subscript":
+ return "subscript";
+ case "link":
+ return "link";
+ case "olist":
+ return "olist";
+ case "superscript":
+ return "superscript";
+ case "monospace_":
+ return "monospace_";
+ case "header6":
+ return "header6";
+ case "extension":
+ return "extension";
+ case "monospace":
+ return "monospace";
+ case "strike_":
+ return "strike_";
+ case "italic":
+ return "italic";
+ case "para":
+ return "para";
+ case "ulistItem":
+ return "ulistItem";
+ case "header2":
+ return "header2";
+ case "header1":
+ return "header1";
+ case "header3":
+ return "header3";
+ case "ulist":
+ return "ulist";
+ case "subscript_":
+ return "subscript_";
+ case "superscript_":
+ return "superscript_";
+ case "bold":
+ return "bold";
+ 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 c = this._many(function() {
- return this._apply("token");
- });
+ return function() {
+ t = this._apply("keyword");
+ return ans = this._applyWithArgs("apply", t);
+ }.call(this);
});
- return c.join("");
- }.call(this);
- },
- bold: function() {
- var $elf = this, _fromIdx = this.input.idx, c;
- return function() {
- c = this._apply("tokens");
- return "<b>" + c + "</b>";
- }.call(this);
- },
- bold_: function() {
- var $elf = this, _fromIdx = this.input.idx, c;
- return function() {
- c = this._apply("tokens");
- return "<b>" + c + "</b>";
- }.call(this);
- },
- italic: function() {
- var $elf = this, _fromIdx = this.input.idx, c;
- return function() {
- c = this._apply("tokens");
- return "<i>" + c + "</i>";
- }.call(this);
- },
- italic_: function() {
- var $elf = this, _fromIdx = this.input.idx, c;
- return function() {
- c = this._apply("tokens");
- return "<i>" + c + "</i>";
- }.call(this);
- },
- underline: function() {
- var $elf = this, _fromIdx = this.input.idx, c;
- return function() {
- c = this._apply("tokens");
- return "<u>" + c + "</u>";
- }.call(this);
- },
- underline_: function() {
- var $elf = this, _fromIdx = this.input.idx, c;
- return function() {
- c = this._apply("tokens");
- return "<u>" + c + "</u>";
- }.call(this);
- },
- strike: function() {
- var $elf = this, _fromIdx = this.input.idx, c;
- return function() {
- c = this._apply("tokens");
- return "<s>" + c + "</s>";
+ return ans;
}.call(this);
- },
- strike_: function() {
- var $elf = this, _fromIdx = this.input.idx, c;
+ }, function() {
return function() {
- c = this._apply("tokens");
- return "<s>" + c + "</s>";
+ c = this._apply("anything");
+ return utils.htmlEscape(c);
}.call(this);
- },
- monospace: function() {
- var $elf = this, _fromIdx = this.input.idx, c;
- return function() {
- c = this._apply("tokens");
- return "<tt>" + c + "</tt>";
- }.call(this);
- },
- monospace_: function() {
- var $elf = this, _fromIdx = this.input.idx, c;
- return function() {
- c = this._apply("tokens");
- return "<tt>" + c + "</tt>";
- }.call(this);
- },
- superscript: function() {
- var $elf = this, _fromIdx = this.input.idx, c;
- return function() {
- c = this._apply("tokens");
- return "<sup>" + c + "</sup>";
- }.call(this);
- },
- superscript_: function() {
- var $elf = this, _fromIdx = this.input.idx, c;
- return function() {
- c = this._apply("tokens");
- return "<sup>" + c + "</sup>";
- }.call(this);
- },
- subscript: function() {
- var $elf = this, _fromIdx = this.input.idx, c;
- return function() {
- c = this._apply("tokens");
- return "<sub>" + c + "</sub>";
- }.call(this);
- },
- subscript_: function() {
- var $elf = this, _fromIdx = this.input.idx, c;
- return function() {
- c = this._apply("tokens");
- return "<sub>" + c + "</sub>";
- }.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 '<a href="' + c + '">' + c + "</a>";
- }.call(this);
- }, function() {
- return function() {
- c = this._apply("token");
- cc = this._apply("tokens");
- return '<a href="' + c + '">' + cc + "</a>";
- }.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");
+ });
});
- },
- link_: function() {
- var $elf = this, _fromIdx = this.input.idx, c;
+ return c.join("");
+ }.call(this);
+ },
+ bold: function() {
+ var $elf = this, _fromIdx = this.input.idx, c;
+ return function() {
+ c = this._apply("tokens");
+ return "<b>" + c + "</b>";
+ }.call(this);
+ },
+ bold_: function() {
+ var $elf = this, _fromIdx = this.input.idx, c;
+ return function() {
+ c = this._apply("tokens");
+ return "<b>" + c + "</b>";
+ }.call(this);
+ },
+ italic: function() {
+ var $elf = this, _fromIdx = this.input.idx, c;
+ return function() {
+ c = this._apply("tokens");
+ return "<i>" + c + "</i>";
+ }.call(this);
+ },
+ italic_: function() {
+ var $elf = this, _fromIdx = this.input.idx, c;
+ return function() {
+ c = this._apply("tokens");
+ return "<i>" + c + "</i>";
+ }.call(this);
+ },
+ underline: function() {
+ var $elf = this, _fromIdx = this.input.idx, c;
+ return function() {
+ c = this._apply("tokens");
+ return "<u>" + c + "</u>";
+ }.call(this);
+ },
+ underline_: function() {
+ var $elf = this, _fromIdx = this.input.idx, c;
+ return function() {
+ c = this._apply("tokens");
+ return "<u>" + c + "</u>";
+ }.call(this);
+ },
+ strike: function() {
+ var $elf = this, _fromIdx = this.input.idx, c;
+ return function() {
+ c = this._apply("tokens");
+ return "<s>" + c + "</s>";
+ }.call(this);
+ },
+ strike_: function() {
+ var $elf = this, _fromIdx = this.input.idx, c;
+ return function() {
+ c = this._apply("tokens");
+ return "<s>" + c + "</s>";
+ }.call(this);
+ },
+ monospace: function() {
+ var $elf = this, _fromIdx = this.input.idx, c;
+ return function() {
+ c = this._apply("tokens");
+ return "<tt>" + c + "</tt>";
+ }.call(this);
+ },
+ monospace_: function() {
+ var $elf = this, _fromIdx = this.input.idx, c;
+ return function() {
+ c = this._apply("tokens");
+ return "<tt>" + c + "</tt>";
+ }.call(this);
+ },
+ superscript: function() {
+ var $elf = this, _fromIdx = this.input.idx, c;
+ return function() {
+ c = this._apply("tokens");
+ return "<sup>" + c + "</sup>";
+ }.call(this);
+ },
+ superscript_: function() {
+ var $elf = this, _fromIdx = this.input.idx, c;
+ return function() {
+ c = this._apply("tokens");
+ return "<sup>" + c + "</sup>";
+ }.call(this);
+ },
+ subscript: function() {
+ var $elf = this, _fromIdx = this.input.idx, c;
+ return function() {
+ c = this._apply("tokens");
+ return "<sub>" + c + "</sub>";
+ }.call(this);
+ },
+ subscript_: function() {
+ var $elf = this, _fromIdx = this.input.idx, c;
+ return function() {
+ c = this._apply("tokens");
+ return "<sub>" + c + "</sub>";
+ }.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 '<a href="' + c + '">' + c + "</a>";
}.call(this);
- },
- lineBreak: function() {
- var $elf = this, _fromIdx = this.input.idx, c;
- return function() {
- c = this._apply("anything");
- return "<br/>";
- }.call(this);
- },
- escaped: function() {
- var $elf = this, _fromIdx = this.input.idx, c;
- return function() {
- c = this._apply("tokens");
- return "<span>" + c + "</span>";
- }.call(this);
- },
- para: function() {
- var $elf = this, _fromIdx = this.input.idx, c;
- return function() {
- c = this._apply("tokens");
- return "<p>" + c + "</p>";
- }.call(this);
- },
- header1: function() {
- var $elf = this, _fromIdx = this.input.idx, c, a;
- return function() {
- c = this._apply("tokens");
- a = this._apply("anything");
- return '<h1 id="' + a + '">' + c + "</h1>";
- }.call(this);
- },
- header2: function() {
- var $elf = this, _fromIdx = this.input.idx, c, a;
- return function() {
- c = this._apply("tokens");
- a = this._apply("anything");
- return '<h2 id="' + a + '">' + c + "</h2>";
- }.call(this);
- },
- header3: function() {
- var $elf = this, _fromIdx = this.input.idx, c, a;
- return function() {
- c = this._apply("tokens");
- a = this._apply("anything");
- return '<h3 id="' + a + '">' + c + "</h3>";
- }.call(this);
- },
- header4: function() {
- var $elf = this, _fromIdx = this.input.idx, c, a;
- return function() {
- c = this._apply("tokens");
- a = this._apply("anything");
- return '<h4 id="' + a + '">' + c + "</h4>";
- }.call(this);
- },
- header5: function() {
- var $elf = this, _fromIdx = this.input.idx, c, a;
- return function() {
- c = this._apply("tokens");
- a = this._apply("anything");
- return '<h5 id="' + a + '">' + c + "</h5>";
- }.call(this);
- },
- header6: function() {
- var $elf = this, _fromIdx = this.input.idx, c, a;
- return function() {
- c = this._apply("tokens");
- a = this._apply("anything");
- return '<h6 id="' + a + '">' + c + "</h6>";
- }.call(this);
- },
- olist: function() {
- var $elf = this, _fromIdx = this.input.idx, c;
- return function() {
- c = this._apply("tokens");
- return "<ol>" + c + "</ol>";
- }.call(this);
- },
- ulist: function() {
- var $elf = this, _fromIdx = this.input.idx, c;
- return function() {
- c = this._apply("tokens");
- return "<ul>" + c + "</ul>";
- }.call(this);
- },
- olistItem: function() {
- var $elf = this, _fromIdx = this.input.idx, c;
- return function() {
- c = this._apply("tokens");
- return "<li>" + c + "</li>";
- }.call(this);
- },
- ulistItem: function() {
- var $elf = this, _fromIdx = this.input.idx, c;
- return function() {
- c = this._apply("tokens");
- return "<li>" + c + "</li>";
- }.call(this);
- },
- extension: 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["extensions"].hasOwnProperty(t) ? ShmakoWikiToHtml["extensions"][t](c, p) : "<div>" + ShmakoWikiToHtml._escape(c) + "</div>";
- }.call(this);
- },
- topLevel: function() {
- var $elf = this, _fromIdx = this.input.idx, c;
- return function() {
- c = this._apply("tokens");
- return '<div class="shmakowiki">' + c + "</div>";
- }.call(this);
- }
- });
- ShmakoWikiToHtml["extensions"] = {
- html: function(c) {
- return c;
- },
- ohl: function(c, p) {
- return OmetaHighlighterToHtml.match(c, "topLevel");
- },
- hljs: function(c, p) {
- return '<pre><code class="' + p + '">' + ShmakoWikiToHtml._escape(c) + "</code></pre>";
- },
- toc: function(c, p) {
- return ShmakoWikiToHtml.match([ c[0] ], "topLevel") + ShmakoWikiToHtml.match(c[1], "topLevel");
- }
- };
- ShmakoWikiToHtml["extensions"]["hl"] = ShmakoWikiToHtml["extensions"]["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, "&amp;").replace(lt, "&lt;").replace(gt, "&gt;").replace(apos, "&apos;").replace(quot, "&quot;");
- };
- }();
-}var ometajs_ = require('ometajs').globals || global;var StringBuffer = ometajs_.StringBuffer;
-var objectThatDelegatesTo = ometajs_.objectThatDelegatesTo;
-var isImmutable = ometajs_.isImmutable;
-var digitValue = ometajs_.digitValue;
-var isSequenceable = ometajs_.isSequenceable;
-var escapeChar = ometajs_.escapeChar;
-var unescape = ometajs_.unescape;
-var getTag = ometajs_.getTag;
-var inspect = ometajs_.inspect;
-var lift = ometajs_.lift;
-var clone = ometajs_.clone;
-var Parser = ometajs_.Parser;
-var fail = ometajs_.fail;
-var OMeta = ometajs_.OMeta;
-var BSNullOptimization = ometajs_.BSNullOptimization;
-var BSAssociativeOptimization = ometajs_.BSAssociativeOptimization;
-var BSSeqInliner = ometajs_.BSSeqInliner;
-var BSJumpTableOptimization = ometajs_.BSJumpTableOptimization;
-var BSOMetaOptimizer = ometajs_.BSOMetaOptimizer;
-var BSOMetaParser = ometajs_.BSOMetaParser;
-var BSOMetaTranslator = ometajs_.BSOMetaTranslator;
-var BSJSParser = ometajs_.BSJSParser;
-var BSSemActionParser = ometajs_.BSSemActionParser;
-var BSJSIdentity = ometajs_.BSJSIdentity;
-var BSJSTranslator = ometajs_.BSJSTranslator;
-var BSOMetaJSParser = ometajs_.BSOMetaJSParser;
-var BSOMetaJSTranslator = ometajs_.BSOMetaJSTranslator;
-if (global === ometajs_) {
- fail = (function(fail) {
- return function() { return fail };
- })(fail);
- OMeta = require('ometajs').OMeta;
-}{
- var ShmakoWikiToBemjson = exports.ShmakoWikiToBemjson = objectThatDelegatesTo(OMeta, {
- keyword: function() {
- var $elf = this, _fromIdx = this.input.idx;
+ }, function() {
return function() {
- switch (this._apply("anything")) {
- case "monospace":
- return "monospace";
- case "strike":
- return "strike";
- case "header6":
- return "header6";
- case "header3":
- return "header3";
- case "para":
- return "para";
- case "italic":
- return "italic";
- case "underline_":
- return "underline_";
- case "header2":
- return "header2";
- case "header4":
- return "header4";
- case "italic_":
- return "italic_";
- case "underline":
- return "underline";
- case "header5":
- return "header5";
- case "strike_":
- return "strike_";
- case "link_":
- return "link_";
- case "subscript":
- return "subscript";
- case "escaped":
- return "escaped";
- case "superscript":
- return "superscript";
- case "ulistItem":
- return "ulistItem";
- case "olistItem":
- return "olistItem";
- case "header1":
- return "header1";
- case "subscript_":
- return "subscript_";
- case "bold_":
- return "bold_";
- case "monospace_":
- return "monospace_";
- case "olist":
- return "olist";
- case "ulist":
- return "ulist";
- case "lineBreak":
- return "lineBreak";
- case "superscript_":
- return "superscript_";
- case "link":
- return "link";
- case "extension":
- return "extension";
- case "bold":
- return "bold";
- default:
- throw fail();
- }
+ c = this._apply("token");
+ cc = this._apply("tokens");
+ return '<a href="' + c + '">' + cc + "</a>";
}.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;
+ });
+ },
+ link_: function() {
+ var $elf = this, _fromIdx = this.input.idx, c;
+ return function() {
+ c = this._apply("token");
+ return '<a href="' + c + '">' + c + "</a>";
+ }.call(this);
+ },
+ lineBreak: function() {
+ var $elf = this, _fromIdx = this.input.idx, c;
+ return function() {
+ c = this._apply("anything");
+ return "<br/>";
+ }.call(this);
+ },
+ escaped: function() {
+ var $elf = this, _fromIdx = this.input.idx, c;
+ return function() {
+ c = this._apply("tokens");
+ return "<span>" + c + "</span>";
+ }.call(this);
+ },
+ para: function() {
+ var $elf = this, _fromIdx = this.input.idx, c;
+ return function() {
+ c = this._apply("tokens");
+ return "<p>" + c + "</p>";
+ }.call(this);
+ },
+ header1: function() {
+ var $elf = this, _fromIdx = this.input.idx, c, a;
+ return function() {
+ c = this._apply("tokens");
+ a = this._apply("anything");
+ return '<h1 id="' + a + '">' + c + "</h1>";
+ }.call(this);
+ },
+ header2: function() {
+ var $elf = this, _fromIdx = this.input.idx, c, a;
+ return function() {
+ c = this._apply("tokens");
+ a = this._apply("anything");
+ return '<h2 id="' + a + '">' + c + "</h2>";
+ }.call(this);
+ },
+ header3: function() {
+ var $elf = this, _fromIdx = this.input.idx, c, a;
+ return function() {
+ c = this._apply("tokens");
+ a = this._apply("anything");
+ return '<h3 id="' + a + '">' + c + "</h3>";
+ }.call(this);
+ },
+ header4: function() {
+ var $elf = this, _fromIdx = this.input.idx, c, a;
+ return function() {
+ c = this._apply("tokens");
+ a = this._apply("anything");
+ return '<h4 id="' + a + '">' + c + "</h4>";
+ }.call(this);
+ },
+ header5: function() {
+ var $elf = this, _fromIdx = this.input.idx, c, a;
+ return function() {
+ c = this._apply("tokens");
+ a = this._apply("anything");
+ return '<h5 id="' + a + '">' + c + "</h5>";
+ }.call(this);
+ },
+ header6: function() {
+ var $elf = this, _fromIdx = this.input.idx, c, a;
+ return function() {
+ c = this._apply("tokens");
+ a = this._apply("anything");
+ return '<h6 id="' + a + '">' + c + "</h6>";
+ }.call(this);
+ },
+ olist: function() {
+ var $elf = this, _fromIdx = this.input.idx, c;
+ return function() {
+ c = this._apply("tokens");
+ return "<ol>" + c + "</ol>";
+ }.call(this);
+ },
+ ulist: function() {
+ var $elf = this, _fromIdx = this.input.idx, c;
+ return function() {
+ c = this._apply("tokens");
+ return "<ul>" + c + "</ul>";
+ }.call(this);
+ },
+ olistItem: function() {
+ var $elf = this, _fromIdx = this.input.idx, c;
+ return function() {
+ c = this._apply("tokens");
+ return "<li>" + c + "</li>";
+ }.call(this);
+ },
+ ulistItem: function() {
+ var $elf = this, _fromIdx = this.input.idx, c;
+ return function() {
+ c = this._apply("tokens");
+ return "<li>" + c + "</li>";
+ }.call(this);
+ },
+ extension: 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 utils.getExtension(t, "astToHtml", function(c, p) {
+ return "<div>" + utils.htmlEscape(c) + "</div>";
+ })(c, p);
+ }.call(this);
+ },
+ topInline: function() {
+ var $elf = this, _fromIdx = this.input.idx, c;
+ return function() {
+ c = this._apply("tokens");
+ return c;
+ }.call(this);
+ },
+ topLevel: function() {
+ var $elf = this, _fromIdx = this.input.idx, c;
+ return function() {
+ c = this._apply("tokens");
+ return '<div class="shmakowiki">' + c + "</div>";
+ }.call(this);
+ }
+});var ometajs_ = require('ometajs').globals || global;var StringBuffer = ometajs_.StringBuffer;
+var objectThatDelegatesTo = ometajs_.objectThatDelegatesTo;
+var isImmutable = ometajs_.isImmutable;
+var digitValue = ometajs_.digitValue;
+var isSequenceable = ometajs_.isSequenceable;
+var escapeChar = ometajs_.escapeChar;
+var unescape = ometajs_.unescape;
+var getTag = ometajs_.getTag;
+var inspect = ometajs_.inspect;
+var lift = ometajs_.lift;
+var clone = ometajs_.clone;
+var Parser = ometajs_.Parser;
+var fail = ometajs_.fail;
+var OMeta = ometajs_.OMeta;
+var BSNullOptimization = ometajs_.BSNullOptimization;
+var BSAssociativeOptimization = ometajs_.BSAssociativeOptimization;
+var BSSeqInliner = ometajs_.BSSeqInliner;
+var BSJumpTableOptimization = ometajs_.BSJumpTableOptimization;
+var BSOMetaOptimizer = ometajs_.BSOMetaOptimizer;
+var BSOMetaParser = ometajs_.BSOMetaParser;
+var BSOMetaTranslator = ometajs_.BSOMetaTranslator;
+var BSJSParser = ometajs_.BSJSParser;
+var BSSemActionParser = ometajs_.BSSemActionParser;
+var BSJSIdentity = ometajs_.BSJSIdentity;
+var BSJSTranslator = ometajs_.BSJSTranslator;
+var BSOMetaJSParser = ometajs_.BSOMetaJSParser;
+var BSOMetaJSTranslator = ometajs_.BSOMetaJSTranslator;
+if (global === ometajs_) {
+ fail = (function(fail) {
+ return function() { return fail };
+ })(fail);
+ OMeta = require('ometajs').OMeta;
+}var ShmakoWikiToBemjson = exports.ShmakoWikiToBemjson = objectThatDelegatesTo(OMeta, {
+ keyword: function() {
+ var $elf = this, _fromIdx = this.input.idx;
+ return function() {
+ switch (this._apply("anything")) {
+ case "olistItem":
+ return "olistItem";
+ case "underline_":
+ return "underline_";
+ case "strike":
+ return "strike";
+ case "header4":
+ return "header4";
+ case "link_":
+ return "link_";
+ case "escaped":
+ return "escaped";
+ case "lineBreak":
+ return "lineBreak";
+ case "italic_":
+ return "italic_";
+ case "bold_":
+ return "bold_";
+ case "underline":
+ return "underline";
+ case "header5":
+ return "header5";
+ case "subscript":
+ return "subscript";
+ case "link":
+ return "link";
+ case "olist":
+ return "olist";
+ case "superscript":
+ return "superscript";
+ case "monospace_":
+ return "monospace_";
+ case "header6":
+ return "header6";
+ case "extension":
+ return "extension";
+ case "monospace":
+ return "monospace";
+ case "strike_":
+ return "strike_";
+ case "italic":
+ return "italic";
+ case "para":
+ return "para";
+ case "ulistItem":
+ return "ulistItem";
+ case "header2":
+ return "header2";
+ case "header1":
+ return "header1";
+ case "header3":
+ return "header3";
+ case "ulist":
+ return "ulist";
+ case "subscript_":
+ return "subscript_";
+ case "superscript_":
+ return "superscript_";
+ case "bold":
+ return "bold";
+ 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 c = this._many(function() {
- return this._apply("token");
- });
+ return function() {
+ t = this._apply("keyword");
+ return ans = this._applyWithArgs("apply", t);
+ }.call(this);
});
- 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
- };
+ return ans;
}.call(this);
- },
- lineBreak: function() {
- var $elf = this, _fromIdx = this.input.idx, c;
+ }, function() {
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, a;
- return function() {
- c = this._apply("tokens");
- a = this._apply("anything");
- return {
- elem: "h1",
- attrs: {
- id: a
- },
- content: c
- };
+ return utils.htmlEscape(c);
}.call(this);
- },
- header2: function() {
- var $elf = this, _fromIdx = this.input.idx, c, a;
- return function() {
- c = this._apply("tokens");
- a = this._apply("anything");
- return {
- elem: "h2",
- attrs: {
- id: a
- },
- content: c
- };
- }.call(this);
- },
- header3: function() {
- var $elf = this, _fromIdx = this.input.idx, c, a;
- return function() {
- c = this._apply("tokens");
- a = this._apply("anything");
- return {
- elem: "h3",
- attrs: {
- id: a
- },
- content: c
- };
- }.call(this);
- },
- header4: function() {
- var $elf = this, _fromIdx = this.input.idx, c, a;
- return function() {
- c = this._apply("tokens");
- a = this._apply("anything");
- return {
- elem: "h4",
- attrs: {
- id: a
- },
- content: c
- };
- }.call(this);
- },
- header5: function() {
- var $elf = this, _fromIdx = this.input.idx, c, a;
- return function() {
- c = this._apply("tokens");
- a = this._apply("anything");
- return {
- elem: "h5",
- attrs: {
- id: a
- },
- content: c
- };
- }.call(this);
- },
- header6: function() {
- var $elf = this, _fromIdx = this.input.idx, c, a;
- return function() {
- c = this._apply("tokens");
- a = this._apply("anything");
- return {
- elem: "h6",
- attrs: {
- id: a
- },
- 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;
+ });
+ },
+ 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("tokens");
+ c = this._apply("token");
+ this._form(function() {
+ return undefined;
+ });
return {
- elem: "ul",
+ block: "b-link",
+ url: c,
content: c
};
}.call(this);
- },
- olistItem: function() {
- var $elf = this, _fromIdx = this.input.idx, c;
+ }, function() {
return function() {
- c = this._apply("tokens");
+ c = this._apply("token");
+ cc = this._apply("tokens");
return {
- elem: "li",
- content: c
+ block: "b-link",
+ url: c,
+ content: cc
};
}.call(this);
- },
- ulistItem: function() {
- var $elf = this, _fromIdx = this.input.idx, c;
- return function() {
- c = this._apply("tokens");
+ });
+ },
+ 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, a;
+ return function() {
+ c = this._apply("tokens");
+ a = this._apply("anything");
+ return {
+ elem: "h1",
+ attrs: {
+ id: a
+ },
+ content: c
+ };
+ }.call(this);
+ },
+ header2: function() {
+ var $elf = this, _fromIdx = this.input.idx, c, a;
+ return function() {
+ c = this._apply("tokens");
+ a = this._apply("anything");
+ return {
+ elem: "h2",
+ attrs: {
+ id: a
+ },
+ content: c
+ };
+ }.call(this);
+ },
+ header3: function() {
+ var $elf = this, _fromIdx = this.input.idx, c, a;
+ return function() {
+ c = this._apply("tokens");
+ a = this._apply("anything");
+ return {
+ elem: "h3",
+ attrs: {
+ id: a
+ },
+ content: c
+ };
+ }.call(this);
+ },
+ header4: function() {
+ var $elf = this, _fromIdx = this.input.idx, c, a;
+ return function() {
+ c = this._apply("tokens");
+ a = this._apply("anything");
+ return {
+ elem: "h4",
+ attrs: {
+ id: a
+ },
+ content: c
+ };
+ }.call(this);
+ },
+ header5: function() {
+ var $elf = this, _fromIdx = this.input.idx, c, a;
+ return function() {
+ c = this._apply("tokens");
+ a = this._apply("anything");
+ return {
+ elem: "h5",
+ attrs: {
+ id: a
+ },
+ content: c
+ };
+ }.call(this);
+ },
+ header6: function() {
+ var $elf = this, _fromIdx = this.input.idx, c, a;
+ return function() {
+ c = this._apply("tokens");
+ a = this._apply("anything");
+ return {
+ elem: "h6",
+ attrs: {
+ id: a
+ },
+ 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);
+ },
+ extension: 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 utils.getExtension(t, "astToBemjson", function(c, p) {
return {
- elem: "li",
- content: c
- };
- }.call(this);
- },
- extension: 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["extensions"].hasOwnProperty(t) ? ShmakoWikiToBemjson["extensions"][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
+ content: utils.htmlEscape(c)
};
- }.call(this);
- }
- });
- ShmakoWikiToBemjson["extensions"] = {
- html: function(c) {
+ })(c, p);
+ }.call(this);
+ },
+ topInline: function() {
+ var $elf = this, _fromIdx = this.input.idx, c;
+ return function() {
+ c = this._apply("tokens");
return c;
- },
- ohl: function(c, p) {
- return OmetaHighlighterToBemjson.match(c, "topLevel");
- },
- hljs: function(c, p) {
+ }.call(this);
+ },
+ topLevel: function() {
+ var $elf = this, _fromIdx = this.input.idx, c;
+ return function() {
+ c = this._apply("tokens");
return {
- block: "b-code",
- cls: p,
- content: ShmakoWikiToBemjson._escape(c)
+ block: "b-text",
+ content: c
};
- },
- toc: function(c, p) {
- return [ {
- block: "b-wiki",
- elem: "toc",
- content: ShmakoWikiToBemjson.match([ c[0] ], "topLevel")["content"]
- }, ShmakoWikiToBemjson.match(c[1], "topLevel") ];
- }
- };
- ShmakoWikiToBemjson["extensions"]["hl"] = ShmakoWikiToBemjson["extensions"]["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, "&amp;").replace(lt, "&lt;").replace(gt, "&gt;").replace(apos, "&apos;").replace(quot, "&quot;");
- };
- }();
-}var ometajs_ = require('ometajs').globals || global;var StringBuffer = ometajs_.StringBuffer;
+ }.call(this);
+ }
+});var ometajs_ = require('ometajs').globals || global;var StringBuffer = ometajs_.StringBuffer;
var objectThatDelegatesTo = ometajs_.objectThatDelegatesTo;
var isImmutable = ometajs_.isImmutable;
var digitValue = ometajs_.digitValue;
@@ -1959,46 +2067,46 @@ if (global === ometajs_) {
var $elf = this, _fromIdx = this.input.idx;
return function() {
switch (this._apply("anything")) {
- case "monospace":
- return "monospace";
- case "strike":
- return "strike";
- case "underline":
- return "underline";
- case "header3":
- return "header3";
- case "para":
- return "para";
- case "italic":
- return "italic";
case "underline_":
return "underline_";
- case "header6":
- return "header6";
+ case "strike":
+ return "strike";
case "header4":
return "header4";
+ case "escaped":
+ return "escaped";
case "italic_":
return "italic_";
- case "strike_":
- return "strike_";
+ case "bold_":
+ return "bold_";
+ case "underline":
+ return "underline";
case "header5":
return "header5";
- case "escaped":
- return "escaped";
- case "header2":
- return "header2";
case "subscript":
return "subscript";
case "superscript":
return "superscript";
+ case "monospace_":
+ return "monospace_";
+ case "header6":
+ return "header6";
+ case "monospace":
+ return "monospace";
+ case "strike_":
+ return "strike_";
+ case "italic":
+ return "italic";
+ case "para":
+ return "para";
case "header1":
return "header1";
+ case "header2":
+ return "header2";
+ case "header3":
+ return "header3";
case "subscript_":
return "subscript_";
- case "bold_":
- return "bold_";
- case "monospace_":
- return "monospace_";
case "superscript_":
return "superscript_";
case "bold":
@@ -2199,4 +2307,4 @@ if (global === ometajs_) {
return c.join("");
}.call(this);
}
-});
+});
View
6 lib/cli.js
@@ -1,7 +1,6 @@
exports.main = function () {
var util = require('util'),
- fs = require('fs'),
q = require('q');
require('coa').Cmd()
@@ -68,10 +67,9 @@ exports.main = function () {
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';
+ shmakowiki.shmakowikiToHtml(input) :
+ JSON.stringify(shmakowiki.shmakowikiToBemjson(input), null, 4)) + '\n';
opts.output.write(result);
if (opts.output != process.stdout) opts.output.end();
opts.verbose && util.error(' create : ' + opts.output);
View
1 lib/extensions/hl.js
@@ -0,0 +1 @@
+module.exports = require('./ohl');
View
15 lib/extensions/hljs.js
@@ -0,0 +1,15 @@
+var utils = require('../utils');
+
+exports.astToBemjson = function(c, p) {
+ return {
+ block: 'b-code',
+ cls: p,
+ content: utils.htmlEscape(c)
+ };
+};
+
+exports.astToHtml = function(c, p) {
+ return '<pre><code class="'+ p + '">' +
+ utils.htmlEscape(c) +
+ '</code></pre>';
+};
View
3 lib/extensions/html.js
@@ -0,0 +1,3 @@
+exports.astToBemjson = exports.astToHtml = function(c, p) {
+ return c;
+};
View
16 lib/extensions/ohl.js
@@ -0,0 +1,16 @@
+var ohl = require('ometa-highlighter'),
+ OmetaHighlighter = ohl.OmetaHighlighter,
+ OmetaHighlighterToHtml = ohl.OmetaHighlighterToHtml,
+ OmetaHighlighterToBemjson = ohl.OmetaHighlighterToBemjson;
+
+exports.shmakowikiToAst = function(c, p) {
+ return OmetaHighlighter.matchAll(c, p);
+};
+
+exports.astToBemjson = function(c, p) {
+ return OmetaHighlighterToBemjson.match(c, 'topLevel');
+};
+
+exports.astToHtml = function(c, p) {
+ return OmetaHighlighterToHtml.match(c, 'topLevel');
+};
View
9 lib/extensions/shmakowiki-toc/lib/shmakowikitoc.js
@@ -1,9 +0,0 @@
-var shmakowikitoc = require('./_shmakowikitoc.js');
-
-exports.transform = function(ast) {
- return shmakowikitoc.ShmakoWikiToc.transform(ast);
-};
-
-exports.match = function(ast, level) {
- return shmakowikitoc.ShmakoWikiToc.match(ast, level);
-};
View
1 lib/extensions/shmakowiki-toc/src/shmakowikitoc.js
@@ -1 +0,0 @@
-var api = require('../../../shmakowiki.js');
View
0 lib/extensions/shmakowiki-toc/GNUmakefile → lib/extensions/toc/GNUmakefile
File renamed without changes.
View
1 lib/extensions/toc/index.js
@@ -0,0 +1 @@
+module.exports = require('./lib/shmakowikitoc');
View
89 ...ions/shmakowiki-toc/lib/_shmakowikitoc.js → lib/extensions/toc/lib/_shmakowikitoc.js
@@ -25,11 +25,20 @@ var TocToList = {
convert: function(headers) {
var levels = { 1: this.createUl() },
- h, n, prev = 1;
+ i, h, n, prev = 1,
+ minLevel = 6,
+ shift = 0;
- for (var i = 0; i < headers.length; i++) {
+ for (i = 0; i < headers.length; i++) {
+ n = this.getLevelNumber(headers[i][0]);
+ if (n < minLevel) minLevel = n;
+ }
+
+ shift = minLevel <