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 endChar = this.selection.getRangeAt(0).startOffset;
|
||||||
var textContent = this.selection.focusNode.textContent;
|
var textContent = this.selection.focusNode.textContent;
|
||||||
|
|
||||||
this.word = this.getLastWord(textContent);
|
|
||||||
textContent = textContent.substring(0, endChar);
|
textContent = textContent.substring(0, endChar);
|
||||||
|
this.word = this.getLastWord(textContent);
|
||||||
|
|
||||||
if (this.word.length > 1 && ['@', '#', ':'].indexOf(this.word[0]) != -1) {
|
if (this.word.length > 1 && ['@', '#', ':'].indexOf(this.word[0]) != -1) {
|
||||||
this.wrap();
|
this.wrap();
|
||||||
|
|
|
@ -46,6 +46,9 @@ class WysiwygMentionService
|
||||||
for prop in searchProps
|
for prop in searchProps
|
||||||
if taiga.slugify(user[prop]).indexOf(term) >= 0
|
if taiga.slugify(user[prop]).indexOf(term) >= 0
|
||||||
return true
|
return true
|
||||||
|
else if user[prop].indexOf(term) >= 0
|
||||||
|
return true
|
||||||
|
|
||||||
return false
|
return false
|
||||||
|
|
||||||
users = users.slice(0, 10).map (it) =>
|
users = users.slice(0, 10).map (it) =>
|
||||||
|
|
|
@ -145,8 +145,43 @@ class WysiwygService
|
||||||
|
|
||||||
return markdown
|
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) ->
|
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',
|
mention: 'twitter',
|
||||||
hashtag: 'twitter',
|
hashtag: 'twitter',
|
||||||
replaceFn: (match) =>
|
replaceFn: (match) =>
|
||||||
|
@ -166,6 +201,10 @@ class WysiwygService
|
||||||
return '<a class="autolink" href="' + url + '">#' + match.getHashtag() + '</a>'
|
return '<a class="autolink" href="' + url + '">#' + match.getHashtag() + '</a>'
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Autolinker.matcher.Mention.prototype.parseMatches = @.parseMentionMatches.bind(autolinker)
|
||||||
|
|
||||||
|
return autolinker.link(html);
|
||||||
|
|
||||||
getHTML: (text) ->
|
getHTML: (text) ->
|
||||||
return "" if !text || !text.length
|
return "" if !text || !text.length
|
||||||
|
|
||||||
|
@ -181,7 +220,6 @@ class WysiwygService
|
||||||
})
|
})
|
||||||
|
|
||||||
md.use(window.markdownitLazyHeaders)
|
md.use(window.markdownitLazyHeaders)
|
||||||
|
|
||||||
result = md.render(text)
|
result = md.render(text)
|
||||||
result = @.searchWikiLinks(result)
|
result = @.searchWikiLinks(result)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue