Skip to content

Commit

Permalink
Revising code format.
Browse files Browse the repository at this point in the history
  • Loading branch information
tatsy committed Feb 7, 2015
1 parent 84d7b17 commit 94a09d1
Show file tree
Hide file tree
Showing 13 changed files with 267 additions and 249 deletions.
2 changes: 2 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

var express = require('express');
var app = express();
var http = require('http').Server(app);
Expand Down
8 changes: 4 additions & 4 deletions lib/article-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ var articleDir = './public/articles/';
exports.dir = articleDir;

/*
* get information text from ARTICLE_DIR/info.txt
*/
* get information text from ARTICLE_DIR/info.txt
*/
exports.getInfo = function(id) {
return JSON.parse(fs.readFileSync(articleDir + id + '/info.txt'));
};

/*
* get article list categorized its post month and day
*/
* get article list categorized its post month and day
*/
exports.getList = function(callback) {
var i;

Expand Down
4 changes: 2 additions & 2 deletions lib/connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ function onConnection(socket) {

socket.on('connected', function(articleInfo) {
var uploadDir = 'articles/' + articleInfo.id + '/upload';
uploadedFiles = getFilesWithCreatedOrder('./public/' + uploadDir);
var uploadedFiles = getFilesWithCreatedOrder('./public/' + uploadDir);
socket.emit('file list update', uploadedFiles);

socket.on('code update', function(code) {
Expand All @@ -134,7 +134,7 @@ function onConnection(socket) {
var uploadDir = 'articles/' + articleInfo.id + '/upload';
var noteStore = enutils.getNoteStore();
var rendered = renderCode(articleInfo.code, uploadDir, uploadDir);
var evData = enutils.ENMLize(rendered);
var evData = enutils.enmlize(rendered);
enutils.makeNote(noteStore, articleInfo.title, evData.enml, evData.resources, null, function() { socket.emit('save evernote success') });
});

Expand Down
6 changes: 3 additions & 3 deletions lib/en-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ function removeIdClass(code) {
return code;
}

function ENMLize(code) {
function enmlize(code) {
var i, after;

var enData = {
Expand Down Expand Up @@ -184,7 +184,7 @@ function ENMLize(code) {
do {
matchCode = regexCode.exec(code);
if(!matchCode) break;

var lineno = matchCode[1].split('\n').length;
var linenoStr = '';
for (i = 1; i <= lineno; i++) {
Expand Down Expand Up @@ -213,5 +213,5 @@ function ENMLize(code) {
return enData;
}

exports.ENMLize = ENMLize;
exports.enmlize = enmlize;
exports.removeIdClass = removeIdClass;
46 changes: 24 additions & 22 deletions lib/md-video.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,35 @@
'use strict';

var regex = {
link: new RegExp(/\$\[([\s\S]*?)\]\(([\s\S]*?)\)/)
link: new RegExp(/\$\[([\s\S]*?)\]\(([\s\S]*?)\)/)
};

function render(href, text) {
var imsizeReg = /([\s\S]+) =([0-9]*)x([0-9]*)/;
var match = imsizeReg.exec(href);
if(match) href = match[1];
var out = '<video src="' + href + '"';
var imsizeReg = /([\s\S]+) =([0-9]*)x([0-9]*)/;
var match = imsizeReg.exec(href);
if(match) href = match[1];
var out = '<video src="' + href + '"';

if(match) {
if(match[2] != '') {
out += ' width="' + match[2] + '"';
}
if(match[3] != '') {
out += ' height="' + match[3] + '"';
}
if(match) {
if(match[2] != '') {
out += ' width="' + match[2] + '"';
}
out += ' controls>';
if (text) {
out += text;
if(match[3] != '') {
out += ' height="' + match[3] + '"';
}
out += '</video>';
return out;
}
out += ' controls>';
if (text) {
out += text;
}
out += '</video>';
return out;
}

exports.marked = function(code) {
var match = null;
while(match = regex.link.exec(code)) {
code = code.replace(regex.link, render(match[2], match[1]));
}
return code;
var match = null;
while(match = regex.link.exec(code)) {
code = code.replace(regex.link, render(match[2], match[1]));
}
return code;
}

0 comments on commit 94a09d1

Please sign in to comment.