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:
delthas 2021-06-20 12:54:20 +02:00 committed by Simon Ser
parent 2203553519
commit 42e0c939f3

View file

@ -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));