Example #1
0
function markdownizeItem(item) {
	if (item.details && item.details.message) {
		item.details.message = markdown(item.details.message, true, allowedHtml, null, true);
	}
	if (item.description) {
		item.description = markdown(item.description, true, allowedHtml, null, true);
	}
	return item;
}
Example #2
0
  initialize: function() {
    if (this.has("contents")) {
      var i, len, parts, key, val, posttags;
      var obj = { contents: '' };
      var docs = this.get('contents').split('\n\n');
      var lines = docs[0].split('\n');

      if(this.has('editfrag')) {
        obj.editurl = paths.githuburl + this.get('editfrag') + '.md';
        obj.slug = this.get('editfrag');
      }

      for (i = 0, len = lines.length; i < len; i++) {
        parts = lines[i].trim().split(':');

        if (parts.length < 2) {
          console.error(lines);
          throw new Error('Invalid key: val ... ' + obj.slug);
        }

        key = parts[0];
        val = parts.slice(1).join(':').trim();

        if(key == 'tags') {
          posttags = val.split(' ');

          //if it is not whitespace separated it must be comma separated
          if(posttags.length === 1) {
            posttags.join(' ').split(',');
          }
          posttags = posttags.map(function(tag) {
            tag = tag.trim();

            //catch use of tags like polyfill, gtie9
            tag = /([^,]*)/.exec(tag)[1];
            return tag;

          });
          val = posttags.join(' ');
        }

       //if(key == 'kind') {
       // obj.moreurl = paths.caniuseurl + obj.slug;
       //}

        obj[key] = (key === 'polyfillurls') ?  "" + Markdown(val) : "" + val.trim();
      }

      obj.contents = "" + Markdown(docs.slice(1).join("\n\n"));


      // Update the model to use the metadata and contents
      this.set(obj);
    }
  }
Example #3
0
	var comment = function(link, user, text, imagedata, callback) {
		var md = require("node-markdown").Markdown;
		text = md(text, true, 'em|strong|strike|a|blockquote|p', {'a':'href'});
		db.createComment(link, text, user.type, (user.type === userpost.USER_ANONYMOUS ? user.name : user.id),
				function(err, result) {
			if (err) {
				callback(err, null);
				
			} else {
				var data = {
					comment: text,
					antiquity: 'justo ahora'
				};
				data[user.type === userpost.USER_ANONYMOUS ? 'submitter_ref' : 'username'] = user.name;
				
				if (typeof imagedata != 'undefined' && imagedata !== null && imagedata.length > 0) {
					saveImageData(result.id, imagedata, function() { callback(null, data); });
					
				} else {
					callback(null, data);
					
				}
				
			}
		});
	};
                        fs.readFile(path_author_json, 'utf8', function (err3, author_json) {
                            if (err3) {
                                res.send('Error loading JSON author file');
                            }
                            else {
                                hangout_obj.href = '/hangout/' + req.params.slug;

                                // set markdown to html content in article object
                                hangout_obj.content = md(hangout_markdown);

                                // set date from string reading
                                hangout_obj.date = moment(hangout_obj.date).fromNow();

                                if (hangout_obj.update != "") {
                                    hangout_obj.update = moment(hangout_obj.update).fromNow();
                                }

                                // set author object
                                var author_obj = JSON.parse(author_json);

                                // set md5 hash to load picture from gravatar.com
                                author_obj.picture = crypto.createHash('md5').update(author_obj.email).digest("hex");

                                // set author object on hangout object
                                hangout_obj.author = author_obj;

                                // load article template with hangout object
                                res.render('hangout', { data: hangout_obj });
                            }
                        });
Example #5
0
    Topic.update({ _id: topic._id }, { $set: { visit_count: topic.visit_count } }, function(err){
      
      // Markdown转HTML
      topic.content = markdown(topic.content);

      res.render('topics/show', { topic: topic });
    });
                        fs.readFile(path_author_json, 'utf8', function (err3, author_json) {
                            if (err3) {
                                res.send('Error loading JSON new file');
                            }
                            else {
                                // set markdown to html content in new object
                                new_obj.content = md(new_markdown);

                                // set date from string reading
                                new_obj.date = moment(new_obj.date).fromNow();

                                if (new_obj.update != "") {
                                    new_obj.update = moment(new_obj.update).fromNow();
                                }

                                // set author object
                                var author_obj = JSON.parse(author_json);

                                // set md5 hash to load picture from gravatar.com
                                author_obj.picture = crypto.createHash('md5').update(author_obj.email).digest("hex");

                                // set author object on new object
                                new_obj.author = author_obj;

                                // load article template with new object
                                res.render('new', { data: new_obj });
                            }
                        });
Example #7
0
	fs.readFile('./README.md', function (err, data) {
		res.write('<!DOCTYPE html><html><head>');
		res.write('<title>Unofficial Google+ API compatible with Google+ API</title>');
		res.write('</head><body>');
		res.write(md(data.toString()));
		res.end('</body></html>');
	});
