From b8e1f25baf959fb7430901bdcf1fa67622212bb5 Mon Sep 17 00:00:00 2001 From: Christian Mueller Date: Fri, 3 Jan 2014 20:59:10 +0100 Subject: [PATCH] switched to JS markdown processing only --- LANDING.md | 2 +- README.md | 6 +--- project.clj | 6 ++-- resources/public/js/main.js | 29 ++++++++++------ src/NoteHub/views/common.clj | 65 ++++++++++++++++++------------------ src/NoteHub/views/pages.clj | 27 ++++----------- 6 files changed, 60 insertions(+), 75 deletions(-) diff --git a/LANDING.md b/LANDING.md index ec7f27f..26f4947 100644 --- a/LANDING.md +++ b/LANDING.md @@ -6,7 +6,7 @@ ## About [NoteHub](http://notehub.org) is a free and hassle-free anonymous pastebin for markdown pages, intended for anonymous one-off publishing. -Send your feedback and comments directly to [@gravitydenier](http://twitter.com/gravitydenier) or open an [issue](https://github.com/gravitydenier/NoteHub/issues) on GitHub. +Send your feedback and comments directly to [@gravitydenier](http://twitter.com/gravitydenier) or open an [issue](https://github.com/chmllr/NoteHub/issues) on GitHub. ## Features - **Color Themes**: specify the color scheme by appending the corresponding parameter to the URL: diff --git a/README.md b/README.md index bdedfa6..23f1a2b 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,3 @@ -## News - - - September 2013: Solarized color theme [added](https://github.com/chmllr/NoteHub/pull/4) (thanks Brandon!) ([Demo](http://notehub.org/2012/6/16/how-notehub-is-built?theme=solarized)) - ## About [NoteHub](http://notehub.org) is a free and hassle-free anonymous hosting for markdown pages. It can be used for publishing of markdown-formatted texts. @@ -10,7 +6,7 @@ NoteHub was an one-app-one-language [experiment](http://notehub.org/2012/6/16/ho The [source code](https://github.com/chmllr/NoteHub) can be found on GitHub. NoteHub's persistence layer is based on the key-value store [redis](http://redis.io). Currently, NoteHub is hosted for free on [Heroku](http://heroku.com). -Send your feedback and comments directly to [@gravitydenier](http://twitter.com/gravitydenier) or open an [issue](https://github.com/gravitydenier/NoteHub/issues) on GitHub. +Send your feedback and comments directly to [@gravitydenier](http://twitter.com/gravitydenier) or open an [issue](https://github.com/chmllr/NoteHub/issues) on GitHub. ## Why? Not every person, who occasionally wants to express some thoughts, needs a blog. diff --git a/project.clj b/project.clj index 5541cb4..d630a7c 100644 --- a/project.clj +++ b/project.clj @@ -1,11 +1,9 @@ -(defproject NoteHub "0.1.0-SNAPSHOT" +(defproject NoteHub "2.0.0" :description "A free and anonymous hosting for markdown pages." - :dependencies [[org.clojure/clojure "1.3.0"] + :dependencies [[org.clojure/clojure "1.5.1"] [hiccup "1.0.0"] [ring/ring-core "1.1.0"] [clj-redis "0.0.12"] - [org.pegdown/pegdown "1.1.0"] [noir "1.3.0-beta1"]] :jvm-opts ["-Dfile.encoding=utf-8"] :main NoteHub.server) - diff --git a/resources/public/js/main.js b/resources/public/js/main.js index a557571..5be8624 100644 --- a/resources/public/js/main.js +++ b/resources/public/js/main.js @@ -27,17 +27,24 @@ var updatePreview = function(){ var content = $draft.value; var delay = Math.min(timerDelay, timerDelay * (content.length / 400)); timer = setTimeout(function(){ - show($dashed_line); - show($input_elems); - $preview.innerHTML = marked(content); - }, delay); + show($dashed_line); + show($input_elems); + $preview.innerHTML = marked(content); + }, delay); }; -if($action.value == "update") updatePreview(); else $draft.value = ""; -if(iosDetected) $draft.className += " ui-border"; else $draft.focus(); -$draft.onkeyup = updatePreview; -$("publish-button").onclick = function(e) { - if($plain_password.value != "") $password.value = md5($plain_password.value); - $plain_password.value = null; - $("session-value").value = hash($draft.value + $("session-key").value); +if($action){ + if($action.value == "update") updatePreview(); else $draft.value = ""; + $draft.onkeyup = updatePreview; + $("publish-button").onclick = function(e) { + if($plain_password.value != "") $password.value = md5($plain_password.value); + $plain_password.value = null; + $("session-value").value = hash($draft.value + $("session-key").value); + } + if(iosDetected) $draft.className += " ui-border"; else $draft.focus(); +} + +var mdDocs = document.getElementsByClassName("markdown"); +for(var i = 0; i < mdDocs.length; i++){ + mdDocs[i].innerHTML = marked(mdDocs[i].innerHTML); } diff --git a/src/NoteHub/views/common.clj b/src/NoteHub/views/common.clj index 1d041ba..8a76efa 100644 --- a/src/NoteHub/views/common.clj +++ b/src/NoteHub/views/common.clj @@ -16,39 +16,38 @@ ; Creates the main html layout (defpartial generate-layout - [params title & content] - ; for the sake of security: escape all symbols of the param values - (let [params (into {} (for [[k v] params] [k (escape-html v)]))] - (html5 - [:head - [:title (print-str (get-message :name) "—" title)] - [:meta {:charset "UTF-8"}] - ; generating a link to google's webfonts - [:link {:href - (clojure.string/replace - (str "http://fonts.googleapis.com/css?family=" - (apply - str - (interpose "|" - ; ugly thing, but it cannot be avoided since these - ; fonts have to be loaded (independently of CSS) - (concat ["PT+Serif:700" "Noticia+Text:700"] - (vals (select-keys params - [:header-font :text-font]))))) - "&subset=latin,cyrillic") " " "+") - :rel "stylesheet" - :type "text/css"}] - ; generating the global CSS - [:link {:rel "stylesheet" :type "text/css" :href "/style.css"}] - ; google analytics code should appear in prod mode only - (if-not (dev-mode?) (include-js "/js/google-analytics.js"))] - [:body content - ; we only need JS during a new note creation, so don't render it otherwise - (when (params :js) - (html - (include-js "/js/md5.js") - (include-js "/js/marked.js") - (include-js "/js/main.js")))]))) + [params title & content] + ; for the sake of security: escape all symbols of the param values + (let [params (into {} (for [[k v] params] [k (escape-html v)]))] + (html5 + [:head + [:title (print-str (get-message :name) "—" title)] + [:meta {:charset "UTF-8"}] + ; generating a link to google's webfonts + [:link {:href + (clojure.string/replace + (str "http://fonts.googleapis.com/css?family=" + (apply + str + (interpose "|" + ; ugly thing, but it cannot be avoided since these + ; fonts have to be loaded (independently of CSS) + (concat ["PT+Serif:700" "Noticia+Text:700"] + (vals (select-keys params + [:header-font :text-font]))))) + "&subset=latin,cyrillic") " " "+") + :rel "stylesheet" + :type "text/css"}] + ; generating the global CSS + [:link {:rel "stylesheet" :type "text/css" :href "/style.css"}] + ; google analytics code should appear in prod mode only + (if-not (dev-mode?) (include-js "/js/google-analytics.js"))] + [:body content + ; we only need JS during a new note creation, so don't render it otherwise + (html + (include-js "/js/md5.js") + (include-js "/js/marked.js") + (include-js "/js/main.js"))]))) (defn layout "Generates the main html layout" diff --git a/src/NoteHub/views/pages.clj b/src/NoteHub/views/pages.clj index 275ffb8..f0c02d7 100644 --- a/src/NoteHub/views/pages.clj +++ b/src/NoteHub/views/pages.clj @@ -14,16 +14,7 @@ [noir.core :only [defpage defpartial]] [noir.statuses]) (:import - [java.util Calendar] - [org.pegdown PegDownProcessor])) - -; Create a new Object of the MD-processor -(def md-processor - (PegDownProcessor.)) - -; Markdown -> HTML mapper -(defn md-to-html [md-text] - (.markdownToHtml md-processor md-text)) + [java.util Calendar])) (defn get-hash "A simple hash-function, which computes a hash from the text field @@ -57,7 +48,7 @@ (defn- wrap [short-url params md-text] (when md-text (layout params (params :title) - [:article.bottom-space (md-to-html md-text)] + [:article.bottom-space.markdown md-text] (let [links (map #(link-to (if (= :short-url %) (url short-url) @@ -78,11 +69,6 @@ ; Routes ; ====== -; This function answers to an AJAX request: it gets a session key and a markdown text. -; It returns the html code of the provided markdown and a new session key. -(defpage [:post "/preview"] {:keys [session-key draft]} - (str "{ preview: " (escape (md-to-html draft) {\" "\\\""}) "}")) - ; Landing Page (defpage "/" {} (layout (get-message :page-title) @@ -92,16 +78,15 @@ [:br] [:a.landing-button {:href "/new" :style "color: white"} (get-message :new-page)]] [:div#dashed-line] - ; dynamically generates three column, retrieving corresponding messages - [:article.helvetica-neue.bottom-space {:style "font-size: 1em"} - (md-to-html (slurp "LANDING.md"))] - [:div.centered.helvetica-neue (md-to-html (get-message :footer))])) + [:article.helvetica-neue.bottom-space.markdown {:style "font-size: 1em"} + (slurp "LANDING.md")] + [:div.centered.helvetica-neue.markdown (get-message :footer)])) ; input form for the markdown text with a preview area (defpartial input-form [form-url command fields content passwd-msg] (let [css-class (when (= :publish command) :hidden)] (layout {:js true} (get-message :new-note) - [:article#preview " "] + [:article#preview.markdown " "] [:div#dashed-line {:class css-class}] [:div.central-element.helvetica-neue {:style "margin-bottom: 3em"} (form-to {:autocomplete :off} [:post form-url]