mirror of
https://git.sr.ht/~emersion/gamja
synced 2024-11-14 19:25:26 -05:00
lib/linkify: stop using RegExp indices
Co-authored-by: Simon Ser <contact@emersion.fr> Closes: https://todo.sr.ht/~emersion/gamja/90
This commit is contained in:
parent
2203553519
commit
42e0c939f3
1 changed files with 4 additions and 3 deletions
|
@ -2,14 +2,15 @@ import { anchorme, html } from "./index.js";
|
|||
|
||||
function linkifyChannel(text, transformChannel) {
|
||||
// Don't match punctuation at the end of the channel name
|
||||
const channelRegex = /(?:^|\s)(#[^\s]+[^\s.?!…():;,])/gid;
|
||||
const channelRegex = /(^|\s)(#[^\s]+[^\s.?!…():;,])/gi;
|
||||
|
||||
let children = [];
|
||||
let match;
|
||||
let last = 0;
|
||||
while ((match = channelRegex.exec(text)) !== null) {
|
||||
let channel = match[1];
|
||||
let [start, end] = match.indices[1];
|
||||
let channel = match[2];
|
||||
let start = match.index + match[1].length;
|
||||
let end = start + match[2].length;
|
||||
|
||||
children.push(text.substring(last, start));
|
||||
children.push(transformChannel(channel));
|
||||
|
|
Loading…
Reference in a new issue