mirror of
https://github.com/anatolykopyl/vue-highlights.git
synced 2026-03-26 12:55:35 +00:00
Made mentionWithDots available as a prop
This commit is contained in:
@@ -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
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -17,7 +17,8 @@ const OPTIONS_NOT_ATTRIBUTES = {
|
||||
invisibleTagAttrs: true,
|
||||
linkAttributeBlock: true,
|
||||
htmlEscapeNonEntities: true,
|
||||
extractUrlsWithoutProtocol: true
|
||||
extractUrlsWithoutProtocol: true,
|
||||
mentionsWithDots: true
|
||||
}
|
||||
|
||||
export default function (options) {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -4,7 +4,8 @@ import autoHighlight from './autoHighlight'
|
||||
|
||||
const defaultOptions = {
|
||||
targetBlank: true,
|
||||
extractUrlsWithoutProtocol: true
|
||||
extractUrlsWithoutProtocol: true,
|
||||
mentionsWithDots: false
|
||||
}
|
||||
|
||||
export function link (text, options = defaultOptions) {
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user