Example #8
0
    fs.readFile('templates/_' + v.type + '.mustache', 'utf8', function(err, data) {
      if (err) throw err;
      if (v.type == 'text')
        v.content = md(v.content.replace(/>>/g,'</p><p>'));

      renders[i] = mustache.render(data, v);
    });
Example #9
0
	app.get('/repositories/info/:repo', function(req, res) {
		var info = {},
		    readme,
		    url = config['repository_dir'] + '/' + req.param('repo') + '.git',
		    branch = null;
		
		if (fs.existsSync(config['repository_dir'] + '/' + req.param('repo') + '/README.md')) {
			readme = md(fs.readFileSync(config['repository_dir'] + '/' + req.param('repo') + '/README.md', 'utf8'));
		} else {
			readme = null;
		}
		
		git.tree(config['repository_dir'] + '/' + req.param('repo'), function(data) {
			branch = data;
			if (data['error']) {
				res.writeHead(500);
			} else {
				res.writeHead(200);
			}
			info.readme = readme;
			info.url = url;
			info.branches = branch;
			info.server = mode;
			res.write(JSON.stringify(info));
			res.end();
		});
	});
Example #10
0
		topic.save(function(err){
			if(!topic.content_is_html){
				// trans Markdown to HTML
				topic.content = Markdown(topic.content,true);
			}
			// format date
			topic.friendly_create_at = Util.format_date(topic.create_at,true);
			topic.friendly_update_at = Util.format_date(topic.update_at,true);

			topic.tags = tags;
			topic.author = author;
			topic.replies = replies;

			if(!req.session.user){
				proxy.trigger('topic',topic);
			}else{
				TopicCollect.findOne({user_id:req.session.user._id, topic_id:topic._id},function(err,doc){
					if(err) return next(err);
					topic.in_collection = doc;
					proxy.trigger('topic',topic);
				});
			}
		
			var opt = {limit:5, sort:[['last_reply_at','desc']]};
			get_topics_by_query({author_id:topic.author_id,_id:{'$nin':[topic._id]}},opt,function(err,topics){
				if(err) return next(err);
				proxy.trigger('author_other_topics',topics);
			});
			opt = {limit:5, sort:[['create_at','desc']]};
			get_topics_by_query({reply_count:0},opt,function(err,topics){
				if(err) return next(err);
				proxy.trigger('no_reply_topics',topics);
			});
		});
Example #11
0
  initialize: function() {
    if (this.has("contents")) {
      var i, len, parts, key, val, posttags;
      var obj = { contents: '' };
      var docs = this.get('contents').split('\n\n');
      var lines = docs[0].split('\n');

      if(this.has('editfrag')) {
        obj.editurl = paths.githuburl + this.get('editfrag') + '.md';
        obj.slug = this.get('editfrag');
      }

      for (i = 0, len = lines.length; i < len; i++) {
        parts = lines[i].trim().split(':');
        
        if (parts.length < 2) {
          console.error(lines);
          throw new Error('Invalid key: val');  
        }
       
        key = parts[0];
        val = parts.slice(1).join(':').trim();
       
        if(key == 'tags') {
          posttags = val.split(' ');
          posttags.forEach(function(tag) {
            tag = tag.trim();
            if(tag && featuretags.indexOf(tag) == -1 && tag !== 'none') {
              featuretags.push(tag);
            }
          });
        }  
       
       if(key == 'kind') {
        obj.moreurl = paths.caniuseurl + obj.slug;
       } 
              
        obj[key] = (key === 'polyfillurls') ?  "" + Markdown(val) : "" + val.trim();
      }

      obj.contents = "" + Markdown(docs.slice(1).join("\n\n"));

       
      // Update the model to use the metadata and contents
      this.set(obj);
    }
  }
Example #12
0
    toMarkdown: function(text) {
        text = md.Markdown(text).replace(/'/g,'&#39;');
        text = text.replace(/<blockquote>/g, '<aside>').
                    replace(/<\/blockquote>/g, '</aside>');

        return text.replace(/<aside>\s+<p><strong>ES5/g,
                            '<aside class="es5"><p><strong>ES5');
    },
Example #13
0
 compile: function(str, options){
   var html = md(str);
   return function(locals){
     return html.replace(/\{([^}]+)\}/g, function(_, name){
       return locals[name];
     });
   };
 }
Example #14
0
 modMd.getDocumentByDir(page.file,function(err,data){
     re.post.title = data.metas['title'] || data.title;
     re.post.url = data.metas['url'] || data.url;
     re.post.tags = data.metas['tags'] ? data.metas['tags'].split(",") : [];
     re.post.mtime = data.mtime.format('cnDate');
     re.post.body = md(data.body);
     callback(re);
 });
Example #15
0
  getChangelog: function() {
    if (!Application.changelog) {
      var changelog = fs.readFileSync(process.cwd() + '/node_modules/sequelize/changelog.md').toString()
      Application.changelog = md(changelog)
    }

    return Application.changelog
  }
