fixes and functions
This commit is contained in:
@@ -100,26 +100,6 @@ export function buildImageAlias(options = {}) {
|
||||
return `[${kind}=${filename},${parts.join(",")}]`;
|
||||
}
|
||||
|
||||
export function updateImageAliasInLine(line, aliasIndex, patch = {}) {
|
||||
const source = String(line || "");
|
||||
const targetIndex = Number(aliasIndex);
|
||||
if (!Number.isInteger(targetIndex) || targetIndex < 0) return null;
|
||||
|
||||
const codeRanges = inlineCodeRanges(source);
|
||||
let index = 0;
|
||||
let changed = false;
|
||||
const value = source.replace(imageAliasPattern(), (match, ...args) => {
|
||||
const offset = args.at(-2);
|
||||
if (isInsideRange(offset, codeRanges) || index++ !== targetIndex) return match;
|
||||
const parsed = parseImageAlias(match);
|
||||
if (!parsed) return match;
|
||||
changed = true;
|
||||
return buildImageAlias({ ...parsed, ...patch });
|
||||
});
|
||||
|
||||
return changed ? value : null;
|
||||
}
|
||||
|
||||
export function updateImageAliasInLineBySource(line, aliasSource, occurrence = 0, patch = {}) {
|
||||
const source = String(line || "");
|
||||
const target = String(aliasSource || "");
|
||||
|
||||
Reference in New Issue
Block a user