upend/tools/upend_text/src/lib.rs

46 lines
1018 B
Rust

use pulldown_cmark::{Options, Parser};
pub struct Annotation {
pub id: String,
pub body: String,
pub target: String,
}
pub struct MarkdownResult {
pub text: String,
pub annotations: Vec<Annotation>,
}
#[derive(Debug)]
pub struct UpEndTextError(pub String);
impl std::fmt::Display for UpEndTextError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{:#?}", self.0)
}
}
pub fn markdown_to_annotations(markdown: &str) -> Result<MarkdownResult, UpEndTextError> {
let mut options = Options::empty();
options.insert(Options::ENABLE_STRIKETHROUGH);
let parser = Parser::new_ext(markdown, options);
for ev in parser {
println!("{:?}", ev);
}
todo!()
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn it_works() {
let markdown_input = "Hello world, this is a ~~complicated~~ *very simple* example.";
let result = markdown_to_annotations(markdown_input);
result.unwrap();
}
}