allow dot mention overriding Autolinker parser
parent
099775b1ed
commit
19c74af27a
|
@ -46,8 +46,8 @@ var MentionExtension = MediumEditor.Extension.extend({
|
|||
var endChar = this.selection.getRangeAt(0).startOffset;
|
||||
var textContent = this.selection.focusNode.textContent;
|
||||
|
||||
this.word = this.getLastWord(textContent);
|
||||
textContent = textContent.substring(0, endChar);
|
||||
this.word = this.getLastWord(textContent);
|
||||
|
||||
if (this.word.length > 1 && ['@', '#', ':'].indexOf(this.word[0]) != -1) {
|
||||
this.wrap();
|
||||
|
|
|
@ -46,6 +46,9 @@ class WysiwygMentionService
|
|||
for prop in searchProps
|
||||
if taiga.slugify(user[prop]).indexOf(term) >= 0
|
||||
return true
|
||||
else if user[prop].indexOf(term) >= 0
|
||||
return true
|
||||
|
||||
return false
|
||||
|
||||
users = users.slice(0, 10).map (it) =>
|
||||
|
|
|
@ -145,8 +145,43 @@ class WysiwygService
|
|||
|
||||
return markdown
|
||||
|
||||
parseMentionMatches: (text) ->
|
||||
serviceName = 'twitter'
|
||||
tagBuilder = this.tagBuilder
|
||||
matches = []
|
||||
|
||||
regex = /@[^\s]{1,50}[^.\s]/g
|
||||
m = regex.exec(text)
|
||||
|
||||
while m != null
|
||||
offset = m.index
|
||||
prevChar = text.charAt( offset - 1 )
|
||||
|
||||
if m.index == regex.lastIndex
|
||||
regex.lastIndex++
|
||||
|
||||
m.forEach (match, groupIndex) ->
|
||||
matches.push( new Autolinker.match.Mention({
|
||||
tagBuilder : tagBuilder,
|
||||
matchedText : match,
|
||||
offset : offset,
|
||||
serviceName : serviceName,
|
||||
mention : match.slice(1)
|
||||
}))
|
||||
|
||||
m = regex.exec(text)
|
||||
|
||||
return matches
|
||||
|
||||
autoLinkHTML: (html) ->
|
||||
return Autolinker.link(html, {
|
||||
# override Autolink parser
|
||||
|
||||
matchRegexStr = String(Autolinker.matcher.Mention.prototype.matcherRegexes.twitter)
|
||||
if matchRegexStr.indexOf('.') == -1
|
||||
matchRegexStr = '@[^\s]{1,50}[^.\s]'
|
||||
#Autolinker.matcher.Mention.prototype.matcherRegexes.twitter = new RegExp(matchRegexStr, 'g')
|
||||
|
||||
autolinker = new Autolinker({
|
||||
mention: 'twitter',
|
||||
hashtag: 'twitter',
|
||||
replaceFn: (match) =>
|
||||
|
@ -166,6 +201,10 @@ class WysiwygService
|
|||
return '<a class="autolink" href="' + url + '">#' + match.getHashtag() + '</a>'
|
||||
})
|
||||
|
||||
Autolinker.matcher.Mention.prototype.parseMatches = @.parseMentionMatches.bind(autolinker)
|
||||
|
||||
return autolinker.link(html);
|
||||
|
||||
getHTML: (text) ->
|
||||
return "" if !text || !text.length
|
||||
|
||||
|
@ -181,7 +220,6 @@ class WysiwygService
|
|||
})
|
||||
|
||||
md.use(window.markdownitLazyHeaders)
|
||||
|
||||
result = md.render(text)
|
||||
result = @.searchWikiLinks(result)
|
||||
|
||||
|
|
Loading…
Reference in New Issue