all repos — litestore @ c8cd1088eb40ed442c48cb6fd3305334284d851a

A minimalist nosql document store.

Customized marked to handle Discount class blocks and pseudo-protocols.
* Closes #18.
h3rald h3rald@h3rald.com
Sun, 22 Mar 2015 17:42:15 +0100
commit

c8cd1088eb40ed442c48cb6fd3305334284d851a

parent

6bbdd99d3baa71ddf471fee271e27ecaa16ffce8

3 files changed, 43 insertions(+), 2 deletions(-)

jump to
M app/js/models.jsapp/js/models.js

@@ -10,7 +10,7 @@ return m.request({

method: "GET", url: "md/"+id+".md", deserialize: function(value) {return value;} - }).then(function(content){ return marked(content);}); + }).then(function(content){ return u.markdown(content);}); }; Info.get = function(){
M app/js/utils.jsapp/js/utils.js

@@ -3,6 +3,42 @@ 'use strict';

var app = window.LS || (window.LS = {}); var u = app.utils = {}; + + u.markdown = function(s) { + var hs = new marked.Renderer(); + var md = new marked.Renderer(); + hs.blockquote = function(q){ + var lines = q.split("\n"); + if (lines[0]){ + var r = /^<p>\s*%(.+?)%\s*/; + var matches = lines[0].match(r); + if (matches) { + var klass = matches[1]; + if (klass){ + return "<div class=\""+klass+"\">\n"+q.replace(r, "<p>")+"\n</div>"; + } + } + } + return md.blockquote(q); + }; + hs.link = function(href, title, text){ + var components = href.match(/^([a-z]+):(.+)$/); + if (components && components.length > 2){ + var protocol = components[1]; + var value = components[2]; + if (protocol === "class"){ + return "<span class=\""+value+"\">"+text+"</span>"; + } else if (protocol === "id"){ + return "<a id=\""+value+"\">"+text+"</a>"; + } else if (protocol === "abbr"){ + return "<abbr title=\""+value+"\">"+text+"</abbr>"; + } + } + return md.link(href, title, text); + }; + return marked(s, {renderer: hs}); + }; + /** * mod object: * @property vm a view-model (with init function)

@@ -177,4 +213,4 @@ return function(xhr) {

xhr.setRequestHeader("Content-Type", contentType); }; }; -}()); +}());
M app/md/overview.mdapp/md/overview.md

@@ -2,6 +2,11 @@ ## Overview

LiteStore is a self-contained, RESTful, multi-format document store written in [Nim](http://www.nim-lang.org). It aims to be a very simple and lightweight backend suitable for prototypes and testing REST APIs. +> %note% +> Note +> +> This is a note. + ### Rationale If you ever wanted to build a simple single-page application in your favorite framework, just to try something out or as a prototype, you inevitably had to answer the question _"What backend should I use?"_