1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
//! The [`Highlighter`] seam — how a host plugs syntax highlighting into
//! [`CodeBlock`](crate::components::CodeBlock) and
//! [`Markdown`](crate::components::Markdown) without tuika taking on any grammar
//! dependency.
//!
//! tuika deliberately depends only on `ratatui`, `crossterm`, `textwrap`, and
//! the `unicode-*` crates; a real highlighter (tree-sitter, syntect, …) pulls in
//! far more. So the toolkit owns only this trait and the *presentation* of code
//! (framing, background, language label, wrapping), while the host supplies the
//! token colors. The companion crate `tuika-codeformatters` ships a tree-sitter
//! implementation; hosts can also write their own.
use Span;
use crateTheme;
/// Turns a fenced code block's source into per-line styled spans.
///
/// Implementations receive the fence's language tag, the block's body split
/// into lines, and the active [`Theme`] (so highlighted tokens follow the host
/// palette via [`Theme::code`](crate::style::CodeTheme)). They return **one span
/// vector per input line** — reconstructing each source line exactly, only
/// restyled — or [`None`] when the language is unknown or the source fails to
/// parse, in which case the caller falls back to unstyled code text.
///
/// The one-line-per-line contract lets callers zip the result against the
/// source without re-deriving line boundaries; an implementation that cannot
/// uphold it (event stream desynced from source lines) must return [`None`].
/// A [`Highlighter`] that highlights nothing — every block renders as plain,
/// theme-colored code text. The default when a caller supplies no highlighter.
;
/// A borrowed highlighter, or the plain fallback. Lets [`CodeBlock`] and
/// [`Markdown`] carry an optional highlighter without a generic parameter
/// leaking through the whole view tree.
///
/// [`CodeBlock`]: crate::components::CodeBlock
/// [`Markdown`]: crate::components::Markdown