Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/patcher/paragraph-split-inject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ import { Element } from "xml-js";

import { createTextElementContents, patchSpaceAttribute } from "./util";

export class TokenNotFoundError extends Error {
public constructor(token: string) {
super(`Token ${token} not found`);
this.name = "TokenNotFoundError";
}
}

export const findRunElementIndexWithToken = (paragraphElement: Element, token: string): number => {
for (let i = 0; i < (paragraphElement.elements ?? []).length; i++) {
const element = paragraphElement.elements![i];
Expand All @@ -20,7 +27,7 @@ export const findRunElementIndexWithToken = (paragraphElement: Element, token: s
}
}

throw new Error("Token not found");
throw new TokenNotFoundError(token);
};

export const splitRunElement = (runElement: Element, token: string): { readonly left: Element; readonly right: Element } => {
Expand Down