Skip to content

hongjr03/typst-zebraw

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

77 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🦓 Zebraw

Zebraw is a lightweight and fast package for displaying code blocks with line numbers in typst, supporting code line highlighting. The term zebraw is a combination of zebra and raw, for the highlighted lines will be displayed in the code block like a zebra lines.

Starting

Import zebraw package by #import "@preview/zebraw:0.4.8": * then follow with #show: zebraw to start using zebraw in the simplest way. To manually display some specific code blocks in zebraw, you can use #zebraw() function:

typst-block

Features

Line Numbering

Line numbers will be displayed on the left side of the code block. By passing an integer to the numbering-offset parameter, you can change the starting line number. The default value is 0.

typst-block

To disable line numbering, pass false to the numbering parameter:

typst-block

Line Highlighting

You can highlight specific lines in the code block by passing the highlight-lines parameter to the zebraw function. The highlight-lines parameter can be a single line number or an array of line numbers.

typst-block

Comment

You can add comments to the highlighted lines by passing an array of line numbers and comments to the highlight-lines parameter.

typst-block

Comments can begin with a flag, which is ">" by default. You can change the flag by passing the comment-flag parameter to the zebraw function:

typst-block

To disable the flag feature, pass "" to the comment-flag parameter (the indentation of the comment will be disabled as well):

typst-block

Header and Footer

Usually, the comments passing by a dictionary of line numbers and comments are used to add a header or footer to the code block:

typst-block

Or you can use header and footer parameters to add a header or footer to the code block:

typst-block

Language Tab

If lang is set to true, then there will be a language tab on the top right corner of the code block:

typst-block

Customize the language to display by pass a string or content to the lang parameter.

typst-block

Copyable

Line numbers will not be selected when selecting exported code in one page.

typst-block

Theme

PRs are welcome!

typst-block

typst-block

(Experimental) HTML Export

See example-html.typ or GitHub Pages for more information.

HTML Export

Customization

There are 3 ways to customize code blocks in your document:

  • Manually render some specific blocks by #zebraw() function and passing parameters to it.
  • By passing parameters to #show: zebraw.with() will affect every raw block after the #show rule, except blocks created manually by #zebraw() function.
  • By passing parameters to #show: zebraw-init.with() will affect every raw block after the #show rule, including blocks created manually by #zebraw() function. By using zebraw-init without any parameters, the values will be reset to default.

Inset

Customize the inset of each line by passing a to the inset parameter:

typst-block

Colors

Customize the background color by passing a or an of s to the background-color parameter.

typst-block

Customize the highlight color by passing a to the highlight-color parameter:

typst-block

Customize the comments' background color by passing a to the comment-color parameter:

typst-block

Customize the language tab's background color by passing a to the lang-color parameter.

typst-block

Font

To customize the arguments of comments' font, the language tab's font or the numberings' font, pass a dictionary to comment-font-args parameter, lang-font-args parameter or numbering-font-args parameter.

Language tab will be rendered as comments if nothing is passed.

typst-block

typst-block

Extend

Extend at vertical is enabled at default. When there's header or footer it will be automatically disabled.

typst-block

Documentation

The default value of most parameters are none for it will use the default value in zebraw-init.

typst-block

Example

typst-block

License

Zebraw is licensed under the MIT License. See the LICENSE file for more information.

About

Displaying code blocks with line numbers and line highlighting.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published