Skip to content

Commit

Permalink
Fix placeholderIndices bug
Browse files Browse the repository at this point in the history
  • Loading branch information
ptgott committed Nov 18, 2024
1 parent f25ffe2 commit 12b2f3c
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions server/rehype-hljs-var.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,16 @@ export const rehypeVarInHLJS = (
// can tell whether a given index falls within a placeholder.
const placeholderIndices = new Map();
placeholders.forEach((p) => {
placeholderIndices.set(p.index, p);
placeholderIndices.set(p.index, p[0]);
});

let valueIdx = 0;
while (valueIdx < textValue.length) {
// The current index is in a placeholder, so add the original Var
// component to newChildren.
if (placeholderIndices.has(valueIdx)) {
const placeholder = valueIdx + placeholderIndices.get(valueIdx);
const placeholder = placeholderIndices.get(valueIdx);
console.log("placeholder:", placeholder);
valueIdx += placeholder.length;
newChildren.push(placeholdersToVars[placeholder]);
continue;
Expand Down

0 comments on commit 12b2f3c

Please sign in to comment.