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:
@@ -58,6 +58,7 @@ As you can see, the component accepts some props:
|
|||||||
| ---- | ---- | -------- |
|
| ---- | ---- | -------- |
|
||||||
| value | String | The text to highlight (**v-model**). |
|
| value | String | The text to highlight (**v-model**). |
|
||||||
| extractUrlsWithoutProtocol | Boolean | As the name says, when active, the compoponet will try to match URLs even when a protocol (http://, https://) is not found. **Defaults to true** |
|
| extractUrlsWithoutProtocol | Boolean | As the name says, when active, the compoponet will try to match URLs even when a protocol (http://, https://) is not found. **Defaults to true** |
|
||||||
|
| mentionsWithDots | Boolean | Whether a mention can contain a dot. **Defaults to false** |
|
||||||
| caretColor | String | A valid HEX color (eg. #ccc, #ff4545). |
|
| caretColor | String | A valid HEX color (eg. #ccc, #ff4545). |
|
||||||
| placeholder | String | A placeholder to show when no text is entered. |
|
| placeholder | String | A placeholder to show when no text is entered. |
|
||||||
| usernameClass | String | The CSS class(es) that will be added to a @username match. |
|
| usernameClass | String | The CSS class(es) that will be added to a @username match. |
|
||||||
|
|||||||
9
dist/vue-highlights.common.js
vendored
9
dist/vue-highlights.common.js
vendored
@@ -1083,7 +1083,7 @@ const endMentionMatch = _regexSupplant(/^(?:#{atSigns}|[#{latinAccentChars}]|:\/
|
|||||||
const validMention = _regexSupplant(
|
const validMention = _regexSupplant(
|
||||||
'(#{validMentionPrecedingChars})' + // $1: Preceding character
|
'(#{validMentionPrecedingChars})' + // $1: Preceding character
|
||||||
'(#{atSigns})' + // $2: At mark
|
'(#{atSigns})' + // $2: At mark
|
||||||
'([a-zA-Z0-9_]{1,20})', // $3: Screen name
|
'([a-zA-Z0-9_\.]{1,20})', // $3: Screen name
|
||||||
// '(/[a-zA-Z][a-zA-Z0-9_-]{0,24})?', // $4: List (optional)
|
// '(/[a-zA-Z][a-zA-Z0-9_-]{0,24})?', // $4: List (optional)
|
||||||
{ validMentionPrecedingChars, atSigns },
|
{ validMentionPrecedingChars, atSigns },
|
||||||
'g'
|
'g'
|
||||||
@@ -1675,6 +1675,10 @@ function src_autoLink (text, options) {
|
|||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: true
|
default: true
|
||||||
},
|
},
|
||||||
|
mentionsWithDots: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
},
|
||||||
caretColor: {
|
caretColor: {
|
||||||
type: String,
|
type: String,
|
||||||
default: '#ccc'
|
default: '#ccc'
|
||||||
@@ -1697,7 +1701,8 @@ function src_autoLink (text, options) {
|
|||||||
},
|
},
|
||||||
computedBody () {
|
computedBody () {
|
||||||
return highlight(this.body, {
|
return highlight(this.body, {
|
||||||
extractUrlsWithoutProtocol: this.extractUrlsWithoutProtocol
|
extractUrlsWithoutProtocol: this.extractUrlsWithoutProtocol,
|
||||||
|
mentionsWithDots: this.mentionsWithDots
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
2
dist/vue-highlights.common.js.map
vendored
2
dist/vue-highlights.common.js.map
vendored
File diff suppressed because one or more lines are too long
9
dist/vue-highlights.umd.js
vendored
9
dist/vue-highlights.umd.js
vendored
@@ -1092,7 +1092,7 @@ const endMentionMatch = _regexSupplant(/^(?:#{atSigns}|[#{latinAccentChars}]|:\/
|
|||||||
const validMention = _regexSupplant(
|
const validMention = _regexSupplant(
|
||||||
'(#{validMentionPrecedingChars})' + // $1: Preceding character
|
'(#{validMentionPrecedingChars})' + // $1: Preceding character
|
||||||
'(#{atSigns})' + // $2: At mark
|
'(#{atSigns})' + // $2: At mark
|
||||||
'([a-zA-Z0-9_]{1,20})', // $3: Screen name
|
'([a-zA-Z0-9_\.]{1,20})', // $3: Screen name
|
||||||
// '(/[a-zA-Z][a-zA-Z0-9_-]{0,24})?', // $4: List (optional)
|
// '(/[a-zA-Z][a-zA-Z0-9_-]{0,24})?', // $4: List (optional)
|
||||||
{ validMentionPrecedingChars, atSigns },
|
{ validMentionPrecedingChars, atSigns },
|
||||||
'g'
|
'g'
|
||||||
@@ -1684,6 +1684,10 @@ function src_autoLink (text, options) {
|
|||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: true
|
default: true
|
||||||
},
|
},
|
||||||
|
mentionsWithDots: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
},
|
||||||
caretColor: {
|
caretColor: {
|
||||||
type: String,
|
type: String,
|
||||||
default: '#ccc'
|
default: '#ccc'
|
||||||
@@ -1706,7 +1710,8 @@ function src_autoLink (text, options) {
|
|||||||
},
|
},
|
||||||
computedBody () {
|
computedBody () {
|
||||||
return highlight(this.body, {
|
return highlight(this.body, {
|
||||||
extractUrlsWithoutProtocol: this.extractUrlsWithoutProtocol
|
extractUrlsWithoutProtocol: this.extractUrlsWithoutProtocol,
|
||||||
|
mentionsWithDots: this.mentionsWithDots
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
2
dist/vue-highlights.umd.js.map
vendored
2
dist/vue-highlights.umd.js.map
vendored
File diff suppressed because one or more lines are too long
2
dist/vue-highlights.umd.min.js
vendored
2
dist/vue-highlights.umd.min.js
vendored
File diff suppressed because one or more lines are too long
2
dist/vue-highlights.umd.min.js.map
vendored
2
dist/vue-highlights.umd.min.js.map
vendored
File diff suppressed because one or more lines are too long
@@ -21,6 +21,7 @@
|
|||||||
:placeholder="placeholder"
|
:placeholder="placeholder"
|
||||||
:caretColor="caretColor"
|
:caretColor="caretColor"
|
||||||
:extractUrlsWithoutProtocol="options.extractUrlsWithoutProtocol"
|
:extractUrlsWithoutProtocol="options.extractUrlsWithoutProtocol"
|
||||||
|
:mentionsWithDots="options.mentionsWithDots"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -28,14 +29,18 @@
|
|||||||
<div id="options" class="content-container">
|
<div id="options" class="content-container">
|
||||||
<h4>Options (props)</h4>
|
<h4>Options (props)</h4>
|
||||||
<div class="flex center">
|
<div class="flex center">
|
||||||
<label for="ep" class="mr-lg cursor-pointer">
|
<label for="ep" class="cursor-pointer">
|
||||||
<input id="ep" type="checkbox" v-model="options.extractUrlsWithoutProtocol">
|
<input id="ep" type="checkbox" v-model="options.extractUrlsWithoutProtocol">
|
||||||
extractUrlsWithoutProtocol
|
extractUrlsWithoutProtocol
|
||||||
</label>
|
</label>
|
||||||
<label for="tb" class="cursor-pointer">
|
<label for="tb" class="mx-lg cursor-pointer">
|
||||||
<input id="tb" type="checkbox" v-model="options.targetBlank">
|
<input id="tb" type="checkbox" v-model="options.targetBlank">
|
||||||
targetBlank
|
targetBlank
|
||||||
</label>
|
</label>
|
||||||
|
<label for="md" class="cursor-pointer">
|
||||||
|
<input id="md" type="checkbox" v-model="options.mentionsWithDots">
|
||||||
|
mentionsWithDots
|
||||||
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="flex center mt-sm text-left relative">
|
<div class="flex center mt-sm text-left relative">
|
||||||
@@ -130,6 +135,7 @@ export default {
|
|||||||
options: {
|
options: {
|
||||||
targetBlank: true,
|
targetBlank: true,
|
||||||
extractUrlsWithoutProtocol: true,
|
extractUrlsWithoutProtocol: true,
|
||||||
|
mentionsWithDots: false,
|
||||||
usernameClass: 'highlights username',
|
usernameClass: 'highlights username',
|
||||||
usernameUrlBase: '#/',
|
usernameUrlBase: '#/',
|
||||||
hashtagClass: 'highlights hashtag',
|
hashtagClass: 'highlights hashtag',
|
||||||
|
|||||||
17151
package-lock.json
generated
17151
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -15,6 +15,10 @@ export default {
|
|||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: true
|
default: true
|
||||||
},
|
},
|
||||||
|
mentionsWithDots: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
},
|
||||||
caretColor: {
|
caretColor: {
|
||||||
type: String,
|
type: String,
|
||||||
default: '#ccc'
|
default: '#ccc'
|
||||||
@@ -37,7 +41,8 @@ export default {
|
|||||||
},
|
},
|
||||||
computedBody () {
|
computedBody () {
|
||||||
return highlight(this.body, {
|
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) {
|
export default function (text, options) {
|
||||||
const entities = extractUrls(text, options)
|
const entities = extractUrls(text, options)
|
||||||
.concat(extractMentions(text))
|
.concat(extractMentions(text, options))
|
||||||
.concat(extractHashtags(text))
|
.concat(extractHashtags(text))
|
||||||
|
|
||||||
if (entities.length === 0) {
|
if (entities.length === 0) {
|
||||||
|
|||||||
@@ -17,7 +17,8 @@ const OPTIONS_NOT_ATTRIBUTES = {
|
|||||||
invisibleTagAttrs: true,
|
invisibleTagAttrs: true,
|
||||||
linkAttributeBlock: true,
|
linkAttributeBlock: true,
|
||||||
htmlEscapeNonEntities: true,
|
htmlEscapeNonEntities: true,
|
||||||
extractUrlsWithoutProtocol: true
|
extractUrlsWithoutProtocol: true,
|
||||||
|
mentionsWithDots: true
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function (options) {
|
export default function (options) {
|
||||||
|
|||||||
@@ -1,15 +1,16 @@
|
|||||||
// Extracts mentions from text.
|
// 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)) {
|
if (!text || !text.match(atSigns)) {
|
||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
|
|
||||||
const mentions = []
|
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)
|
const after = chunk.slice(offset + match.length)
|
||||||
if (!after.match(endMentionMatch)) {
|
if (!after.match(endMentionMatch)) {
|
||||||
const startPosition = offset + before.length
|
const startPosition = offset + before.length
|
||||||
|
|||||||
@@ -4,7 +4,8 @@ import autoHighlight from './autoHighlight'
|
|||||||
|
|
||||||
const defaultOptions = {
|
const defaultOptions = {
|
||||||
targetBlank: true,
|
targetBlank: true,
|
||||||
extractUrlsWithoutProtocol: true
|
extractUrlsWithoutProtocol: true,
|
||||||
|
mentionsWithDots: false
|
||||||
}
|
}
|
||||||
|
|
||||||
export function link (text, options = defaultOptions) {
|
export function link (text, options = defaultOptions) {
|
||||||
|
|||||||
@@ -187,6 +187,14 @@ export const validHashtag = regexSupplant(
|
|||||||
export const atSigns = /[@@]/
|
export const atSigns = /[@@]/
|
||||||
export const endMentionMatch = regexSupplant(/^(?:#{atSigns}|[#{latinAccentChars}]|:\/\/)/, { atSigns, latinAccentChars })
|
export const endMentionMatch = regexSupplant(/^(?:#{atSigns}|[#{latinAccentChars}]|:\/\/)/, { atSigns, latinAccentChars })
|
||||||
export const validMention = regexSupplant(
|
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
|
'(#{validMentionPrecedingChars})' + // $1: Preceding character
|
||||||
'(#{atSigns})' + // $2: At mark
|
'(#{atSigns})' + // $2: At mark
|
||||||
'([a-zA-Z0-9_\.]{1,20})', // $3: Screen name
|
'([a-zA-Z0-9_\.]{1,20})', // $3: Screen name
|
||||||
|
|||||||
Reference in New Issue
Block a user