Skip to content

Commit a53da81

Browse files
committed
feat(hashtag & mentions): added support for hashtag & mentions
closes #161
1 parent d385ed2 commit a53da81

10 files changed

Lines changed: 107 additions & 6 deletions

File tree

demo/index.html

Lines changed: 10 additions & 2 deletions
Large diffs are not rendered by default.

dist/embed.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/embed.es2015.js

Lines changed: 30 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/embed.es2015.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/embed.js

Lines changed: 28 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/embed.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/js/main.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ import SlideShare from './modules/image/slideshare'
2121
import OpenGraph from './modules/openGraph'
2222
import Github from './modules/github'
2323

24+
import mentions from './modules/mentions';
25+
import hashtag from './modules/hashtag';
26+
2427
import regex from './modules/regex'
2528

2629
import {applyPlyr, applyVideoJS, playVideo, destroyVideos, baseEmbed} from './helpers'
@@ -41,6 +44,8 @@ var defaultOptions = {
4144
fontIcons : true,
4245
customFontIcons : [],
4346
highlightCode : false,
47+
mentions : false,
48+
hashtag : false,
4449
videoJS : false,
4550
videojsOptions : {
4651
fluid : true,
@@ -102,6 +107,10 @@ var defaultOptions = {
102107
},
103108
videoClickClass : 'ejs-video-thumb',
104109
customVideoClickHandler: false,
110+
mentionsUrl : function () {
111+
},
112+
hashtagUrl : function () {
113+
},
105114
beforeEmbedJSApply : function () {
106115
},
107116
afterEmbedJSApply : function () {
@@ -191,6 +200,12 @@ export default class EmbedJS {
191200
if (options.fontIcons) {
192201
output = new Smiley(output, options).process()
193202
}
203+
if (options.mentions) {
204+
output = mentions(output, options);
205+
}
206+
if (options.hashtag) {
207+
output = hashtag(output, options);
208+
}
194209

195210
[output, embeds] = baseEmbed(input, output, embeds, options, regex.ideone, 'ideone');
196211
[output, embeds] = baseEmbed(input, output, embeds, options, regex.plunker, 'plunker');

src/js/modules/hashtag.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import regex from './regex';
2+
3+
export default function (input, options) {
4+
const hRegex = regex.hashtag;
5+
return input.replace(hRegex,(match)=>{
6+
const username = match.split('#')[1];
7+
return options.hashtagUrl(username);
8+
})
9+
}

src/js/modules/mentions.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import regex from './regex';
2+
3+
export default function (input, options) {
4+
const mRegex = regex.mentions;
5+
return input.replace(mRegex,(match) => {
6+
const username = match.split('@')[1];
7+
return options.mentionsUrl(username);
8+
})
9+
}

src/js/modules/regex.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
const regex = {
2+
mentions : /\B@[a-z0-9_-]+/gi,
3+
hashtag : /\B#[a-z0-9_-]+/gi,
24
basicAudio : /((?:https?):\/\/\S*\.(?:wav|mp3|ogg))/gi,
35
soundCloud : /(soundcloud.com)\/[a-zA-Z0-9-_]+\/[a-zA-Z0-9-_]+/gi,
46
spotify : /spotify.com\/track\/[a-zA-Z0-9_]+/gi,

0 commit comments

Comments
 (0)