1pub mod default_renderer;
2#[cfg(debug_assertions)]
3pub mod test_renderer;
4
5use ratatui::style::Style;
6use textwrap::core::Fragment;
7use wiki_api::document::{Document, Node};
8
9#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
10pub struct Word {
11 pub index: usize,
12 pub content: String,
13 pub style: Style,
14 pub width: f64,
16 pub whitespace_width: f64,
18 pub penalty_width: f64,
20}
21
22impl<'a> Word {
23 pub fn node(&self, document: &'a Document) -> Option<Node<'a>> {
24 document.nth(self.index)
25 }
26}
27
28impl Fragment for Word {
29 #[inline]
30 fn width(&self) -> f64 {
31 self.width
32 }
33
34 #[inline]
35 fn whitespace_width(&self) -> f64 {
36 self.whitespace_width
37 }
38
39 #[inline]
40 fn penalty_width(&self) -> f64 {
41 self.penalty_width
42 }
43}
44
45#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
46pub struct RenderedDocument {
47 pub lines: Vec<Vec<Word>>,
48 pub links: Vec<(usize, usize)>,
50}