mirror of
https://github.com/ilyakooo0/urbit.git
synced 2024-12-15 01:52:42 +03:00
tokenizeMessage: expand group links
This commit is contained in:
parent
6c653e7ab9
commit
be34223a6e
@ -3,6 +3,8 @@ import { parsePermalink, permalinkToReference } from '~/logic/lib/permalinks';
|
||||
|
||||
const URL_REGEX = new RegExp(String(/^(([\w\-\+]+:\/\/)[-a-zA-Z0-9:@;?&=\/%\+\.\*!'\(\),\$_\{\}\^~\[\]`#|]+\w)/.source));
|
||||
|
||||
const GROUP_REGEX = new RegExp(String(/^~[-a-z_]+\/[-a-z]+/.source));
|
||||
|
||||
const isUrl = (string) => {
|
||||
try {
|
||||
return URL_REGEX.test(string);
|
||||
@ -15,6 +17,16 @@ const isRef = (str) => {
|
||||
return isUrl(str) && str.startsWith('web+urbitgraph://');
|
||||
};
|
||||
|
||||
const isGroup = str => {
|
||||
try {
|
||||
return GROUP_REGEX.test(str);
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
const convertToGroupRef = (group) => `web+urbitgraph://group/${group}`;
|
||||
|
||||
const tokenizeMessage = (text) => {
|
||||
let messages = [];
|
||||
// by line
|
||||
@ -37,7 +49,9 @@ const tokenizeMessage = (text) => {
|
||||
currTextLine = [line];
|
||||
} else {
|
||||
const words = line.split(/\s/);
|
||||
words.forEach((str, idx) => {
|
||||
words.forEach((word, idx) => {
|
||||
const str = isGroup(word) ? convertToGroupRef(word) : word;
|
||||
|
||||
const last = words.length - 1 === idx;
|
||||
if (
|
||||
(str.startsWith('`') && str !== '`')
|
||||
|
Loading…
Reference in New Issue
Block a user