autolink urls in content view
This commit is contained in:
parent
70737ddc9d
commit
ad2e6a414f
3 changed files with 29 additions and 2 deletions
|
|
@ -10,9 +10,11 @@ app.views.Content = app.views.StreamObject.extend({
|
|||
text = text || ""
|
||||
return mentionify(
|
||||
hashtagify(
|
||||
urlify(
|
||||
markdownify(text)
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
function markdownify(text){
|
||||
|
|
@ -34,11 +36,18 @@ app.views.Content = app.views.StreamObject.extend({
|
|||
return person.diaspora_id == diasporaId
|
||||
}).id
|
||||
|
||||
|
||||
return "<a href='/people/" + personId + "' class='mention'>" + fullName + "</a>"
|
||||
})
|
||||
return text
|
||||
}
|
||||
|
||||
function urlify(text) {
|
||||
var urlRegex = /[-a-zA-Z0-9@:%_\+.~#?&//=]{2,256}\.[a-z]{2,4}\b(\/[-a-zA-Z0-9@:%_\+.~#?&//=]*)?/gi
|
||||
return text.replace(urlRegex, function(url) {
|
||||
var protocol = (url.search(/:\/\//) == -1 ? "http://" : "")
|
||||
return "<a href='" + protocol + url + "' target=_blank>" + url + "</a>"
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
|
|
|
|||
|
|
@ -126,6 +126,23 @@ describe("app.views.Post", function(){
|
|||
})
|
||||
})
|
||||
|
||||
context("generates urls from plaintext", function(){
|
||||
it("works", function(){
|
||||
links = ["http://google.com",
|
||||
"https://joindiaspora.com",
|
||||
"http://www.yahooligans.com",
|
||||
"obama.com",
|
||||
"japan.co.jp"]
|
||||
|
||||
this.statusMessage.set({text : links.join(" ")})
|
||||
var view = new app.views.Post({model : this.statusMessage}).render();
|
||||
|
||||
_.each(links, function(link) {
|
||||
expect(view.$("a[href='" + link + "']").text()).toContain(link)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
context("user not signed in", function(){
|
||||
it("does not provide a Feedback view", function(){
|
||||
window.current_user = app.user(null);
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ src_files:
|
|||
- public/javascripts/app/models/*
|
||||
- public/javascripts/app/collections/*
|
||||
- public/javascripts/app/views/stream_object_view.js
|
||||
- public/javascripts/app/views/content_view.js
|
||||
- public/javascripts/app/views/*
|
||||
|
||||
- public/javascripts/mobile.js
|
||||
|
|
|
|||
Loading…
Reference in a new issue