Skip to content

Commit

Permalink
Don't include placeholders as first or last line (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
LegNeato authored Nov 24, 2024
1 parent ede8afd commit 44fa0b1
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions src/components/Snippet/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,21 +105,18 @@ const Snippet: React.FC<SnippetProps> = ({
}, Infinity);

lines.forEach((line, index) => {
if (index > 0 && lines[index - 1] < line - 1) {
includedContent.push(omitted_placeholder); // Add placeholder for omitted lines
}

const rawLine = allLines[line - 1] || "";
const trimmedLine =
rawLine.trim().length > 0 ? rawLine.slice(minIndent) : rawLine;

if (index > 0 && lines[index - 1] < line - 1) {
// Add placeholder for omitted lines only if within range
includedContent.push(omitted_placeholder);
}

includedContent.push(trimmedLine);
});

// Add placeholder if lines at the end are omitted
if (lines[lines.length - 1] < allLines.length) {
includedContent.push(omitted_placeholder);
}

return includedContent.join("\n");
};

Expand Down

0 comments on commit 44fa0b1

Please sign in to comment.