From 74d9dea5bb65caf9ab9262d56e2dd34e8adf2d93 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Tue, 1 Jun 2021 09:53:11 +0200 Subject: [PATCH] Use RegExp match indices in linkifyChannel --- lib/linkify.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/linkify.js b/lib/linkify.js index aee4512..b4b44b3 100644 --- a/lib/linkify.js +++ b/lib/linkify.js @@ -3,18 +3,18 @@ import { anchorme, html } from "./index.js"; function linkifyChannel(text, transformChannel) { var children = []; // TODO: Don't match punctuation - const channelRegex = /(^|\s)(#[^\s]+)/gid; + const channelRegex = /(?:^|\s)(#[^\s]+)/gid; let match; var last = 0; while ((match = channelRegex.exec(text)) !== null) { - const [_, spaces, channel] = match; + var channel = match[1]; + var [start, end] = match.indices[1]; - const start = match.index + spaces.length; children.push(text.substring(last, start)); children.push(transformChannel(channel)); - last = match.index + spaces.length + channel.length; + last = end; } children.push(text.substring(last));