Skip to content

Commit

Permalink
added syntax highlight using highlight.js
Browse files Browse the repository at this point in the history
  • Loading branch information
Felix Chern committed Jun 24, 2013
1 parent baba158 commit 0fc1093
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 9 deletions.
4 changes: 2 additions & 2 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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**)
- change design of formatted markdown files (**especially for links**)
- have syntax highlighting of code
19 changes: 15 additions & 4 deletions lib/mdserver.js
Original file line number Diff line number Diff line change
@@ -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;
}
});


Expand All @@ -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
Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nodewiki",
"version": "0.1.2",
"version": "0.1.3",
"author": "Nafis Hossain <nhoss2@gmail.com>",
"description": "A simple wiki that uses markdown files",
"license": "MIT",
Expand All @@ -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",
Expand Down
1 change: 1 addition & 0 deletions static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<link rel="stylesheet" type="text/css" href="design/css.css">
<link href='http://fonts.googleapis.com/css?family=PT+Sans:400,400italic,700,700italic' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=PT+Mono' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="http://yandex.st/highlightjs/7.3/styles/default.min.css">
<script type="text/javascript" src="/jquery.js"></script>
<script type="text/javascript" src="/socketio.js"></script>
<script type="text/javascript" src="/socket.io/socket.io.js"></script>
Expand Down

0 comments on commit 0fc1093

Please sign in to comment.