Skip to content

Commit

Permalink
Fix rewrite rules
Browse files Browse the repository at this point in the history
  • Loading branch information
ggodlewski committed Apr 5, 2024
1 parent 03cb456 commit a644cb3
Showing 1 changed file with 14 additions and 32 deletions.
46 changes: 14 additions & 32 deletions src/odt/postprocess/applyRewriteRules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export function applyRewriteRules(markdownChunks: MarkdownNodes, rewriteRule: Re
}

if ('tag' in chunk && ['SVG/', 'IMG/'].includes(chunk.tag)) {
let broke = false;
for (const rule of rewriteRule) {
const { shouldBreak, text } = applyRewriteRule(rule, {
...chunk,
Expand All @@ -20,29 +19,21 @@ export function applyRewriteRules(markdownChunks: MarkdownNodes, rewriteRule: Re
alt: 'payload' in chunk ? chunk.payload?.alt : undefined
});

const textNode: MarkdownTextNode = {
isTag: false,
text,
parent: undefined,
comment: 'MarkdownNodes.ts: appendText'
};
chunk.parent.children.splice(ctx.nodeIdx, 1, textNode);

if (shouldBreak) {
// retVal.push(text);
broke = true;
const textNode: MarkdownTextNode = {
isTag: false,
text: text,
parent: undefined,
comment: 'MarkdownNodes.ts: appendText'
};
chunk.parent.children.splice(ctx.nodeIdx, 1, textNode);
break;
}
}

if (broke) {
// return retVal.join('');
}
}

if ('tag' in chunk && 'A' === chunk.tag) {
const alt = chunksToText(chunk.children, { ...ctx, mode: 'md', onlyNotTag: true });
let broke = false;
for (const rule of rewriteRule) {
const { shouldBreak, text } = applyRewriteRule(rule, {
...chunk,
Expand All @@ -51,26 +42,17 @@ export function applyRewriteRules(markdownChunks: MarkdownNodes, rewriteRule: Re
alt
});

const textNode: MarkdownTextNode = {
isTag: false,
text,
parent: undefined,
comment: 'MarkdownNodes.ts: appendText'
};
chunk.parent.children.splice(ctx.nodeIdx, 1, textNode);

if (shouldBreak) {
// retVal.push(text);
broke = true;
const textNode: MarkdownTextNode = {
isTag: false,
text,
parent: undefined,
comment: 'MarkdownNodes.ts: appendText'
};
chunk.parent.children.splice(ctx.nodeIdx, 1, textNode);
break;
}
}

if (broke) {
// return retVal.join('');
// retVal.splice(chunkNo, matchingNo - chunkNo);
// return retVal;
}
}

}, {}, (chunk) => {
Expand Down

0 comments on commit a644cb3

Please sign in to comment.