|
@@ -0,0 +1,556 @@
|
|
|
|
+/**
|
|
|
|
+* Copyright (c) 2012, Leon Sorokin
|
|
|
|
+* All rights reserved. (MIT Licensed)
|
|
|
|
+*
|
|
|
|
+* reMarked.js - DOM > markdown
|
|
|
|
+*/
|
|
|
|
+
|
|
|
|
+reMarked = function(opts) {
|
|
|
|
+
|
|
|
|
+ var links = [];
|
|
|
|
+ var cfg = {
|
|
|
|
+ link_list: false, // render links as references, create link list as appendix
|
|
|
|
+ // link_near: // cite links immediately after blocks
|
|
|
|
+ h1_setext: true, // underline h1 headers
|
|
|
|
+ h2_setext: true, // underline h2 headers
|
|
|
|
+ h_atx_suf: false, // header suffix (###)
|
|
|
|
+ // h_compact: true, // compact headers (except h1)
|
|
|
|
+ gfm_code: false, // render code blocks as via ``` delims
|
|
|
|
+ li_bullet: "*-+"[0], // list item bullet style
|
|
|
|
+ // list_indnt: // indent top-level lists
|
|
|
|
+ hr_char: "-_*"[0], // hr style
|
|
|
|
+ indnt_str: [" ","\t"," "][0], // indentation string
|
|
|
|
+ bold_char: "*_"[0], // char used for strong
|
|
|
|
+ emph_char: "*_"[1], // char used for em
|
|
|
|
+ gfm_tbls: true, // markdown-extra tables
|
|
|
|
+ tbl_edges: false, // show side edges on tables
|
|
|
|
+ hash_lnks: false, // anchors w/hash hrefs as links
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ extend(cfg, opts);
|
|
|
|
+
|
|
|
|
+ function extend(a, b) {
|
|
|
|
+ if (!b) return a;
|
|
|
|
+ for (var i in a) {
|
|
|
|
+ if (typeof b[i] !== "undefined")
|
|
|
|
+ a[i] = b[i];
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ function rep(str, num) {
|
|
|
|
+ var s = "";
|
|
|
|
+ while (num-- > 0)
|
|
|
|
+ s += str;
|
|
|
|
+ return s;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ function trim12(str) {
|
|
|
|
+ var str = str.replace(/^\s\s*/, ''),
|
|
|
|
+ ws = /\s/,
|
|
|
|
+ i = str.length;
|
|
|
|
+ while (ws.test(str.charAt(--i)));
|
|
|
|
+ return str.slice(0, i + 1);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ function lpad(targ, padStr, len) {
|
|
|
|
+ return rep(padStr, len - targ.length) + targ;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ function rpad(targ, padStr, len) {
|
|
|
|
+ return targ + rep(padStr, len - targ.length);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ function otag(tag) {
|
|
|
|
+ if (!tag) return "";
|
|
|
|
+ return "<" + tag + ">";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ function ctag(tag) {
|
|
|
|
+ if (!tag) return "";
|
|
|
|
+ return "</" + tag + ">";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ function pfxLines(txt, pfx) {
|
|
|
|
+ return txt.replace(/^/gm, pfx);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ function nodeName(e) {
|
|
|
|
+ return (e.nodeName == "#text" ? "txt" : e.nodeName).toLowerCase();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ function wrap(str, opts) {
|
|
|
|
+ var pre, suf;
|
|
|
|
+
|
|
|
|
+ if (opts instanceof Array) {
|
|
|
|
+ pre = opts[0];
|
|
|
|
+ suf = opts[1];
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ pre = suf = opts;
|
|
|
|
+
|
|
|
|
+ pre = pre instanceof Function ? pre.call(this, str) : pre;
|
|
|
|
+ suf = suf instanceof Function ? suf.call(this, str) : suf;
|
|
|
|
+
|
|
|
|
+ return pre + str + suf;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ this.render = function(ctr) {
|
|
|
|
+ if (typeof ctr == "string") {
|
|
|
|
+ var htmlstr = ctr;
|
|
|
|
+ ctr = document.createElement("div");
|
|
|
|
+ ctr.innerHTML = htmlstr;
|
|
|
|
+ }
|
|
|
|
+ var s = new lib.tag(ctr, null, 0);
|
|
|
|
+ var re = s.rend().replace(/^[\t ]+\n/gm, "\n");
|
|
|
|
+ if (cfg.link_list) {
|
|
|
|
+ // hack
|
|
|
|
+ re += "\n\n";
|
|
|
|
+ var maxlen = 0;
|
|
|
|
+ // get longest link href with title, TODO: use getAttribute?
|
|
|
|
+ for (var y in links) {
|
|
|
|
+ if (!links[y].e.title) continue;
|
|
|
|
+ var len = links[y].e.href.length;
|
|
|
|
+ if (len && len > maxlen)
|
|
|
|
+ maxlen = len;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ for (var k in links) {
|
|
|
|
+ var title = links[k].e.title ? rep(" ", (maxlen + 2) - links[k].e.href.length) + '"' + links[k].e.title + '"' : "";
|
|
|
|
+ re += " [" + (+k+1) + "]: " + links[k].e.href + title + "\n";
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return re.replace(/^[\t ]+\n/gm, "\n");
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ var lib = {};
|
|
|
|
+
|
|
|
|
+ lib.tag = klass({
|
|
|
|
+ wrap: "",
|
|
|
|
+ lnPfx: "", // only block
|
|
|
|
+ lnInd: 0, // only block
|
|
|
|
+ init: function(e, p, i)
|
|
|
|
+ {
|
|
|
|
+ this.e = e;
|
|
|
|
+ this.p = p;
|
|
|
|
+ this.i = i;
|
|
|
|
+ this.c = [];
|
|
|
|
+ this.tag = nodeName(e);
|
|
|
|
+
|
|
|
|
+ this.initK();
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ initK: function()
|
|
|
|
+ {
|
|
|
|
+ var i;
|
|
|
|
+ if (this.e.hasChildNodes()) {
|
|
|
|
+ // inline elems allowing adjacent whitespace text nodes to be rendered
|
|
|
|
+ var inlRe = /^(?:a|strong|code|em|sub|sup|del|i|u|b|big|center)$/, n, name;
|
|
|
|
+ for (i in this.e.childNodes) {
|
|
|
|
+ if (!/\d+/.test(i)) continue;
|
|
|
|
+
|
|
|
|
+ n = this.e.childNodes[i];
|
|
|
|
+ name = nodeName(n);
|
|
|
|
+
|
|
|
|
+ // ignored tags
|
|
|
|
+ if (/style|script|canvas|video|audio/.test(name))
|
|
|
|
+ continue;
|
|
|
|
+
|
|
|
|
+ // empty whitespace handling
|
|
|
|
+ if (name == "txt" && /^\s+$/.test(n.textContent)) {
|
|
|
|
+ // ignore if first or last child (trim)
|
|
|
|
+ if (i == 0 || i == this.e.childNodes.length - 1 || !this.p)
|
|
|
|
+ continue;
|
|
|
|
+
|
|
|
|
+ // only ouput when has an adjacent inline elem
|
|
|
|
+ var prev = this.e.childNodes[i-1],
|
|
|
|
+ next = this.e.childNodes[i+1];
|
|
|
|
+ if (prev && !nodeName(prev).match(inlRe) || next && !nodeName(next).match(inlRe))
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ if (!lib[name])
|
|
|
|
+ name = "tag";
|
|
|
|
+
|
|
|
|
+ var node = new lib[name](n, this, this.c.length);
|
|
|
|
+
|
|
|
|
+ if (node instanceof lib.a && n.href || node instanceof lib.img) {
|
|
|
|
+ node.lnkid = links.length;
|
|
|
|
+ links.push(node);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ this.c.push(node);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ rend: function()
|
|
|
|
+ {
|
|
|
|
+ return this.rendK().replace(/\n{3,}/gm, "\n\n"); // can screw up pre and code :(
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ rendK: function()
|
|
|
|
+ {
|
|
|
|
+ var n, buf = "";
|
|
|
|
+ for (var i in this.c) {
|
|
|
|
+ n = this.c[i];
|
|
|
|
+ buf += (n.bef || "") + n.rend() + (n.aft || "");
|
|
|
|
+ }
|
|
|
|
+ return buf.replace(/^\n+|\n+$/, "");
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ lib.blk = lib.tag.extend({
|
|
|
|
+ wrap: ["\n\n", ""],
|
|
|
|
+ wrapK: null,
|
|
|
|
+ tagr: false,
|
|
|
|
+ lnInd: null,
|
|
|
|
+ init: function(e, p ,i) {
|
|
|
|
+ this.supr(e,p,i);
|
|
|
|
+
|
|
|
|
+ // kids indented
|
|
|
|
+ if (this.lnInd === null) {
|
|
|
|
+ if (this.p && this.tagr && this.c[0] instanceof lib.blk)
|
|
|
|
+ this.lnInd = 4;
|
|
|
|
+ else
|
|
|
|
+ this.lnInd = 0;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // kids wrapped?
|
|
|
|
+ if (this.wrapK === null) {
|
|
|
|
+ if (this.tagr && this.c[0] instanceof lib.blk)
|
|
|
|
+ this.wrapK = "\n";
|
|
|
|
+ else
|
|
|
|
+ this.wrapK = "";
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ rend: function()
|
|
|
|
+ {
|
|
|
|
+ return wrap.call(this, (this.tagr ? otag(this.tag) : "") + wrap.call(this, pfxLines(pfxLines(this.rendK(), this.lnPfx), rep(" ", this.lnInd)), this.wrapK) + (this.tagr ? ctag(this.tag) : ""), this.wrap);
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ rendK: function()
|
|
|
|
+ {
|
|
|
|
+ var kids = this.supr();
|
|
|
|
+ // remove min uniform leading spaces from block children. marked.js's list outdent algo sometimes leaves these
|
|
|
|
+ if (this.p instanceof lib.li) {
|
|
|
|
+ var repl = null, spcs = kids.match(/^[\t ]+/gm);
|
|
|
|
+ if (!spcs) return kids;
|
|
|
|
+ for (var i in spcs) {
|
|
|
|
+ if (repl === null || spcs[i][0].length < repl.length)
|
|
|
|
+ repl = spcs[i][0];
|
|
|
|
+ }
|
|
|
|
+ return kids.replace(new RegExp("^" + repl), "");
|
|
|
|
+ }
|
|
|
|
+ return kids;
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ lib.tblk = lib.blk.extend({tagr: true});
|
|
|
|
+
|
|
|
|
+ lib.cblk = lib.blk.extend({wrap: ["\n", ""]});
|
|
|
|
+ lib.ctblk = lib.cblk.extend({tagr: true});
|
|
|
|
+
|
|
|
|
+ lib.inl = lib.tag.extend({
|
|
|
|
+ rend: function()
|
|
|
|
+ {
|
|
|
|
+ return wrap.call(this, this.rendK(), this.wrap);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ lib.tinl = lib.inl.extend({
|
|
|
|
+ tagr: true,
|
|
|
|
+ rend: function()
|
|
|
|
+ {
|
|
|
|
+ return otag(this.tag) + wrap.call(this, this.rendK(), this.wrap) + ctag(this.tag);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ lib.p = lib.blk.extend({
|
|
|
|
+ rendK: function() {
|
|
|
|
+ return this.supr().replace(/^\s+/gm, "");
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ lib.div = lib.p.extend();
|
|
|
|
+
|
|
|
|
+ lib.span = lib.inl.extend();
|
|
|
|
+
|
|
|
|
+ lib.list = lib.blk.extend({
|
|
|
|
+ expn: false,
|
|
|
|
+ wrap: [function(){return this.p instanceof lib.li ? "\n" : "\n\n";}, ""]
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ lib.ul = lib.list.extend({});
|
|
|
|
+
|
|
|
|
+ lib.ol = lib.list.extend({});
|
|
|
|
+
|
|
|
|
+ lib.li = lib.cblk.extend({
|
|
|
|
+ wrap: ["\n", function(kids) {
|
|
|
|
+ return this.p.expn || kids.match(/\n{2}/gm) ? "\n" : ""; // || this.kids.match(\n)
|
|
|
|
+ }],
|
|
|
|
+ wrapK: [function() {
|
|
|
|
+ return this.p.tag == "ul" ? cfg.li_bullet + " " : (this.i + 1) + ". ";
|
|
|
|
+ }, ""],
|
|
|
|
+ rendK: function() {
|
|
|
|
+ return this.supr().replace(/\n([^\n])/gm, "\n" + cfg.indnt_str + "$1");
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ lib.hr = lib.blk.extend({
|
|
|
|
+ wrap: ["\n\n", rep(cfg.hr_char, 3)]
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ lib.h = lib.blk.extend({});
|
|
|
|
+
|
|
|
|
+ lib.h_setext = lib.h.extend({});
|
|
|
|
+
|
|
|
|
+ cfg.h1_setext && (lib.h1 = lib.h_setext.extend({
|
|
|
|
+ wrapK: ["", function(kids) {
|
|
|
|
+ return "\n" + rep("=", kids.length);
|
|
|
|
+ }]
|
|
|
|
+ }));
|
|
|
|
+
|
|
|
|
+ cfg.h2_setext && (lib.h2 = lib.h_setext.extend({
|
|
|
|
+ wrapK: ["", function(kids) {
|
|
|
|
+ return "\n" + rep("-", kids.length);
|
|
|
|
+ }]
|
|
|
|
+ }));
|
|
|
|
+
|
|
|
|
+ lib.h_atx = lib.h.extend({
|
|
|
|
+ wrapK: [
|
|
|
|
+ function(kids) {
|
|
|
|
+ return rep("#", this.tag[1]) + " ";
|
|
|
|
+ },
|
|
|
|
+ function(kids) {
|
|
|
|
+ return cfg.h_atx_suf ? " " + rep("#", this.tag[1]) : "";
|
|
|
|
+ }
|
|
|
|
+ ]
|
|
|
|
+ });
|
|
|
|
+ !cfg.h1_setext && (lib.h1 = lib.h_atx.extend({}));
|
|
|
|
+
|
|
|
|
+ !cfg.h2_setext && (lib.h2 = lib.h_atx.extend({}));
|
|
|
|
+
|
|
|
|
+ lib.h3 = lib.h_atx.extend({});
|
|
|
|
+
|
|
|
|
+ lib.h4 = lib.h_atx.extend({});
|
|
|
|
+
|
|
|
|
+ lib.h5 = lib.h_atx.extend({});
|
|
|
|
+
|
|
|
|
+ lib.h6 = lib.h_atx.extend({});
|
|
|
|
+
|
|
|
|
+ lib.a = lib.inl.extend({
|
|
|
|
+ lnkid: null,
|
|
|
|
+ rend: function() {
|
|
|
|
+ var kids = this.rendK(),
|
|
|
|
+ href = this.e.getAttribute("href"),
|
|
|
|
+ title = this.e.title ? ' "' + this.e.title + '"' : "";
|
|
|
|
+
|
|
|
|
+ if (!href || href == kids || href[0] == "#" && !cfg.hash_lnks)
|
|
|
|
+ return kids;
|
|
|
|
+
|
|
|
|
+ if (cfg.link_list)
|
|
|
|
+ return "[" + kids + "] [" + (this.lnkid + 1) + "]";
|
|
|
|
+
|
|
|
|
+ return "[" + kids + "](" + href + title + ")";
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ // almost identical to links, maybe merge
|
|
|
|
+ lib.img = lib.inl.extend({
|
|
|
|
+ lnkid: null,
|
|
|
|
+ rend: function() {
|
|
|
|
+ var kids = this.e.alt,
|
|
|
|
+ src = this.e.getAttribute("src");
|
|
|
|
+
|
|
|
|
+ if (cfg.link_list)
|
|
|
|
+ return "[" + kids + "] [" + (this.lnkid + 1) + "]";
|
|
|
|
+
|
|
|
|
+ var title = this.e.title ? ' "'+ this.e.title + '"' : "";
|
|
|
|
+
|
|
|
|
+ return "";
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ lib.em = lib.inl.extend({wrap: cfg.emph_char});
|
|
|
|
+
|
|
|
|
+ lib.i = lib.em.extend();
|
|
|
|
+
|
|
|
|
+ lib.del = lib.tinl.extend();
|
|
|
|
+
|
|
|
|
+ lib.br = lib.inl.extend({
|
|
|
|
+ wrap: ["", function() {
|
|
|
|
+ // br in headers output as html
|
|
|
|
+ return this.p instanceof lib.h ? "<br>" : " \n";
|
|
|
|
+ }]
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ lib.strong = lib.inl.extend({wrap: rep(cfg.bold_char, 2)});
|
|
|
|
+
|
|
|
|
+ lib.b = lib.strong.extend();
|
|
|
|
+
|
|
|
|
+ lib.dl = lib.tblk.extend({lnInd: 2});
|
|
|
|
+
|
|
|
|
+ lib.dt = lib.ctblk.extend();
|
|
|
|
+
|
|
|
|
+ lib.dd = lib.ctblk.extend();
|
|
|
|
+
|
|
|
|
+ lib.sub = lib.tinl.extend();
|
|
|
|
+
|
|
|
|
+ lib.sup = lib.tinl.extend();
|
|
|
|
+
|
|
|
|
+ lib.blockquote = lib.blk.extend({
|
|
|
|
+ lnPfx: "> ",
|
|
|
|
+ rend: function() {
|
|
|
|
+ return this.supr().replace(/>[ \t]$/gm, ">");
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ // can render with or without tags
|
|
|
|
+ lib.pre = lib.blk.extend({
|
|
|
|
+ tagr: true,
|
|
|
|
+ wrapK: "\n",
|
|
|
|
+ lnInd: 0
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ // can morph into inline based on context
|
|
|
|
+ lib.code = lib.blk.extend({
|
|
|
|
+ tagr: false,
|
|
|
|
+ wrap: "",
|
|
|
|
+ wrapK: function(kids) {
|
|
|
|
+ return kids.indexOf("`") !== -1 ? "``" : "`"; // esc double backticks
|
|
|
|
+ },
|
|
|
|
+ lnInd: 0,
|
|
|
|
+ init: function(e, p, i) {
|
|
|
|
+ this.supr(e, p, i);
|
|
|
|
+
|
|
|
|
+ if (this.p instanceof lib.pre) {
|
|
|
|
+ this.p.tagr = false;
|
|
|
|
+
|
|
|
|
+ if (cfg.gfm_code) {
|
|
|
|
+ var cls = this.e.getAttribute("class");
|
|
|
|
+ this.wrapK = ["```" + (cls ? " " + cls : "") + "\n", "\n```"];
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ this.wrapK = "";
|
|
|
|
+ this.p.lnInd = 4;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ lib.table = cfg.gfm_tbls ? lib.blk.extend({
|
|
|
|
+ cols: [],
|
|
|
|
+ init: function(e, p, i) {
|
|
|
|
+ this.supr(e, p, i);
|
|
|
|
+ this.cols = [];
|
|
|
|
+ },
|
|
|
|
+ rend: function() {
|
|
|
|
+ // run prep on all cells to get max col widths
|
|
|
|
+ for (var tsec in this.c)
|
|
|
|
+ for (var row in this.c[tsec].c)
|
|
|
|
+ for (var cell in this.c[tsec].c[row].c)
|
|
|
|
+ this.c[tsec].c[row].c[cell].prep();
|
|
|
|
+
|
|
|
|
+ return this.supr();
|
|
|
|
+ }
|
|
|
|
+ }) : lib.tblk.extend();
|
|
|
|
+
|
|
|
|
+ lib.thead = cfg.gfm_tbls ? lib.cblk.extend({
|
|
|
|
+ wrap: ["\n", function(kids) {
|
|
|
|
+ var buf = "";
|
|
|
|
+ for (var i in this.p.cols) {
|
|
|
|
+ var col = this.p.cols[i],
|
|
|
|
+ al = col.a[0] == "c" ? ":" : " ",
|
|
|
|
+ ar = col.a[0] == "r" || col.a[0] == "c" ? ":" : " ";
|
|
|
|
+
|
|
|
|
+ buf += (i == 0 && cfg.tbl_edges ? "|" : "") + al + rep("-", col.w) + ar + (i < this.p.cols.length-1 || cfg.tbl_edges ? "|" : "");
|
|
|
|
+ }
|
|
|
|
+ return "\n" + trim12(buf);
|
|
|
|
+ }]
|
|
|
|
+ }) : lib.ctblk.extend();
|
|
|
|
+
|
|
|
|
+ lib.tbody = cfg.gfm_tbls ? lib.cblk.extend() : lib.ctblk.extend();
|
|
|
|
+
|
|
|
|
+ lib.tfoot = cfg.gfm_tbls ? lib.cblk.extend() : lib.ctblk.extend();
|
|
|
|
+
|
|
|
|
+ lib.tr = cfg.gfm_tbls ? lib.cblk.extend({
|
|
|
|
+ wrapK: [cfg.tbl_edges ? "| " : "", cfg.tbl_edges ? " |" : ""],
|
|
|
|
+ }) : lib.ctblk.extend();
|
|
|
|
+
|
|
|
|
+ lib.th = cfg.gfm_tbls ? lib.inl.extend({
|
|
|
|
+ guts: null,
|
|
|
|
+ // TODO: DRY?
|
|
|
|
+ wrap: [function() {
|
|
|
|
+ var col = this.p.p.p.cols[this.i],
|
|
|
|
+ spc = this.i == 0 ? "" : " ",
|
|
|
|
+ pad, fill = col.w - this.guts.length;
|
|
|
|
+
|
|
|
|
+ switch (col.a[0]) {
|
|
|
|
+ case "r": pad = rep(" ", fill); break;
|
|
|
|
+ case "c": pad = rep(" ", Math.floor(fill/2)); break;
|
|
|
|
+ default: pad = "";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return spc + pad;
|
|
|
|
+ }, function() {
|
|
|
|
+ var col = this.p.p.p.cols[this.i],
|
|
|
|
+ edg = this.i == this.p.c.length - 1 ? "" : " |",
|
|
|
|
+ pad, fill = col.w - this.guts.length;
|
|
|
|
+
|
|
|
|
+ switch (col.a[0]) {
|
|
|
|
+ case "r": pad = ""; break;
|
|
|
|
+ case "c": pad = rep(" ", Math.ceil(fill/2)); break;
|
|
|
|
+ default: pad = rep(" ", fill);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return pad + edg;
|
|
|
|
+ }],
|
|
|
|
+ prep: function() {
|
|
|
|
+ this.guts = this.rendK(); // pre-render
|
|
|
|
+ this.rendK = function() {return this.guts};
|
|
|
|
+
|
|
|
|
+ var cols = this.p.p.p.cols;
|
|
|
|
+ if (!cols[this.i])
|
|
|
|
+ cols[this.i] = {w: null, a: ""}; // width and alignment
|
|
|
|
+ var col = cols[this.i];
|
|
|
|
+ col.w = Math.max(col.w || 0, this.guts.length);
|
|
|
|
+ if (this.e.align)
|
|
|
|
+ col.a = this.e.align;
|
|
|
|
+ },
|
|
|
|
+ }) : lib.ctblk.extend();
|
|
|
|
+
|
|
|
|
+ lib.td = lib.th.extend();
|
|
|
|
+
|
|
|
|
+ lib.txt = lib.inl.extend({
|
|
|
|
+ initK: function()
|
|
|
|
+ {
|
|
|
|
+ this.c = this.e.textContent.split(/^/gm);
|
|
|
|
+ },
|
|
|
|
+ rendK: function()
|
|
|
|
+ {
|
|
|
|
+ var kids = this.c.join("").replace(/\r/gm, "");
|
|
|
|
+
|
|
|
|
+ // this is strange, cause inside of code, inline should not be processed, but is?
|
|
|
|
+ if (!(this.p instanceof lib.code || this.p instanceof lib.pre)) {
|
|
|
|
+ kids = kids
|
|
|
|
+ .replace(/^\s*#/gm,"\\#")
|
|
|
|
+ .replace(/\*/gm,"\\*");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (this.i == 0)
|
|
|
|
+ kids = kids.replace(/^\n+/, "");
|
|
|
|
+ if (this.i == this.p.c.length - 1)
|
|
|
|
+ kids = kids.replace(/\n+$/, "");
|
|
|
|
+ return kids;
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+/*!
|
|
|
|
+ * klass: a classical JS OOP façade
|
|
|
|
+ * https://github.com/ded/klass
|
|
|
|
+ * License MIT (c) Dustin Diaz & Jacob Thornton 2012
|
|
|
|
+ */
|
|
|
|
+!function(a,b){typeof define=="function"?define(b):typeof module!="undefined"?module.exports=b():this[a]=b()}("klass",function(){function f(a){return j.call(g(a)?a:function(){},a,1)}function g(a){return typeof a===c}function h(a,b,c){return function(){var d=this.supr;this.supr=c[e][a];var f=b.apply(this,arguments);return this.supr=d,f}}function i(a,b,c){for(var f in b)b.hasOwnProperty(f)&&(a[f]=g(b[f])&&g(c[e][f])&&d.test(b[f])?h(f,b[f],c):b[f])}function j(a,b){function c(){}function l(){this.init?this.init.apply(this,arguments):(b||h&&d.apply(this,arguments),j.apply(this,arguments))}c[e]=this[e];var d=this,f=new c,h=g(a),j=h?a:this,k=h?{}:a;return l.methods=function(a){return i(f,a,d),l[e]=f,this},l.methods.call(l,k).prototype.constructor=l,l.extend=arguments.callee,l[e].implement=l.statics=function(a,b){return a=typeof a=="string"?function(){var c={};return c[a]=b,c}():a,i(this,a,d),this},l}var a=this,b=a.klass,c="function",d=/xyz/.test(function(){xyz})?/\bsupr\b/:/.*/,e="prototype";return f.noConflict=function(){return a.klass=b,this},a.klass=f,f});
|