highlight

package
v1.2.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 15, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package highlight provides syntax highlighting for English source code.

It exposes two main entry points:

  • Highlight(source, useColor) – colour an entire source file
  • HighlightInline(text, useColor) – highlight English code snippets embedded inside prose text (e.g. error-message hints that contain single-quoted examples like `'Declare x to be 5.'`)

When useColor is false both functions return plain text with no ANSI codes.

Both functions use the shared tokeniser package so that keyword recognition, multi-word operators, possessive handling, and every other tokenisation rule are identical to those used by the actual compiler.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Highlight

func Highlight(source string, useColor bool) string

Highlight returns source with ANSI syntax highlighting applied when useColor is true. If the source contains unrecognised characters the remainder is coloured in a dim grey so that as much as possible is highlighted while invalid sections are still clearly distinguishable.

func HighlightInline

func HighlightInline(text string, useColor bool) string

HighlightInline scans text for English code snippets delimited by single quotes (e.g. the hint strings produced by parser/messages.go) and applies syntax highlighting to each snippet. Surrounding prose is returned unchanged.

When useColor is false the text is returned unmodified.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL