https://github.com/r4ai/typst-code-info
https://github.com/r4ai/typst-code-info
typst
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/r4ai/typst-code-info
- Owner: r4ai
- License: mit
- Created: 2024-08-13T17:09:43.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-10-02T15:20:42.000Z (over 1 year ago)
- Last Synced: 2025-12-25T07:53:05.438Z (6 months ago)
- Topics: typst
- Language: Typst
- Homepage:
- Size: 247 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# typst-code-info
This is a library to display code blocks with extra information like captions, line numbers, diff highlights, etc.
## Features
- Show line numbers
- Calculate diff between two code blocks and highlight the differences
- Highlighting of specific lines
- Display captions
## Installation
> [!warning]
> Following are required to build and install:
>
> - [Rust](https://www.rust-lang.org/)
> - [Task](https://taskfile.dev/)
> - [Deno](https://deno.com/)
- **From local source**:
Clone the repository and run the following command:
```bash
task install
```
## Usage
### Line numbers
````typst
#import "../../plugin.typ": init-code-info, code-info
#show: init-code-info.with()
#code-info(show-line-numbers: true)
```rust
pub fn add(a: i32, b: i32) -> i32 {
a + b
}
pub fn sub(a: i32, b: i32) -> i32 {
a - b
}
pub fn mul(a: i32, b: i32) -> i32 {
a * b
}
pub fn div(a: i32, b: i32) -> i32 {
a / b
}
```
````
yields:

### Diff highlighting
````typst
#import "../../plugin.typ": init-code-info, code-info, parse-diff-code
#show: init-code-info.with()
#code-info(
diff: true,
show-line-numbers: true,
always-show-lines: (1,),
)
```rust
pub fn add(a: i32, b: i32) -> i32 {
a + b
}
pub fn sub(a: i32, b: i32) -> i32 {
a - b
}
pub fn mul(a: i32, b: i32) -> i32 {
a * b
}
pub fn div(a: i32, b: i32) -> i32 {
a / b
}
```
```rust
pub fn add(a: i32, b: i32) -> i32 {
a + b
}
pub fn sub(a: i32, b: i32) -> i32 {
let c = a - b;
c
}
pub fn mul(a: i32, b: i32) -> i32 {
a * b
}
pub fn div(a: i32, b: i32) -> i32 {
a / b
}
```
````
yields:

### Captions
````typst
#import "../../plugin.typ": init-code-info, code-info, parse-diff-code
#show: init-code-info.with()
#code-info(
caption: [A program to display "Hello, world!"],
label: "hello-world",
)
```rust
pub fn main() {
println!("Hello, world!");
}
```
According to @hello-world, the program displays "Hello, world!".
````
yields:

## Development
### Pre-requisites
- **[typstyle](https://github.com/Enter-tainer/typstyle)**: Formatter for Typst files
- **[task](https://taskfile.dev/)**: Task runner
- **[deno](https://deno.com/)**: JavaScript runtime
### Commands
| Command | Description |
| ----------------- | ------------------------------------ |
| `task build` | Build the library |
| `task install` | Install the library |
| `task gen-readme` | Generate the files used in README.md |