Keep context implementations with their document models
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::contextualize::Contextualize;
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
|
||||
#[serde(tag = "kind", content = "data", rename_all = "snake_case")]
|
||||
pub enum Inline {
|
||||
@@ -16,3 +18,21 @@ impl From<&str> for RichText {
|
||||
Self(vec![Inline::Text(value.into())])
|
||||
}
|
||||
}
|
||||
|
||||
impl Contextualize for RichText {
|
||||
fn render_context(&self) -> String {
|
||||
let mut text = String::new();
|
||||
for item in &self.0 {
|
||||
match item {
|
||||
Inline::Text(value) => text.push_str(value),
|
||||
Inline::Link { label, url } => {
|
||||
text.push_str(label);
|
||||
text.push_str(" (");
|
||||
text.push_str(url);
|
||||
text.push(')');
|
||||
}
|
||||
}
|
||||
}
|
||||
text
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user