Keep context implementations with their document models
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
use std::collections::{HashMap, HashSet};
|
||||
|
||||
use super::contextualize::Contextualize;
|
||||
|
||||
use thiserror::Error;
|
||||
|
||||
use crate::{Document, DocumentId};
|
||||
@@ -79,3 +81,24 @@ impl DocumentTree {
|
||||
.chain(self.descendants.iter().map(|(depth, node)| (*depth, node)))
|
||||
}
|
||||
}
|
||||
|
||||
impl Contextualize for DocumentTree {
|
||||
fn render_context(&self) -> String {
|
||||
let mut text = String::new();
|
||||
let mut first_line = true;
|
||||
for (depth, node) in self.nodes() {
|
||||
let rendered = node.render_context();
|
||||
for line in rendered.split('\n') {
|
||||
if !first_line {
|
||||
text.push('\n');
|
||||
}
|
||||
first_line = false;
|
||||
for _ in 1..depth {
|
||||
text.push_str(" ");
|
||||
}
|
||||
text.push_str(line);
|
||||
}
|
||||
}
|
||||
text
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user