Example #16
0
 },function(post){
     var data = {};
     data.title = post.metas['title'] || post.title;
     data.url = post.metas['url'] || post.url;
     data.tags = post.metas['tags'] ? post.metas['tags'].split(",") : [];
     data.mtime = post.mtime.format('cnDate');
     data.summary = md(post.summary);
     re.posts.push(data);
 });
Example #17
0
app.use(function(req, res){
    if (req.path.match('^(?:[a-zA-Z0-9-_/]*\.?)*$') && fs.existsSync(path.resolve("./web" + req.path + ".hbs"))) {
        var template = Handlebars.compile(fs.readFileSync(path.resolve("./web" + req.path + ".hbs")).toString());
        var data = { title: config.title, description: md(fs.readFileSync("./description.md").toString()) };
        res.type("text/html").send(template(data));
    } else if (req.path.match('^(?:[a-zA-Z0-9-_/]*\.?)*$') && fs.existsSync(path.resolve("./web" + req.path))) {
        res.sendfile(path.resolve("./web" + req.path));
    } else res.status(404).end();
});
Example #18
0
 .then(function (markdown) {
   try {
     var html = md(markdown);
     deferred.resolve(html);
   } catch (e) {
     logger.error('parsing of markdown for page $s: $s', pageName, e);
     deferred.reject(e);
   }
 })
Example #19
0
everyone.now.sendMessage = function(message) {
	if(this.user.name) {
		everyone.now.chats.push({
			user: this.user.name,
			message: markdown(sanitizer.escape(message)),
			time: (new Date()).toTimeString()
		});
	}
}
Example #20
0
 load("http://cfp.breizhcamp.org/accepted/talk/" + talk.id).then(function(talkDetail) {
     send(baseUrl + '/r' + voxxrinPres.uri, _.extend(voxxrinPres,
         {
             "tags":talkDetail.tags,
             "summary":md(talkDetail.description)
         })).then(function () {
             console.log('PRESENTATION: ', voxxrinPres.title, daySchedule.id, voxxrinPres.slot)
         }).fail(onFailure);
 });
 fs.readFile("./AllWordInfo.md", function(err, data){
   if (err) 
     console.log('read file error!');
   else {
     str = md(String(data));
     res.send(String(str));
     //res.send(String(data));
   }
 }); // readFile
Example #22
0
 fs.readFile(path,'utf8', function (err, data) {
     if (err) {
         self.sendError_(req, res, err);
     }
     else {
         var html = md(data); 
         res.end(html);   
     }
 });
Example #23
0
 topics.forEach(function (topic) {
   rss_obj.channel.item.push({
     title: topic.title,
     link: config.rss.link + '/topic/' + topic._id,
     guid: config.rss.link + '/topic/' + topic._id,
     description: markdown(topic.content, true),
     author: topic.author.name,
     pubDate: topic.create_at.toUTCString()
   });
 });
Example #24
0
File: api.js Project: irini/taina
		Post.findBySlug(slug, function(err, post) {
			var obj = new Post(post);
			var data = obj.content;
			res.render('website/pages/post_show', {
				page_title: obj.title,
				page_slug: 'post',
				post: post,
				content: md(data)
			});
		});
Example #25
0
			collection.findOne(query,function (err,doc){
				mongodb.close();
				if(err){
					return callback(err,null);
				}
				//解析 markdown 为 html
				doc.originPost = doc.post;
				doc.post = markdown(doc.post,true);
				callback(null,doc);
			});
Example #26
0
 fs.readFile('CREDITS.md', 'utf-8', function (err, credits) {
   if (err) {
     logger.err("Error reading CREDITS.md", err);
     res.send("Error!");
     return;
   }
   var html = md(credits);
   res.header("Content-Type", "text/html");
   res.send(html);
 });
Example #27
0
    transform: function(item, context) {
      for (var i in engine.engines) {
        var e = engine.engines[i];

        if (typeof item._filetype != "undefined" && item._filetype == e.name) {
          return e.handler(item.content, context);
        }
      }

      return markdown(item.content);
    },
Example #28
0
 require('../models/article').get(id , function(data){
     if( !data ){
         res.redirect('/share/404');
         return;
     }
     data.article = md( data.article );
     data.common = require('./common').fetch();
     if( data.author == data.common.uname || data.common.uname == config.admin ){
         data.admin = true;
     }
     res.render( '../views/article.ejs' , data );
 });
Example #29
0
    done: function (err, win) {
      if (err) {
        res.send('Error!');
      } else {

        var $ = win.$;

        postBody = md($('html body').html());

        res.render('post', {post: postBody }); 
      }
    }
Example #30
0
function formatPreview(query, str) {
  if(str[0] === '#') return;
  
  var words = query.split(/\s/);
  str = md(str);
  
  words.forEach(function (w) {
    var r = '(' + w + ')';
    str = str.replace(RegExp(r, 'gi'), '<strong class="kw-match">$1</strong>');
  });
  
  return str;
}