### Example Rust Code Block with Codly Source: https://github.com/dherse/codly/blob/main/README.md Demonstrates how a standard Rust code block is rendered by Codly after initialization and potential configuration. The code itself is a simple 'Hello, world!' program. ```rust pub fn main() { println!("Hello, world!"); } ``` -------------------------------- ### Initialize Codly with Default Settings Source: https://github.com/dherse/codly/blob/main/README.md Initializes Codly for Typst documents using a show rule. This setup is typically done once per document to enable Codly's features globally. It imports necessary packages and applies the default configuration. ```typst #import "@preview/codly:1.3.1": * #import "@preview/codly-languages:0.1.1": * #show: codly-init.with() ``` -------------------------------- ### Headers and Footers (Typst, Yaml) Source: https://context7.com/dherse/codly/llms.txt Demonstrates how to add custom headers and footers to code blocks, including options for repeating them. This is useful for adding context, filenames, or source information. YAML is used as the example language. ```typ #codly( header: [*Configuration File*], header-repeat: true, footer: [Source: config.yml], footer-repeat: false, ) ``` ```yaml server: host: localhost port: 8080 database: name: myapp user: admin ``` -------------------------------- ### Initialize Codly and Configure Languages Source: https://context7.com/dherse/codly/llms.txt Initializes the Codly package and configures language-specific settings such as name, icon, and color. This setup ensures proper syntax highlighting and display for different programming languages. It requires the `codly` package and optionally the `codly-languages` package. ```typst #import "@preview/codly:1.3.1": * #show: codly-init.with() #codly(languages: ( rust: (name: "Rust", icon: "🦀", color: rgb("#CE412B")), python: (name: "Python", icon: "🐍", color: rgb("#3776AB")), )) ``` -------------------------------- ### Reset Configuration (Typst) Source: https://context7.com/dherse/codly/llms.txt Shows how to reset Codly's configuration settings back to their default values using `codly-reset()`. This is useful for starting fresh after applying custom settings or for managing configuration across different document sections. ```typ #codly(/* custom settings */) // Reset to defaults #codly-reset() // All settings back to initial values ``` -------------------------------- ### Custom Number Formatting (Typst, Rust) Source: https://context7.com/dherse/codly/llms.txt Illustrates customizing the appearance and alignment of line numbers in code blocks. This allows for unique styling, such as using different colors or prefixes for line numbers. Rust is used as the example language. ```typ #codly( number-format: (n) => text(fill: blue)[→ #n], number-align: right + horizon, ) ``` ```rust fn custom_numbers() { println!("Custom styled line numbers"); } ``` -------------------------------- ### Filename Display (Typst, Rust) Source: https://context7.com/dherse/codly/llms.txt Illustrates how to display a filename in the header of a code block, along with a custom separator. This is useful for indicating the file associated with the code snippet. Rust is used as the example language. ```typ #codly( filename: "main.rs", filename-separator: " • ", display-name: true, ) ``` ```rust fn main() { println!("Filename shown in header"); } ``` -------------------------------- ### Select a Subset of Lines with `codly-range` Source: https://github.com/dherse/codly/blob/main/README.md Selects a specific range of lines from a code block for processing or display. Setting `start` and `end` parameters defines the inclusive boundaries. Using `start: 1` and `end: none` selects all lines from the beginning to the end of the block. ```typst #codly-range(start: 5, end: 10) ``` -------------------------------- ### Custom Stroke Styling (Typst, Rust) Source: https://context7.com/dherse/codly/llms.txt Shows how to apply custom stroke styles, including gradients and thickness, to the border of code blocks. This allows for visually distinct code block borders. Rust is used as the example language. ```typ #codly( stroke: 3pt + gradient.linear(red, blue, angle: 45deg), radius: 8pt, ) ``` ```rust fn styled_border() { println!("Gradient border around code block"); } ``` -------------------------------- ### Local Settings with Scoped Configuration (Typst, Python) Source: https://context7.com/dherse/codly/llms.txt Demonstrates how to apply local configuration settings for code blocks, affecting only the enclosed code. This allows for specific styling or behavior within a limited scope, reverting to global settings afterward. Python is used as an example language for the scoped code. ```typ #show: codly-init.with() #local( default-color: red, stroke: 2pt + red, zebra-fill: none, )[ ```python def special(): # Red theme applied only here pass ``` ] ``` ```python def special(): # Red theme applied only here pass ``` ```python def normal(): # Returns to global settings pass ``` -------------------------------- ### Number Placement Outside (Typst, Python) Source: https://context7.com/dherse/codly/llms.txt Demonstrates placing line numbers outside the bordered area of a code block, providing a cleaner separation between the code and its numbering. Python is used as the example language. ```typ #codly( number-placement: "outside", stroke: 1pt + black, ) ``` ```python def example(): # Line numbers appear outside the bordered area pass ``` -------------------------------- ### Reference Code Lines (Typst, Python) Source: https://context7.com/dherse/codly/llms.txt Demonstrates how to reference specific lines within a code block using Typst's figure system and Codly's capabilities. This is valuable for documentation and tutorials to point out specific parts of the code. Python is used as the example language. ```typ #figure( ```python def example(): result = calculate() return result ```, caption: [Example function] ) ``` ```python def example(): result = calculate() return result ``` -------------------------------- ### Smart Indentation Control (Typst, Python) Source: https://context7.com/dherse/codly/llms.txt Shows how Codly's smart indentation feature helps in maintaining proper alignment for wrapped code lines, improving readability. This is particularly useful for long lines of code. Python is used as the example language. ```typ #codly(smart-indent: true) ``` ```python def nested_example(): for i in range(10): if i % 2 == 0: # Smart indent adjusts wrapping offset print(f"Very long line that will wrap with proper indentation alignment for readability") ``` -------------------------------- ### Customize Stroke Around Code Blocks Source: https://github.com/dherse/codly/blob/main/README.md The stroke (border) surrounding the code block can be customized using the `stroke` parameter. This allows you to change the thickness and color of the border, for example, setting it to `1pt + red`. ```typ #codly(stroke: 1pt + red) ``` -------------------------------- ### Disable Line Numbers (Typst, Javascript) Source: https://context7.com/dherse/codly/llms.txt Shows how to disable line numbers for code blocks using Codly configuration. This is useful when line numbers are not desired or would clutter the presentation. Javascript is used as the example language. ```typ #codly(number-format: none) ``` ```javascript function example() { console.log("No line numbers"); return true; } ``` -------------------------------- ### Add Annotations to Code Lines Source: https://context7.com/dherse/codly/llms.txt Adds custom annotations to spans of lines within a code block using the `annotations` parameter in `#codly()`. Each annotation can define a start and end line, custom content (e.g., explanatory text), and a label for referencing. This is useful for detailed code explanations. ```typst #codly( annotations: ( ( start: 2, end: 4, content: block( width: 2em, rotate(-90deg, align(center, box(width: 100pt)[Function body])) ), label: ), ), ) ```python def fibonacci(n): if n <= 1: return n return fibonacci(n - 1) + fibonacci(n - 2) result = fibonacci(10) ``` // Annotation bracket spans lines 2-4 with custom content // Reference with @annotation-1 ``` -------------------------------- ### Disable Zebra Striping (Typst, Python) Source: https://context7.com/dherse/codly/llms.txt Explains how to disable the default zebra striping (alternating background colors for lines) in code blocks for a uniform look. This allows for a consistent background color across all lines. Python is used as the example language. ```typ #codly(zebra-fill: none, fill: white) ``` ```python def no_stripes(): # Uniform background pass ``` -------------------------------- ### Smart Skip for Ranges (Typst) Source: https://context7.com/dherse/codly/llms.txt Explains Codly's smart skipping feature for code ranges, which replaces omitted lines with indicators. This is useful for displaying only specific parts of large code files while maintaining continuity. Includes an example using `codly-range`. ```typ #codly( smart-skip: (first: true, last: true, rest: false), ) #codly-range(start: 5, end: 8) ``` ```python # Lines 1-4 replaced with skip indicator def visible_function(): line_5 = "shown" line_6 = "shown" line_7 = "shown" line_8 = "shown" # Lines 9+ replaced with skip indicator ``` -------------------------------- ### Select Line Range for Display Source: https://context7.com/dherse/codly/llms.txt Allows specifying a range of lines to be displayed within a code block using `#codly-range(start: n, end: m)`. Lines outside this range are omitted. This is useful for focusing on specific parts of a larger code snippet. ```typst #codly-range(start: 3, end: 6) ```python def example(): line_1 = "not shown" line_2 = "not shown" line_3 = "shown" line_4 = "shown" line_5 = "shown" line_6 = "shown" line_7 = "not shown" ``` // Only lines 3-6 are displayed ``` -------------------------------- ### Skip Last Empty Line (Typst, Python) Source: https://context7.com/dherse/codly/llms.txt Demonstrates Codly's ability to automatically remove the last empty line from a code block, preventing unintended spacing. This ensures cleaner code presentation. Python is used as the example language. ```typ #codly(skip-last-empty: true) ``` ```python def function(): return 42 ``` -------------------------------- ### Set Line Number Offset with Codly Source: https://context7.com/dherse/codly/llms.txt Configures Codly to start line numbering from a specified offset rather than the default of 1. The `#codly-offset(n)` function sets this offset globally for subsequent code blocks. This is useful for exercises or documentation where specific line numbering is required. ```typst #codly-offset(25) ```python def fibonacci(n): if n <= 1: return n return fibonacci(n - 1) + fibonacci(n - 2) print(fibonacci(10)) ``` // Line numbers start at 25 instead of 1 ``` -------------------------------- ### Add Line Skips to Code Blocks Source: https://context7.com/dherse/codly/llms.txt Introduces visual skips in line numbering for code blocks using the `skips` parameter in `#codly()`. `skips: ((start_line, count),)` indicates that `count` lines are skipped starting from `start_line`, and the line numbering continues accordingly. This visually represents omitted code sections. ```typst #codly(skips: ((5, 32),)) ```python def long_function(): line_1 = 1 line_2 = 2 line_3 = 3 line_4 = 4 # Line 5 shows "..." with 32 line jump line_37 = 37 line_38 = 38 ``` // Visual skip indicator with adjusted line numbers ``` -------------------------------- ### Add Highlights to Code Lines Source: https://github.com/dherse/codly/blob/main/README.md This feature allows you to highlight specific parts of lines within your code snippets. You can define the line number, start and end positions for the highlight, and the fill color. Optional tags can also be added to highlighted sections. This is useful for drawing attention to specific code segments. ```typ #codly(highlights: ( (line: 4, start: 2, end: none, fill: red), (line: 5, start: 13, end: 19, fill: green, tag: "(a)"), (line: 5, start: 26, fill: blue, tag: "(b)"), )) ```py def fib(n): if n <= 1: return n else: return fib(n - 1) + fib(n - 2) print(fib(25)) ``` ``` -------------------------------- ### Custom Language Styling (Typst, Mylang) Source: https://context7.com/dherse/codly/llms.txt Explains how to define and apply custom styling for specific programming languages within Codly. This includes setting language names, icons, and colors for a personalized appearance. A custom language 'mylang' is defined. ```typ #codly( languages: ( mylang: ( name: "Custom Language", icon: "🚀", color: rgb("#FF6B35") ) ), lang-fill: (lang) => lang.color.lighten(90%), lang-stroke: (lang) => 2pt + lang.color, ) ``` ```mylang custom syntax here with beautiful styling ``` -------------------------------- ### Configure Global Codly Settings Source: https://context7.com/dherse/codly/llms.txt Sets global configuration options for Codly, affecting aspects like line number formatting and alignment, background fills, stroke, corner radius, and indentation. These settings apply to all subsequent code blocks unless overridden locally. It utilizes Typst's state management for persistent configuration. ```typst #codly( number-format: (number) => [#number], number-align: left + horizon, zebra-fill: luma(240), stroke: 1pt + luma(240), radius: 0.32em, inset: 0.32em, breakable: true, display-name: true, display-icon: true, ) ``` -------------------------------- ### Language Aliases (Typst) Source: https://context7.com/dherse/codly/llms.txt Shows how to create aliases for programming language identifiers, allowing shorter or alternative names to be used when specifying the language. This improves flexibility in code block definition. ```typ #codly(aliases: ( js: "javascript", py: "python", rs: "rust", )) ``` ```js // Automatically translated to javascript console.log("Hello"); ``` -------------------------------- ### Configure Codly with Custom Language Settings Source: https://github.com/dherse/codly/blob/main/README.md Configures Codly with custom parameters, specifically defining settings for the Rust programming language. This includes its display name, icon, and color. This configuration overrides default settings and applies globally unless localized. ```typst #codly( languages: ( rust: (name: "Rust", icon: "🦀", color: rgb("#CE412B")) ) ) ``` -------------------------------- ### Highlight Code Portions with Colors and Tags Source: https://context7.com/dherse/codly/llms.txt Enables highlighting of specific text ranges within lines or entire lines using the `highlights` parameter in `#codly()`. Each highlight can specify a line, start/end character positions, fill color, and an optional tag for referencing. This feature aids in emphasizing critical code segments. ```typst #codly( highlights: ( (line: 4, start: 2, end: none, fill: red.lighten(80%)), (line: 5, start: 13, end: 19, fill: green.lighten(80%), tag: "(a)"), (line: 5, start: 26, fill: blue.lighten(80%), tag: "(b)", label: ) ), ) ```python def fibonacci(n): if n <= 1: return n else: return fibonacci(n - 1) + fibonacci(n - 2) print(fibonacci(25)) ``` // Specific text ranges highlighted with colors and labels // Reference highlights with @highlight-1 ``` -------------------------------- ### Highlight Full Lines with Custom Colors Source: https://context7.com/dherse/codly/llms.txt Highlights entire lines of code using `highlighted-lines` and `highlighted-default-color` in `#codly()`. Specific lines can be assigned custom colors, while others default to a specified color. This helps draw attention to important lines or sections of code. ```typst #codly( highlighted-lines: (2, 4, (6, yellow)), highlighted-default-color: blue.lighten(80%) ) ```python def example(): highlighted_line_2 = "blue background" normal_line = "no highlight" highlighted_line_4 = "blue background" normal_line_2 = "no highlight" highlighted_line_6 = "yellow background" ``` ``` -------------------------------- ### Enable/Disable Codly Formatting Source: https://context7.com/dherse/codly/llms.txt Demonstrates how to globally enable and disable Codly's code block formatting. The `#codly()` function can be used to re-enable formatting after it has been disabled with `#codly-disable()`. This allows for selective application of Codly's styling. ```typst #codly(languages: ( rust: (name: "Rust", icon: "🦀", color: rgb("#CE412B")), )) ```rust // This will be beautifully formatted fn example() {} ``` #codly-disable() ```rust // This will use default Typst formatting fn plain() {} ``` #codly-enable() ```rust // Beautiful formatting is back fn restored() {} ``` ``` -------------------------------- ### Relative Offset from Previous Block Source: https://context7.com/dherse/codly/llms.txt Continues line numbering from a previous code block using the `offset-from` parameter within `#codly()`. This is achieved by referencing a previously defined code block's end point (e.g., ``). This facilitates sequential numbering across multiple code snippets. ```typst ```python def part_one(): print("First part") ``` // Continue numbering from previous block #codly(offset-from: ) ```python def part_two(): print("Second part continues numbering") ``` ``` -------------------------------- ### Add Annotations to Code Lines Source: https://github.com/dherse/codly/blob/main/README.md Annotations can be added to specific lines or ranges of lines in your code. This allows for adding explanatory content or visual cues alongside the code. The annotation content can be complex, including text, shapes, and transformations. ```typ // Add an annotation from the second line (0 indexing) to the 5th line included. #codly( annotations: ( ( start: 2, end: 4, content: block( width: 2em, // Rotate the element to make it look nice rotate( -90deg, align(center, box(width: 100pt)[Function body]) ) ) ), ) ) ``` -------------------------------- ### Local Codly Formatting Control Source: https://context7.com/dherse/codly/llms.txt Shows how to locally disable Codly formatting for specific code blocks using the `#no-codly` directive. Formatting is automatically reapplied after the `#no-codly` block. This provides finer control over which code snippets receive Codly's styling. ```typst #show: codly-init.with() #codly() ```python # This code block has Codly formatting def formatted(): pass ``` #no-codly[ ```python # This code block uses default formatting def plain(): pass ``` ] ```python # Codly formatting automatically restored def formatted_again(): pass ``` ``` -------------------------------- ### Add a Skip Between Lines in Codly Source: https://github.com/dherse/codly/blob/main/README.md Inserts a visual and numerical skip between lines in a code block using the `skips` parameter. This parameter takes a tuple of `(index, number_of_lines)` to define where the skip occurs and its visual length. Line numbers are adjusted to account for the skip. ```typst // Before the 5th line (indexing start at 0), insert a 32 line jump. #codly(skips: ((5, 32), )) ``` -------------------------------- ### Disable Codly Locally Source: https://github.com/dherse/codly/blob/main/README.md Disables Codly's enhancements for the current scope within a Typst document. This allows for specific code blocks to be rendered with standard Typst raw block formatting, bypassing Codly's processing. Codly can be re-enabled later using the `codly` configuration function. ```typst #codly-disable() ``` -------------------------------- ### Disable Codly Locally with `no-codly` Function Source: https://github.com/dherse/codly/blob/main/README.md Achieves the same local disabling effect as `codly-disable()` but uses the `no-codly` function. Content within the `[...]` block will not be processed by Codly. This is useful for selectively rendering raw Typst code blocks. ```typst #no-codly[ ```typ I will be displayed using the normal raw blocks. ``` ] ``` -------------------------------- ### Set a Fixed Line Offset in Codly Source: https://github.com/dherse/codly/blob/main/README.md Applies a fixed offset to the line numbering of a code block without selecting a specific range of lines. The `codly-offset` function takes a number of lines to add to the perceived line count, affecting all subsequent line references and numbering. ```typst // Sets a 5 line offset #codly-offset(5) ``` -------------------------------- ### Set Codly Offset Relative to Another Code Block Source: https://github.com/dherse/codly/blob/main/README.md Configures a code block's offset relative to another code block identified by a Typst label. The `offset-from` parameter allows for dependent line numbering, ensuring consistent spacing and referencing across related code segments. ```typst #codly(offset-from: ) ``` -------------------------------- ### Disable Icon Display Source: https://github.com/dherse/codly/blob/main/README.md The display of an icon associated with the code block can be toggled using the `display-icon` parameter, setting it to `false` to disable it. This setting also impacts other visual aspects such as name, radius, and padding. ```typ #codly(display-icon: false) ``` -------------------------------- ### Disable Zebra Striping in Code Blocks Source: https://github.com/dherse/codly/blob/main/README.md Zebra striping, which alternates background colors for lines, can be disabled by setting the `zebra-fill` parameter to `none` or `white`. This provides a cleaner look for code blocks if alternating line colors are not desired. ```typ #codly(zebra-fill: none) ``` -------------------------------- ### Disable Smart Indentation in Codly Source: https://github.com/dherse/codly/blob/main/README.md Configures Codly to disable the 'smart-indent' feature. By default, Codly automatically adjusts indentation for line wrapping. Setting `smart-indent: false` reverts to standard behavior, which may affect how wrapped lines are aligned. ```typst #codly(smart-indent: false) ``` -------------------------------- ### Disable Line Numbers in Code Blocks Source: https://github.com/dherse/codly/blob/main/README.md This configuration option disables the display of line numbers in the code blocks generated by Codly. It is controlled via the `number-format` parameter within the `codly` function. ```typ #codly(number-format: none) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.