mirror of
https://git.sr.ht/~emersion/gamja
synced 2024-11-14 19:25:26 -05:00
Use RegExp match indices in linkifyChannel
This commit is contained in:
parent
0bcd044f10
commit
74d9dea5bb
1 changed files with 4 additions and 4 deletions
|
@ -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));
|
||||
|
||||
|
|
Loading…
Reference in a new issue