Skip to content

Code

code.python exports CurrentLine, MoveXStart, MoveXEnd, and insert_highlighted(manifest, colors, grid, text, language='js', ...). code.syntax is a brokered HTTP data source. With syntax service 1.2.0, it supports JavaScript and TypeScript (including JSX and TSX), Python, C, C++, C#, Java, Go, Rust, Ruby, PHP, Swift, Kotlin, shell scripts, SQL, HTML, CSS, JSON, YAML, Markdown, and other common formats. Language IDs and aliases are case-insensitive. Examples include js, ts, py, cpp, c++, bash, and yml. The configured syntax service is authoritative for additional grammar IDs; language names and aliases are case-insensitive. Highlighting is performed during authoring, so rendering remains deterministic after spans are inserted into the grid.

The example uses Source Code Pro. Make that font available in your project before running it. Animate provides syntax highlighting for the selected Code package.

Managed-project example

Select "Code": "3.1.0" under packages in project.json. Import the core and package APIs at module scope.

from manifest import Video2d, TextGrid, Font, Position, FadeIn, Move, project, color_schemes
from manifest.code import insert_highlighted, CurrentLine

colors = color_schemes['neutral.colors']

def build(seq, frame):
    grid = TextGrid(frame, 28, font=Font('Source Code Pro'))
    grid.props.position = Position(60, 60)
    letters = insert_highlighted(project, colors, grid, 'count = 3  # items',
                                      language='python', opacity=0)
    marker = CurrentLine(grid, 0, color=colors['accent'])
    seq.show(FadeIn(letters, time=.5))
    seq.show(Move(marker, Position(0, 1), time=.5))

def make_video():
    return Video2d(build)

TextGrid, Position, Font, FadeIn, and Move are core imports. The library activates the selected plugins before construction. Use grid.insert() for plain text when no highlighting service is configured. CurrentLine itself does not call a service. Its x_start and x_end properties are horizontal endpoints in resolved coordinates; MoveXStart and MoveXEnd animate those endpoints. Its y position is measured in grid rows.

insert_highlighted accepts position to set the grid cursor, prefix/postfix for syntax context, and opacity for newly inserted characters. It returns the character list. Supply foreground, keyword, string, number, and comment in the palette. A missing category used by the result raises KeyError. The Neutral palette supplies all five keys.

Version 1.0.0 · Package API 1 · Code API reference