Permalink
Browse files

Merge pull request #19 from veged/highlight.js

Use highlight.js for the code highlighting
  • Loading branch information...
2 parents fdef0b8 + 37c28e0 commit 18c0e35720d6d383a20aa741813d60f42a53317c @arikon arikon committed Oct 12, 2012
View
2 GNUmakefile
@@ -4,7 +4,7 @@ all: lib
src: $(patsubst %.ometajs,%.ometajs.js,$(wildcard src/*.ometajs))
%.ometajs.js: %.ometajs
- ometajs2js -i $< -o $@
+ ./node_modules/.bin/ometajs2js -i $< -o $@
lib: lib/_shmakowiki.js
View
549 lib/_shmakowiki.js
@@ -146,16 +146,16 @@ if (global === ometajs_) {
var $elf = this, _fromIdx = this.input.idx;
return function() {
switch (this._apply("anything")) {
- case "[":
- return function() {
- this._applyWithArgs("exactly", "[");
- return "[[";
- }.call(this);
case "(":
return function() {
this._applyWithArgs("exactly", "(");
return "((";
}.call(this);
+ case "[":
+ return function() {
+ this._applyWithArgs("exactly", "[");
+ return "[[";
+ }.call(this);
default:
throw fail();
}
@@ -550,15 +550,19 @@ if (global === ometajs_) {
return this._applyWithArgs("allInline", []);
});
},
+ noNlSpace: function() {
+ var $elf = this, _fromIdx = this.input.idx;
+ return function() {
+ this._not(function() {
+ return this._applyWithArgs("exactly", "\n");
+ });
+ return this._apply("space");
+ }.call(this);
+ },
spacesNoNl: function() {
var $elf = this, _fromIdx = this.input.idx;
return this._many(function() {
- return function() {
- this._not(function() {
- return this._applyWithArgs("exactly", "\n");
- });
- return this._apply("space");
- }.call(this);
+ return this._apply("noNlSpace");
});
},
spacesNlSpaces: function() {
@@ -591,8 +595,10 @@ if (global === ometajs_) {
c = this._many1(function() {
return this._applyWithArgs("exactly", "=");
});
- this._apply("spacesNoNl");
- return c.join("")["length"] - 1;
+ this._many(function() {
+ return this._apply("noNlSpace");
+ });
+ return c["length"] - 1;
}.call(this);
},
headerEnd: function() {
@@ -603,7 +609,9 @@ if (global === ometajs_) {
case "\n":
return this._many(function() {
return function() {
- this._apply("spacesNoNl");
+ this._many(function() {
+ return this._apply("noNlSpace");
+ });
return this._applyWithArgs("exactly", "\n");
}.call(this);
});
@@ -671,25 +679,25 @@ if (global === ometajs_) {
return function() {
switch (this._apply("anything")) {
case "\n":
- return this._not(function() {
+ return this._or(function() {
return this._not(function() {
- return this._apply("extBlockStart");
+ return this._not(function() {
+ return this._apply("extBlockStart");
+ });
});
- });
- default:
- throw fail();
- }
- }.call(this);
- }, function() {
- return this._apply("nl");
- }, function() {
- return function() {
- switch (this._apply("anything")) {
- case "\n":
- return this._or(function() {
+ }, function() {
+ return this._many1(function() {
+ return function() {
+ this._many(function() {
+ return this._apply("noNlSpace");
+ });
+ return this._applyWithArgs("exactly", "\n");
+ }.call(this);
+ });
+ }, function() {
return this._not(function() {
return this._not(function() {
- return this._apply("anyLi");
+ return this._apply("listStart");
});
});
}, function() {
@@ -721,7 +729,19 @@ if (global === ometajs_) {
return this._apply("blockEnd");
});
return this._or(function() {
- return this._apply("spacesNlSpaces");
+ return function() {
+ this._many(function() {
+ return this._apply("noNlSpace");
+ });
+ this._applyWithArgs("exactly", "\n");
+ this._many(function() {
+ return this._apply("noNlSpace");
+ });
+ this._not(function() {
+ return this._apply("end");
+ });
+ return " ";
+ }.call(this);
}, function() {
return this._apply("char");
});
@@ -732,38 +752,56 @@ if (global === ometajs_) {
return [ "para", ShmakoWiki.matchAll(c, "topInline") ];
}.call(this);
},
- uli: function() {
- var $elf = this, _fromIdx = this.input.idx, s;
+ listStart: function() {
+ var $elf = this, _fromIdx = this.input.idx;
+ return function() {
+ this._many(function() {
+ return this._apply("noNlSpace");
+ });
+ return this._apply("bullet");
+ }.call(this);
+ },
+ uliBullet: function() {
+ var $elf = this, _fromIdx = this.input.idx;
return function() {
- s = this._apply("spacesNoNl");
this._applyWithArgs("exactly", "*");
this._not(function() {
return this._applyWithArgs("exactly", "*");
});
- this._apply("spacesNoNl");
- return s.join("");
+ this._many(function() {
+ return this._apply("noNlSpace");
+ });
+ return "u";
}.call(this);
},
- oli: function() {
- var $elf = this, _fromIdx = this.input.idx, s;
+ oliBullet: function() {
+ var $elf = this, _fromIdx = this.input.idx;
return function() {
- s = this._apply("spacesNoNl");
this._many1(function() {
return this._apply("digit");
});
this._applyWithArgs("exactly", ".");
- this._apply("spacesNoNl");
- return s.join("");
+ this._many(function() {
+ return this._apply("noNlSpace");
+ });
+ return "o";
}.call(this);
},
- anyLi: function() {
+ bullet: function() {
var $elf = this, _fromIdx = this.input.idx;
return this._or(function() {
- return this._apply("uli");
+ return this._apply("uliBullet");
}, function() {
- return this._apply("oli");
+ return this._apply("oliBullet");
});
},
+ bullet1: function() {
+ var $elf = this, _fromIdx = this.input.idx, t;
+ return function() {
+ t = this._apply("anything");
+ return this._applyWithArgs("apply", t + "liBullet");
+ }.call(this);
+ },
listItemContent: function() {
var $elf = this, _fromIdx = this.input.idx, c;
return function() {
@@ -778,91 +816,68 @@ if (global === ometajs_) {
return ShmakoWiki.matchAll(c.join(""), "topInline");
}.call(this);
},
- anySubList: function() {
- var $elf = this, _fromIdx = this.input.idx, l, s, sl;
- return function() {
- l = this._apply("anything");
- this._applyWithArgs("exactly", "\n");
- this._not(function() {
- return this._not(function() {
- return s = this._apply("anyLi");
- });
- });
- this._pred(s["length"] > l["length"]);
- sl = this._apply("anyList");
- return sl;
- }.call(this);
- },
listItem: function() {
- var $elf = this, _fromIdx = this.input.idx, t, l, s, c, cc;
+ var $elf = this, _fromIdx = this.input.idx, t, n, s, p, b;
return function() {
t = this._apply("anything");
- l = this._apply("anything");
- s = this._applyWithArgs("apply", t);
- this._pred(s["length"] == l["length"]);
- c = this._apply("listItemContent");
- cc = this._or(function() {
- return this._many1(function() {
- return this._applyWithArgs("anySubList", s);
- });
- }, function() {
+ n = this._apply("anything");
+ s = this._many(function() {
+ return this._applyWithArgs("exactly", " ");
+ });
+ this._pred(n == s["length"]);
+ this._applyWithArgs("bullet1", t);
+ p = this._apply("listItemContent");
+ this._or(function() {
return function() {
- this._or(function() {
- return function() {
- switch (this._apply("anything")) {
- case "\n":
- return this._not(function() {
- return this._not(function() {
- return this._applyWithArgs("apply", t);
- });
- });
- default:
- throw fail();
- }
- }.call(this);
- }, function() {
- return this._not(function() {
- return this._not(function() {
- return this._apply("blockEnd");
- });
- });
- });
- return "";
+ switch (this._apply("anything")) {
+ case "\n":
+ return "\n";
+ default:
+ throw fail();
+ }
}.call(this);
+ }, function() {
+ return this._apply("end");
});
- return function() {
- if (cc) {
- c = c.concat(cc);
- } else {
- undefined;
- }
- return [ t + "stItem", c ];
- }.call(this);
+ b = this._many(function() {
+ return this._applyWithArgs("list1", n + 1);
+ });
+ return [ t + "listItem", p.concat(b) ];
}.call(this);
},
list: function() {
- var $elf = this, _fromIdx = this.input.idx, t, s, c;
+ var $elf = this, _fromIdx = this.input.idx;
+ return this._applyWithArgs("list1", 0);
+ },
+ list1: function() {
+ var $elf = this, _fromIdx = this.input.idx, n, s, b, ss;
return function() {
- t = this._apply("anything");
+ n = this._apply("anything");
this._not(function() {
return this._not(function() {
- return s = this._applyWithArgs("apply", t);
+ return function() {
+ s = this._many(function() {
+ return this._apply("noNlSpace");
+ });
+ return b = this._apply("bullet");
+ }.call(this);
});
});
- c = this._many1(function() {
- return this._applyWithArgs("listItem", t, s);
+ this._pred(n <= s["length"]);
+ ss = this._many1(function() {
+ return this._applyWithArgs("listItem", b, s["length"]);
+ });
+ this._many(function() {
+ return function() {
+ this._applyWithArgs("exactly", "\n");
+ return this._many(function() {
+ return this._apply("noNlSpace");
+ });
+ }.call(this);
});
- return [ t + "st", c ];
+ return [ b + "list", ss ];
}.call(this);
},
- anyList: function() {
- var $elf = this, _fromIdx = this.input.idx;
- return this._or(function() {
- return this._applyWithArgs("list", "uli");
- }, function() {
- return this._applyWithArgs("list", "oli");
- });
- },
extBlockStart: function() {
var $elf = this, _fromIdx = this.input.idx, t, tt, c, cc;
return function() {
@@ -956,15 +971,11 @@ if (global === ometajs_) {
}.call(this);
},
allBlock: function() {
- var $elf = this, _fromIdx = this.input.idx, l;
+ var $elf = this, _fromIdx = this.input.idx;
return this._or(function() {
return this._apply("extBlock");
}, function() {
- return function() {
- l = this._apply("anyList");
- this._apply("blockEnd");
- return l;
- }.call(this);
+ return this._apply("list");
}, function() {
return this._apply("header");
}, function() {
@@ -1049,48 +1060,48 @@ if (global === ometajs_) {
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 "bold":
+ return "bold";
+ case "monospace":
+ return "monospace";
case "italic_":
return "italic_";
- case "bold_":
- return "bold_";
- case "underline":
- return "underline";
- case "header5":
- return "header5";
+ case "strike":
+ return "strike";
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 "header5":
+ return "header5";
+ case "header4":
+ return "header4";
case "header1":
return "header1";
- case "header2":
- return "header2";
+ case "superscript":
+ return "superscript";
+ case "italic":
+ return "italic";
case "header3":
return "header3";
- case "subscript_":
- return "subscript_";
case "superscript_":
return "superscript_";
- case "bold":
- return "bold";
+ case "subscript_":
+ return "subscript_";
+ case "strike_":
+ return "strike_";
+ case "bold_":
+ return "bold_";
+ case "header6":
+ return "header6";
+ case "monospace_":
+ return "monospace_";
+ case "header2":
+ return "header2";
+ case "underline":
+ return "underline";
+ case "underline_":
+ return "underline_";
default:
throw fail();
}
@@ -1197,66 +1208,66 @@ if (global === ometajs_) {
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 "bold":
+ return "bold";
+ case "monospace":
+ return "monospace";
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 "link":
return "link";
+ case "strike":
+ return "strike";
+ case "subscript":
+ return "subscript";
+ case "escaped":
+ return "escaped";
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 "header5":
+ return "header5";
+ case "ulist":
+ return "ulist";
+ case "lineBreak":
+ return "lineBreak";
+ case "header4":
+ return "header4";
case "header1":
return "header1";
+ case "superscript":
+ return "superscript";
+ case "italic":
+ return "italic";
case "header3":
return "header3";
- case "ulist":
- return "ulist";
- case "subscript_":
- return "subscript_";
+ case "olistItem":
+ return "olistItem";
case "superscript_":
return "superscript_";
- case "bold":
- return "bold";
+ case "subscript_":
+ return "subscript_";
+ case "strike_":
+ return "strike_";
+ case "bold_":
+ return "bold_";
+ case "ulistItem":
+ return "ulistItem";
+ case "header6":
+ return "header6";
+ case "monospace_":
+ return "monospace_";
+ case "header2":
+ return "header2";
+ case "underline":
+ return "underline";
+ case "extension":
+ return "extension";
+ case "underline_":
+ return "underline_";
default:
throw fail();
}
@@ -1574,66 +1585,66 @@ if (global === ometajs_) {
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 "bold":
+ return "bold";
+ case "monospace":
+ return "monospace";
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 "link":
return "link";
+ case "strike":
+ return "strike";
+ case "subscript":
+ return "subscript";
+ case "escaped":
+ return "escaped";
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 "header5":
+ return "header5";
+ case "ulist":
+ return "ulist";
+ case "lineBreak":
+ return "lineBreak";
+ case "header4":
+ return "header4";
case "header1":
return "header1";
+ case "superscript":
+ return "superscript";
+ case "italic":
+ return "italic";
case "header3":
return "header3";
- case "ulist":
- return "ulist";
- case "subscript_":
- return "subscript_";
+ case "olistItem":
+ return "olistItem";
case "superscript_":
return "superscript_";
- case "bold":
- return "bold";
+ case "subscript_":
+ return "subscript_";
+ case "strike_":
+ return "strike_";
+ case "bold_":
+ return "bold_";
+ case "ulistItem":
+ return "ulistItem";
+ case "header6":
+ return "header6";
+ case "monospace_":
+ return "monospace_";
+ case "header2":
+ return "header2";
+ case "underline":
+ return "underline";
+ case "extension":
+ return "extension";
+ case "underline_":
+ return "underline_";
default:
throw fail();
}
@@ -2067,50 +2078,50 @@ if (global === ometajs_) {
var $elf = this, _fromIdx = this.input.idx;
return function() {
switch (this._apply("anything")) {
- case "underline_":
- return "underline_";
+ case "bold":
+ return "bold";
+ case "monospace":
+ return "monospace";
+ case "italic_":
+ return "italic_";
case "strike":
return "strike";
- case "header4":
- return "header4";
+ case "subscript":
+ return "subscript";
case "escaped":
return "escaped";
- case "italic_":
- return "italic_";
- case "bold_":
- return "bold_";
- case "underline":
- return "underline";
+ case "para":
+ return "para";
case "header5":
return "header5";
- case "subscript":
- return "subscript";
+ case "header4":
+ return "header4";
+ case "header1":
+ return "header1";
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";
+ case "subscript_":
+ return "subscript_";
+ case "strike_":
+ return "strike_";
+ case "bold_":
+ return "bold_";
+ case "header6":
+ return "header6";
+ case "monospace_":
+ return "monospace_";
+ case "header2":
+ return "header2";
+ case "underline":
+ return "underline";
+ case "underline_":
+ return "underline_";
default:
throw fail();
}
View
1 lib/extensions/hl.js
@@ -1 +0,0 @@
-module.exports = require('./ohl');
View
25 lib/extensions/hl/hljs-client.js
@@ -0,0 +1,25 @@
+var HLU = require('./util'),
+ U = require('../../utils');
+
+exports.astToBemjson = function(c, p) {
+
+ var lang = HLU.translateAlias(p);
+
+ return {
+ block: 'highlight',
+ mods: {'render': 'client'},
+ lang: lang,
+ content: U.htmlEscape(c)
+ };
+
+};
+
+exports.astToHtml = function(c, p) {
+
+ var lang = HLU.translateAlias(p);
+
+ return '<pre class="highlight highlight_render_client"><code class="highlight__code ' + lang + '">' +
+ U.htmlEscape(c) +
+ '</code></pre>';
+
+};
View
26 lib/extensions/hl/hljs-server.js
@@ -0,0 +1,26 @@
+var HL = require('highlight.js'),
+ U = require('./util');
+
+exports.astToBemjson = function(c, p) {
+
+ var lang = U.translateAlias(p),
+ res = p? HL.highlight(lang, c) : HL.highlightAuto(c);
+
+ return {
+ block: 'highlight',
+ lang: res.language,
+ content: res.value
+ };
+
+};
+
+exports.astToHtml = function(c, p) {
+
+ var lang = U.translateAlias(p),
+ res = p? HL.highlight(lang, c) : HL.highlightAuto(c);
+
+ return '<pre class="highlight"><code class="highlight__code ' + res.language + '">' +
+ res.value +
+ '</code></pre>';
+
+};
View
23 lib/extensions/hl/index.js
@@ -0,0 +1,23 @@
+var HL_DEFAULT = 'no-hl',
+ HL = process.env.SHMAKOWIKI_HL || HL_DEFAULT;
+
+if (!~['server', 'client', 'ohl', 'no-hl'].indexOf(HL)) {
+ HL = HL_DEFAULT;
+}
+
+var ext;
+switch (HL) {
+
+ case 'server':
+ case 'client':
+ ext = require('./hljs-' + HL);
+ break;
+
+ case 'ohl':
+ case 'no-hl':
+ ext = require('./' + HL);
+ break;
+
+}
+
+module.exports = ext;
View
22 lib/extensions/hl/no-hl.js
@@ -0,0 +1,22 @@
+var U = require('../../utils');
+
+exports.astToBemjson = function(c, p) {
+
+ return {
+ tag: 'pre',
+ content: {
+ tag: 'code',
+ cls: p,
+ content: U.htmlEscape(c)
+ }
+ };
+
+};
+
+exports.astToHtml = function(c, p) {
+
+ return '<pre><code class="' + p + '">' +
+ U.htmlEscape(c) +
+ '</code></pre>';
+
+};
View
16 lib/extensions/hl/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
23 lib/extensions/hl/util.js
@@ -0,0 +1,23 @@
+exports.translateAlias = function(alias) {
+
+ var lang = alias;
+
+ switch (alias) {
+
+ case 'js':
+ lang = 'javascript';
+ break;
+
+ case 'patch':
+ lang = 'diff';
+ break;
+
+ case 'md':
+ lang = 'markdown';
+ break;
+
+ }
+
+ return lang;
+
+};
View
15 lib/extensions/hljs.js
@@ -1,15 +0,0 @@
-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
18 lib/extensions/ohl.js
@@ -1,16 +1,2 @@
-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');
-};
+// backward compatibility wrapper
+module.exports = require('./hl/ohl');
View
5 package.json
@@ -20,7 +20,8 @@
"ometajs": "2.1.x",
"ometa-highlighter": "~ 0.2.3",
"q": "0.7.x",
- "coa": "0.3.x"
+ "coa": "0.3.x",
+ "highlight.js": "7"
},
"engines": {
"node": ">=0.4.0"
@@ -32,4 +33,4 @@
],
"devDependencies": {},
"optionalDependencies": {}
-}
+}
View
245 src/shmakowiki.ometajs.js
@@ -143,16 +143,16 @@ if (global === ometajs_) {
var $elf = this, _fromIdx = this.input.idx;
return function() {
switch (this._apply("anything")) {
- case "[":
- return function() {
- this._applyWithArgs("exactly", "[");
- return "[[";
- }.call(this);
case "(":
return function() {
this._applyWithArgs("exactly", "(");
return "((";
}.call(this);
+ case "[":
+ return function() {
+ this._applyWithArgs("exactly", "[");
+ return "[[";
+ }.call(this);
default:
throw fail();
}
@@ -547,15 +547,19 @@ if (global === ometajs_) {
return this._applyWithArgs("allInline", []);
});
},
+ noNlSpace: function() {
+ var $elf = this, _fromIdx = this.input.idx;
+ return function() {
+ this._not(function() {
+ return this._applyWithArgs("exactly", "\n");
+ });
+ return this._apply("space");
+ }.call(this);
+ },
spacesNoNl: function() {
var $elf = this, _fromIdx = this.input.idx;
return this._many(function() {
- return function() {
- this._not(function() {
- return this._applyWithArgs("exactly", "\n");
- });
- return this._apply("space");
- }.call(this);
+ return this._apply("noNlSpace");
});
},
spacesNlSpaces: function() {
@@ -588,8 +592,10 @@ if (global === ometajs_) {
c = this._many1(function() {
return this._applyWithArgs("exactly", "=");
});
- this._apply("spacesNoNl");
- return c.join("")["length"] - 1;
+ this._many(function() {
+ return this._apply("noNlSpace");
+ });
+ return c["length"] - 1;
}.call(this);
},
headerEnd: function() {
@@ -600,7 +606,9 @@ if (global === ometajs_) {
case "\n":
return this._many(function() {
return function() {
- this._apply("spacesNoNl");
+ this._many(function() {
+ return this._apply("noNlSpace");
+ });
return this._applyWithArgs("exactly", "\n");
}.call(this);
});
@@ -668,25 +676,25 @@ if (global === ometajs_) {
return function() {
switch (this._apply("anything")) {
case "\n":
- return this._not(function() {
+ return this._or(function() {
return this._not(function() {
- return this._apply("extBlockStart");
+ return this._not(function() {
+ return this._apply("extBlockStart");
+ });
});
- });
- default:
- throw fail();
- }
- }.call(this);
- }, function() {
- return this._apply("nl");
- }, function() {
- return function() {
- switch (this._apply("anything")) {
- case "\n":
- return this._or(function() {
+ }, function() {
+ return this._many1(function() {
+ return function() {
+ this._many(function() {
+ return this._apply("noNlSpace");
+ });
+ return this._applyWithArgs("exactly", "\n");
+ }.call(this);
+ });
+ }, function() {
return this._not(function() {
return this._not(function() {
- return this._apply("anyLi");
+ return this._apply("listStart");
});
});
}, function() {
@@ -718,7 +726,19 @@ if (global === ometajs_) {
return this._apply("blockEnd");
});
return this._or(function() {
- return this._apply("spacesNlSpaces");
+ return function() {
+ this._many(function() {
+ return this._apply("noNlSpace");
+ });
+ this._applyWithArgs("exactly", "\n");
+ this._many(function() {
+ return this._apply("noNlSpace");
+ });
+ this._not(function() {
+ return this._apply("end");
+ });
+ return " ";
+ }.call(this);
}, function() {
return this._apply("char");
});
@@ -729,38 +749,56 @@ if (global === ometajs_) {
return [ "para", ShmakoWiki.matchAll(c, "topInline") ];
}.call(this);
},
- uli: function() {
- var $elf = this, _fromIdx = this.input.idx, s;
+ listStart: function() {
+ var $elf = this, _fromIdx = this.input.idx;
+ return function() {
+ this._many(function() {
+ return this._apply("noNlSpace");
+ });
+ return this._apply("bullet");
+ }.call(this);
+ },
+ uliBullet: function() {
+ var $elf = this, _fromIdx = this.input.idx;
return function() {
- s = this._apply("spacesNoNl");
this._applyWithArgs("exactly", "*");
this._not(function() {
return this._applyWithArgs("exactly", "*");
});
- this._apply("spacesNoNl");
- return s.join("");
+ this._many(function() {
+ return this._apply("noNlSpace");
+ });
+ return "u";
}.call(this);
},
- oli: function() {
- var $elf = this, _fromIdx = this.input.idx, s;
+ oliBullet: function() {
+ var $elf = this, _fromIdx = this.input.idx;
return function() {
- s = this._apply("spacesNoNl");
this._many1(function() {
return this._apply("digit");
});
this._applyWithArgs("exactly", ".");
- this._apply("spacesNoNl");
- return s.join("");
+ this._many(function() {
+ return this._apply("noNlSpace");
+ });
+ return "o";
}.call(this);
},
- anyLi: function() {
+ bullet: function() {
var $elf = this, _fromIdx = this.input.idx;
return this._or(function() {
- return this._apply("uli");
+ return this._apply("uliBullet");
}, function() {
- return this._apply("oli");
+ return this._apply("oliBullet");
});
},
+ bullet1: function() {
+ var $elf = this, _fromIdx = this.input.idx, t;
+ return function() {
+ t = this._apply("anything");
+ return this._applyWithArgs("apply", t + "liBullet");
+ }.call(this);
+ },
listItemContent: function() {
var $elf = this, _fromIdx = this.input.idx, c;
return function() {
@@ -775,91 +813,68 @@ if (global === ometajs_) {
return ShmakoWiki.matchAll(c.join(""), "topInline");
}.call(this);
},
- anySubList: function() {
- var $elf = this, _fromIdx = this.input.idx, l, s, sl;
- return function() {
- l = this._apply("anything");
- this._applyWithArgs("exactly", "\n");
- this._not(function() {
- return this._not(function() {
- return s = this._apply("anyLi");
- });
- });
- this._pred(s["length"] > l["length"]);
- sl = this._apply("anyList");
- return sl;
- }.call(this);
- },
listItem: function() {
- var $elf = this, _fromIdx = this.input.idx, t, l, s, c, cc;
+ var $elf = this, _fromIdx = this.input.idx, t, n, s, p, b;
return function() {
t = this._apply("anything");
- l = this._apply("anything");
- s = this._applyWithArgs("apply", t);
- this._pred(s["length"] == l["length"]);
- c = this._apply("listItemContent");
- cc = this._or(function() {
- return this._many1(function() {
- return this._applyWithArgs("anySubList", s);
- });
- }, function() {
+ n = this._apply("anything");
+ s = this._many(function() {
+ return this._applyWithArgs("exactly", " ");
+ });
+ this._pred(n == s["length"]);
+ this._applyWithArgs("bullet1", t);
+ p = this._apply("listItemContent");
+ this._or(function() {
return function() {
- this._or(function() {
- return function() {
- switch (this._apply("anything")) {
- case "\n":
- return this._not(function() {
- return this._not(function() {
- return this._applyWithArgs("apply", t);
- });
- });
- default:
- throw fail();
- }
- }.call(this);
- }, function() {
- return this._not(function() {
- return this._not(function() {
- return this._apply("blockEnd");
- });
- });
- });
- return "";
+ switch (this._apply("anything")) {
+ case "\n":
+ return "\n";
+ default:
+ throw fail();
+ }
}.call(this);
+ }, function() {
+ return this._apply("end");
});
- return function() {
- if (cc) {
- c = c.concat(cc);
- } else {
- undefined;
- }
- return [ t + "stItem", c ];
- }.call(this);
+ b = this._many(function() {
+ return this._applyWithArgs("list1", n + 1);
+ });
+ return [ t + "listItem", p.concat(b) ];
}.call(this);
},
list: function() {
- var $elf = this, _fromIdx = this.input.idx, t, s, c;
+ var $elf = this, _fromIdx = this.input.idx;
+ return this._applyWithArgs("list1", 0);
+ },
+ list1: function() {
+ var $elf = this, _fromIdx = this.input.idx, n, s, b, ss;
return function() {
- t = this._apply("anything");
+ n = this._apply("anything");
this._not(function() {
return this._not(function() {
- return s = this._applyWithArgs("apply", t);
+ return function() {
+ s = this._many(function() {
+ return this._apply("noNlSpace");
+ });
+ return b = this._apply("bullet");
+ }.call(this);
});
});
- c = this._many1(function() {
- return this._applyWithArgs("listItem", t, s);
+ this._pred(n <= s["length"]);
+ ss = this._many1(function() {
+ return this._applyWithArgs("listItem", b, s["length"]);
+ });
+ this._many(function() {
+ return function() {
+ this._applyWithArgs("exactly", "\n");
+ return this._many(function() {
+ return this._apply("noNlSpace");
+ });
+ }.call(this);
});
- return [ t + "st", c ];
+ return [ b + "list", ss ];
}.call(this);
},
- anyList: function() {
- var $elf = this, _fromIdx = this.input.idx;
- return this._or(function() {
- return this._applyWithArgs("list", "uli");
- }, function() {
- return this._applyWithArgs("list", "oli");
- });
- },
extBlockStart: function() {
var $elf = this, _fromIdx = this.input.idx, t, tt, c, cc;
return function() {
@@ -953,15 +968,11 @@ if (global === ometajs_) {
}.call(this);
},
allBlock: function() {
- var $elf = this, _fromIdx = this.input.idx, l;
+ var $elf = this, _fromIdx = this.input.idx;
return this._or(function() {
return this._apply("extBlock");
}, function() {
- return function() {
- l = this._apply("anyList");
- this._apply("blockEnd");
- return l;
- }.call(this);
+ return this._apply("list");
}, function() {
return this._apply("header");
}, function() {
View
92 src/shmakowiki2bemjson.ometajs.js
@@ -35,66 +35,66 @@ if (global === ometajs_) {
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 "bold":
+ return "bold";
+ case "monospace":
+ return "monospace";
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 "link":
return "link";
+ case "strike":
+ return "strike";
+ case "subscript":
+ return "subscript";
+ case "escaped":
+ return "escaped";
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 "header5":
+ return "header5";
+ case "ulist":
+ return "ulist";
+ case "lineBreak":
+ return "lineBreak";
+ case "header4":
+ return "header4";
case "header1":
return "header1";
+ case "superscript":
+ return "superscript";
+ case "italic":
+ return "italic";
case "header3":
return "header3";
- case "ulist":
- return "ulist";
- case "subscript_":
- return "subscript_";
+ case "olistItem":
+ return "olistItem";
case "superscript_":
return "superscript_";
- case "bold":
- return "bold";
+ case "subscript_":
+ return "subscript_";
+ case "strike_":
+ return "strike_";
+ case "bold_":
+ return "bold_";
+ case "ulistItem":
+ return "ulistItem";
+ case "header6":
+ return "header6";
+ case "monospace_":
+ return "monospace_";
+ case "header2":
+ return "header2";
+ case "underline":
+ return "underline";
+ case "extension":
+ return "extension";
+ case "underline_":
+ return "underline_";
default:
throw fail();
}
View
92 src/shmakowiki2html.ometajs.js
@@ -35,66 +35,66 @@ if (global === ometajs_) {
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 "bold":
+ return "bold";
+ case "monospace":
+ return "monospace";
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 "link":
return "link";
+ case "strike":
+ return "strike";
+ case "subscript":
+ return "subscript";
+ case "escaped":
+ return "escaped";
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 "header5":
+ return "header5";
+ case "ulist":
+ return "ulist";
+ case "lineBreak":
+ return "lineBreak";
+ case "header4":
+ return "header4";
case "header1":
return "header1";
+ case "superscript":
+ return "superscript";
+ case "italic":
+ return "italic";
case "header3":
return "header3";
- case "ulist":
- return "ulist";
- case "subscript_":
- return "subscript_";
+ case "olistItem":
+ return "olistItem";
case "superscript_":
return "superscript_";
- case "bold":
- return "bold";
+ case "subscript_":
+ return "subscript_";
+ case "strike_":
+ return "strike_";
+ case "bold_":
+ return "bold_";
+ case "ulistItem":
+ return "ulistItem";
+ case "header6":
+ return "header6";
+ case "monospace_":
+ return "monospace_";
+ case "header2":
+ return "header2";
+ case "underline":
+ return "underline";
+ case "extension":
+ return "extension";
+ case "underline_":
+ return "underline_";
default:
throw fail();
}
View
60 src/shmakowiki2plain.ometajs.js
@@ -35,50 +35,50 @@ if (global === ometajs_) {
var $elf = this, _fromIdx = this.input.idx;
return function() {
switch (this._apply("anything")) {
- case "underline_":
- return "underline_";
+ case "bold":
+ return "bold";
+ case "monospace":
+ return "monospace";
+ case "italic_":
+ return "italic_";
case "strike":
return "strike";
- case "header4":
- return "header4";
+ case "subscript":
+ return "subscript";
case "escaped":
return "escaped";
- case "italic_":
- return "italic_";
- case "bold_":
- return "bold_";
- case "underline":
- return "underline";
+ case "para":
+ return "para";
case "header5":
return "header5";
- case "subscript":
- return "subscript";
+ case "header4":
+ return "header4";
+ case "header1":
+ return "header1";
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";
+ case "subscript_":
+ return "subscript_";
+ case "strike_":
+ return "strike_";
+ case "bold_":
+ return "bold_";
+ case "header6":
+ return "header6";
+ case "monospace_":
+ return "monospace_";
+ case "header2":
+ return "header2";
+ case "underline":
+ return "underline";
+ case "underline_":
+ return "underline_";
default:
throw fail();
}
View
60 src/transform.ometajs.js
@@ -35,48 +35,48 @@ if (global === ometajs_) {
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 "bold":
+ return "bold";
+ case "monospace":
+ return "monospace";
case "italic_":
return "italic_";
- case "bold_":
- return "bold_";
- case "underline":
- return "underline";
- case "header5":
- return "header5";
+ case "strike":
+ return "strike";
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 "header5":
+ return "header5";
+ case "header4":
+ return "header4";
case "header1":
return "header1";
- case "header2":
- return "header2";
+ case "superscript":
+ return "superscript";
+ case "italic":
+ return "italic";
case "header3":
return "header3";
- case "subscript_":
- return "subscript_";
case "superscript_":
return "superscript_";
- case "bold":
- return "bold";
+ case "subscript_":
+ return "subscript_";
+ case "strike_":
+ return "strike_";
+ case "bold_":
+ return "bold_";
+ case "header6":
+ return "header6";
+ case "monospace_":
+ return "monospace_";
+ case "header2":
+ return "header2";
+ case "underline":
+ return "underline";
+ case "underline_":
+ return "underline_";
default:
throw fail();
}
View
4 tests/tests.js
@@ -1,3 +1,5 @@
+process.env.SHMAKOWIKI_HL = 'ohl';
+
var tests = [
{
@@ -777,3 +779,5 @@ for (var i = 0; i < tests.length; i++) {
console.log('-----------------------------------------------------');
}
console.log('\n' + (totalFail ? 'Total FAIL: ' + totalFail : 'All Ok'));
+
+process.exit(totalFail);

0 comments on commit 18c0e35

Please sign in to comment.