Made mentionWithDots available as a prop

This commit is contained in:
2021-11-19 01:26:37 +03:00
parent 6a840c3171
commit f2269798e6
15 changed files with 17173 additions and 45 deletions

View File

@@ -15,6 +15,10 @@ export default {
type: Boolean,
default: true
},
mentionsWithDots: {
type: Boolean,
default: false
},
caretColor: {
type: String,
default: '#ccc'
@@ -37,7 +41,8 @@ export default {
},
computedBody () {
return highlight(this.body, {
extractUrlsWithoutProtocol: this.extractUrlsWithoutProtocol
extractUrlsWithoutProtocol: this.extractUrlsWithoutProtocol,
mentionsWithDots: this.mentionsWithDots
})
}
},

View File

@@ -8,7 +8,7 @@ import removeOverlappingEntities from './removeOverlappingEntities'
export default function (text, options) {
const entities = extractUrls(text, options)
.concat(extractMentions(text))
.concat(extractMentions(text, options))
.concat(extractHashtags(text))
if (entities.length === 0) {

View File

@@ -17,7 +17,8 @@ const OPTIONS_NOT_ATTRIBUTES = {
invisibleTagAttrs: true,
linkAttributeBlock: true,
htmlEscapeNonEntities: true,
extractUrlsWithoutProtocol: true
extractUrlsWithoutProtocol: true,
mentionsWithDots: true
}
export default function (options) {

View File

@@ -1,15 +1,16 @@
// Extracts mentions from text.
import { atSigns, endMentionMatch, validMention } from './regex'
import { atSigns, endMentionMatch, validMention, validDotMention } from './regex'
export default function (text) {
export default function (text, options) {
if (!text || !text.match(atSigns)) {
return []
}
const mentions = []
const mentionRegex = options.mentionsWithDots ? validDotMention : validMention
text.replace(validMention, function (match, before, atSign, mentionText, offset, chunk) {
text.replace(mentionRegex, function (match, before, atSign, mentionText, offset, chunk) {
const after = chunk.slice(offset + match.length)
if (!after.match(endMentionMatch)) {
const startPosition = offset + before.length

View File

@@ -4,7 +4,8 @@ import autoHighlight from './autoHighlight'
const defaultOptions = {
targetBlank: true,
extractUrlsWithoutProtocol: true
extractUrlsWithoutProtocol: true,
mentionsWithDots: false
}
export function link (text, options = defaultOptions) {

View File

@@ -187,6 +187,14 @@ export const validHashtag = regexSupplant(
export const atSigns = /[@]/
export const endMentionMatch = regexSupplant(/^(?:#{atSigns}|[#{latinAccentChars}]|:\/\/)/, { atSigns, latinAccentChars })
export const validMention = regexSupplant(
'(#{validMentionPrecedingChars})' + // $1: Preceding character
'(#{atSigns})' + // $2: At mark
'([a-zA-Z0-9_]{1,20})', // $3: Screen name
// '(/[a-zA-Z][a-zA-Z0-9_-]{0,24})?', // $4: List (optional)
{ validMentionPrecedingChars, atSigns },
'g'
)
export const validDotMention = regexSupplant(
'(#{validMentionPrecedingChars})' + // $1: Preceding character
'(#{atSigns})' + // $2: At mark
'([a-zA-Z0-9_\.]{1,20})', // $3: Screen name