This repository has been archived by the owner on Jul 11, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from moose-team/updates
make it work better
- Loading branch information
Showing
10 changed files
with
130 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,7 @@ | ||
language: node_js | ||
node_js: | ||
- 'iojs' | ||
sudo: false | ||
- '4' | ||
- '5' | ||
cache: | ||
directories: | ||
- node_modules | ||
script: | ||
- npm test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,64 @@ | ||
module.exports = require('./lib/rich-message.js') | ||
module.exports = makeRichMessage | ||
module.exports.mergeMessages = mergeMessages | ||
module.exports.timeago = timeago | ||
|
||
var emoji = require('markdown-it-emoji') | ||
var ghlink = require('ghlink') | ||
var higlight = require('highlight.js') | ||
var MarkdownIt = require('markdown-it') | ||
var twemoji = require('twemoji') | ||
var moment = require('moment') | ||
|
||
var CAT_URL = 'https://cdn.rawgit.com/moose-team/rich-message/master/cat.png' | ||
|
||
var md = new MarkdownIt({ | ||
linkify: true, | ||
highlight: function (str, lang) { | ||
if (lang && higlight.getLanguage(lang)) { | ||
try { | ||
return higlight.highlight(lang, str).value | ||
} catch (err) {} | ||
} | ||
|
||
try { | ||
return higlight.highlightAuto(str).value | ||
} catch (err) {} | ||
|
||
return '' // use external default escaping | ||
} | ||
}).use(emoji) | ||
|
||
md.renderer.rules.emoji = function (token, index) { | ||
return twemoji.parse(token[index].content) | ||
} | ||
|
||
function makeRichMessage (message, username) { | ||
message.anon = /Anonymous/i.test(message.username) | ||
message.avatar = message.anon | ||
? CAT_URL | ||
: `https://github.com/${message.username}.png` | ||
message.timeago = timeago(message.timestamp) | ||
|
||
message.text = message.text.replace(/(^|\s)(#[a-zA-Z0-9]+)(?=$|\s)/g, '$1[$2]($2)') | ||
message.html = md.render(message.text) | ||
message.html = message.html.replace(/\n/g, '<p></p>') | ||
message.html = ghlink(message.html, { format: 'html' }) | ||
|
||
var highlight = (message.text.indexOf(username) !== -1) | ||
var classStr = highlight ? ' class="highlight"' : '' | ||
message.html = `<div${classStr}>${message.html}</div>` | ||
|
||
return message | ||
} | ||
|
||
function mergeMessages (message1, message2) { | ||
message1.text += '\n' + message2.text | ||
message1.html += '<p></p>' + message2.html | ||
return message1 | ||
} | ||
|
||
function timeago (milliseconds) { | ||
var timeago = moment(milliseconds).calendar() | ||
if (timeago.indexOf('Today at ') === 0) return timeago.substring(9) | ||
return timeago | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters