Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use highlight.js for syntax highlight #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 <[email protected]>",
"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