Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Milan
diaspora
Commits
694dc7d8
Commit
694dc7d8
authored
Mar 13, 2014
by
Hincu Petru
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Check if the hashtag is a link in function .hashtagify
parent
a51c4f0d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
5 deletions
+28
-5
app/assets/javascripts/app/helpers/text_formatter.js
app/assets/javascripts/app/helpers/text_formatter.js
+9
-5
spec/javascripts/app/helpers/text_formatter_spec.js
spec/javascripts/app/helpers/text_formatter_spec.js
+19
-0
No files found.
app/assets/javascripts/app/helpers/text_formatter.js
View file @
694dc7d8
...
...
@@ -108,11 +108,15 @@ $(function() {
};
textFormatter
.
hashtagify
=
function
hashtagify
(
text
){
var
utf8WordCharcters
=
/
(\s
|^|>
)
#
([\u
0080-
\u
FFFF|
\w
|-
]
+|<3
)
/g
return
text
.
replace
(
utf8WordCharcters
,
function
(
hashtag
,
preceeder
,
tagText
)
{
return
preceeder
+
"
<a href='/tags/
"
+
tagText
.
toLowerCase
()
+
"
' class='tag'>#
"
+
tagText
+
"
</a>
"
})
var
utf8WordCharcters
=
/
(
<a
[^
>
]
*>.*
?
<
\/
a>
)
|
(\s
|^|>
)
#
([\u
0080-
\u
FFFF|
\w
|-
]
+|<3
)
/g
;
return
text
.
replace
(
utf8WordCharcters
,
function
(
result
,
linkTag
,
preceeder
,
tagText
)
{
if
(
linkTag
)
return
linkTag
;
else
return
preceeder
+
"
<a href='/tags/
"
+
tagText
.
toLowerCase
()
+
"
' class='tag'>#
"
+
tagText
+
"
</a>
"
;
});
};
textFormatter
.
mentionify
=
function
mentionify
(
text
,
mentions
)
{
...
...
spec/javascripts/app/helpers/text_formatter_spec.js
View file @
694dc7d8
...
...
@@ -238,6 +238,25 @@ describe("app.helpers.textFormatter", function(){
expect
(
formattedText
).
toContain
(
"
/tags/parties
"
)
})
it
(
"
doesn't create tag if the text is a link
"
,
function
(){
var
tags
=
[
'
diaspora
'
,
'
twitter
'
,
'
hrabrahabr
'
];
var
text
=
$
(
'
<a/>
'
,
{
href
:
'
http://me.co
'
}).
html
(
'
#me
'
)[
0
].
outerHTML
;
_
.
each
(
tags
,
function
(
tagName
){
text
+=
'
#
'
+
tagName
+
'
,
'
;
});
text
+=
'
I love
'
;
var
formattedText
=
this
.
formatter
.
hashtagify
(
text
);
var
wrapper
=
$
(
'
<div>
'
).
html
(
formattedText
);
expect
(
wrapper
.
find
(
"
a[href='http://me.co']
"
).
text
()).
toContain
(
'
#me
'
);
_
.
each
(
tags
,
function
(
tagName
){
expect
(
wrapper
.
find
(
"
a[href='/tags/
"
+
tagName
+
"
']
"
).
text
()).
toContain
(
'
#
'
+
tagName
);
});
})
})
})
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment