diff --git a/TODO.md b/TODO.md index 80ff07d..98a7677 100644 --- a/TODO.md +++ b/TODO.md @@ -2,7 +2,6 @@ TODO: - have the ability to link to other files - have an alert that asks if user wants to save changes when they navigate away -- have syntax highlighting of code - have the ability to delete files and folders - maybe have a better markdown editor - create public API @@ -19,4 +18,5 @@ FINISHED: - have the ability to create new folder - have different port support - have responsive design (just make it wider for larger screens) -- change design of formatted markdown files (**especially for links**) \ No newline at end of file +- change design of formatted markdown files (**especially for links**) +- have syntax highlighting of code diff --git a/lib/mdserver.js b/lib/mdserver.js index 71ef32f..f5d9399 100644 --- a/lib/mdserver.js +++ b/lib/mdserver.js @@ -1,14 +1,25 @@ var fs = require("fs"); var path = require("path"); var marked = require("marked"); +var hljs = require('highlight.js'); var allowedExtensions = require("./allowedExtensions"); var git = require("./git"); var nodewiki = require("../nodewiki"); +var languageOverrides = { + js: 'javascript', + clj: 'clojure', + html: 'xml' +} + marked.setOptions({ - gfm: true, - pendantic: false, - sanitize: true, + // gfm: true, + // pendantic: false, + // sanitize: true, + highlight: function(code, lang){ + if(languageOverrides[lang]) lang = languageOverrides[lang]; + return hljs.LANGUAGES[lang] ? hljs.highlight(lang, code).value : hljs.highlightAuto(code).value; + } }); @@ -30,7 +41,7 @@ function sendFile(file, directory, socket){ socket.emit('readFileReply', {fileContents: "", error: {error: true, reason: "file requested is not a markdown file"}}); } } - + function saveFile(file, directory, socket){ if (allowedExtensions.checkExtension(file.name) == true && typeof file.content != 'undefined'){ // only allow markdown files to be saved diff --git a/package.json b/package.json index a8a2137..51e9f58 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "nodewiki", - "version": "0.1.2", + "version": "0.1.3", "author": "Nafis Hossain ", "description": "A simple wiki that uses markdown files", "license": "MIT", @@ -16,8 +16,9 @@ "dependencies": { "connect": "2.3.x", "socket.io": "0.9.x", - "marked": "0.2.x", - "posix-getopt": "1.0.x" + "marked": "0.2.9", + "posix-getopt": "1.0.x", + "highlight.js": "7.3.x" }, "repository": { "type": "git", diff --git a/static/index.html b/static/index.html index 65dd915..275a80a 100644 --- a/static/index.html +++ b/static/index.html @@ -5,6 +5,7 @@ +