Add html.rs viewer
This commit is contained in:
28
src/viewer/html.rs
Normal file
28
src/viewer/html.rs
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
//! HTML 檢視器
|
||||||
|
|
||||||
|
use anyhow::Result;
|
||||||
|
|
||||||
|
pub struct HtmlViewer {
|
||||||
|
content: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl HtmlViewer {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Self { content: None }
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn load_file(&mut self, path: &str) -> Result<String> {
|
||||||
|
let content = std::fs::read_to_string(path)?;
|
||||||
|
self.content = Some(content.clone());
|
||||||
|
Ok(content)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn load_content(&mut self, html: &str) -> String {
|
||||||
|
self.content = Some(html.to_string());
|
||||||
|
html.to_string()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_content(&self) -> Option<&str> {
|
||||||
|
self.content.as_deref()
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user