The Highlight component has the option to add line numbers. See the following examples.
Add numberLine
props to add line numbers.
1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | |
15 | |
<script lang="ts">
import { Highlight } from 'runes-webkit';
import typescript from 'highlight.js/lib/languages/typescript';
const examples = import.meta.glob('./*.md', {
query: '?raw',
import: 'default',
eager: true
});
const tsLang = {
name: 'typescript',
register: typescript
};
</script>
<Highlight language={tsLang} code={examples['./sample-1.md'] as string} numberLine />
Add hideBorder
props to hide the border.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<script lang="ts">
import { Highlight } from 'runes-webkit';
import typescript from 'highlight.js/lib/languages/typescript';
const examples = import.meta.glob('./*.md', {
query: '?raw',
import: 'default',
eager: true
});
const tsLang = {
name: 'typescript',
register: typescript
};
</script>
<Highlight language={tsLang} code={examples['./sample-1.md'] as string} hideBorder numberLine />
Add wrapLines
props to wrap lines.
1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | |
15 | |
<script lang="ts">
import { Highlight } from 'runes-webkit';
import typescript from 'highlight.js/lib/languages/typescript';
const examples = import.meta.glob('./*.md', {
query: '?raw',
import: 'default',
eager: true
});
const tsLang = {
name: 'typescript',
register: typescript
};
</script>
<Highlight language={tsLang} code={examples['./sample-1.md'] as string} wrapLines numberLine />
1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | |
15 | |
<script lang="ts">
import { Highlight } from 'runes-webkit';
import typescript from 'highlight.js/lib/languages/typescript';
const examples = import.meta.glob('./*.md', {
query: '?raw',
import: 'default',
eager: true
});
const tsLang = {
name: 'typescript',
register: typescript
};
</script>
<Highlight language={tsLang} code={examples['./sample-1.md'] as string} numberLine backgroudColor="red" />
Use one of 'static' | 'relative' | 'abolute' | 'sticky' | undefined. The default value is 'sticky'.
1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | |
15 | |
<script lang="ts">
import { Highlight } from 'runes-webkit';
import typescript from 'highlight.js/lib/languages/typescript';
const examples = import.meta.glob('./*.md', {
query: '?raw',
import: 'default',
eager: true
});
const tsLang = {
name: 'typescript',
register: typescript
};
</script>
<Highlight language={tsLang} code={examples['./sample-1.md'] as string} numberLine backgroudColor="#326bfc" position="relative" />
Use the startingLineNumber
props to set the start line number.
42 | |
43 | |
44 | |
45 | |
46 | |
47 | |
48 | |
49 | |
50 | |
51 | |
52 | |
53 | |
54 | |
55 | |
56 | |
<script lang="ts">
import { Highlight } from 'runes-webkit';
import typescript from 'highlight.js/lib/languages/typescript';
const examples = import.meta.glob('./*.md', {
query: '?raw',
import: 'default',
eager: true
});
const tsLang = {
name: 'typescript',
register: typescript
};
</script>
<Highlight language={tsLang} code={examples['./sample-1.md'] as string} numberLine startingLineNumber={42} />
Use the highlightedLines
and highlightedBackground
props to highlight lines.
1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | |
15 | |
<script lang="ts">
import { Highlight } from 'runes-webkit';
import typescript from 'highlight.js/lib/languages/typescript';
const examples = import.meta.glob('./*.md', {
query: '?raw',
import: 'default',
eager: true
});
const tsLang = {
name: 'typescript',
register: typescript
};
</script>
<Highlight language={tsLang} code={examples['./sample-1.md'] as string} numberLine highlightedLines={[2, 4]} --highlighted-background="#666" />
Use the --line-number-color
, --border-color
--padding-left
, --padding-right
, and --highlighted-background
props to customize the styles.
1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | |
15 | |
<script lang="ts">
import { Highlight } from 'runes-webkit';
import typescript from 'highlight.js/lib/languages/typescript';
const examples = import.meta.glob('./*.md', {
query: '?raw',
import: 'default',
eager: true
});
const tsLang = {
name: 'typescript',
register: typescript
};
</script>
<Highlight
language={tsLang}
code={examples['./sample-1.md'] as string}
numberLine
highlightedLines={[1, 3]}
--line-number-color="pink"
--border-color="rgba(25, 155, 55, 1)"
--padding-left="1em"
--padding-right="2em"
--highlighted-background="#6e6e6e"
/>