Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(line-numbers): correctly set top/bottom padding #260

Merged
merged 2 commits into from
Jan 1, 2023
Merged
Show file tree
Hide file tree
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
16 changes: 10 additions & 6 deletions src/LineNumbers.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* @default false
*/
hideBorder?: boolean;

/**
* Specify which starting line number should be displayed.
* @default 1
Expand Down Expand Up @@ -65,7 +65,7 @@
export let hideBorder = false;

export let wrapLines = false;

export let startingLineNumber = 1;

const DIGIT_WIDTH = 12;
Expand All @@ -82,8 +82,6 @@
<tbody class:hljs={true}>
{#each lines as line, i}
{@const lineNumber = i + startingLineNumber}
{@const isFirst = i === 0}
{@const isLast = i === lines.length - 1}
<tr>
<td
class:hljs={true}
Expand All @@ -92,8 +90,6 @@
style:left="0"
style:text-align="right"
style:user-select="none"
style:padding-top={isFirst ? "1em" : undefined}
style:padding-bottom={isLast ? "1em" : undefined}
style:width={width + "px"}
>
<code style:color="var(--line-number-color, currentColor)">
Expand Down Expand Up @@ -129,6 +125,14 @@
border-spacing: 0;
}

tr:first-of-type td {
padding-top: 1em;
}

tr:last-child td {
padding-bottom: 1em;
}

td {
padding-left: var(--padding-left, 1em);
padding-right: var(--padding-right, 1em);
Expand Down
2 changes: 1 addition & 1 deletion tests/SvelteHighlight.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ describe("SvelteHighlight", () => {

expect(target.querySelector("#line-numbers")?.innerHTML)
.toMatchInlineSnapshot(`
"<div style=\\"overflow-x: auto;\\" class=\\"svelte-2e2lav\\"><table class=\\"svelte-2e2lav\\"><tbody class=\\"hljs\\"><tr class=\\"svelte-2e2lav\\"><td class=\\"svelte-2e2lav hljs\\" style=\\"position: sticky; left: 0px; text-align: right; user-select: none; padding-top: 1em; padding-bottom: 1em; width: 24px;\\"><code>1</code></td> <td class=\\"svelte-2e2lav\\"><pre class=\\"svelte-2e2lav\\"><code>
"<div style=\\"overflow-x: auto;\\" class=\\"svelte-1kmlnkb\\"><table class=\\"svelte-1kmlnkb\\"><tbody class=\\"hljs\\"><tr class=\\"svelte-1kmlnkb\\"><td class=\\"svelte-1kmlnkb hljs\\" style=\\"position: sticky; left: 0px; text-align: right; user-select: none; width: 24px;\\"><code>1</code></td> <td class=\\"svelte-1kmlnkb\\"><pre class=\\"svelte-1kmlnkb\\"><code>
</code></pre></td> </tr></tbody></table></div>"
`);
});
Expand Down