diff --git a/src/main.rs b/src/main.rs index 836680b..e8e1c18 100644 --- a/src/main.rs +++ b/src/main.rs @@ -44,104 +44,13 @@ fn renderer(path: FullPath, user_agent: String) -> Box { .collect(), false => vec![target_path], }; - /*for i in &page_contents { - println!("{:?}", i); - }*/ if user_agent.starts_with("curl/") { println!("displaying curl formatting"); - /*let box_opts = boxen::builder() - .border_style(boxen::BorderStyle::Round) - .width(60) - .padding(3) - .text_alignment(boxen::TextAlignment::Center);*/ let page_markdowns: Vec = page_contents .iter() .map(|x| { - /*let md_two = Markdown::new(std::fs::read_to_string(x).unwrap_or_default()); - let console = rich_rs::Console::new(); - let options = ConsoleOptions::default(); - let seg = md_two.render(&console, &options); - for s in seg { - println!("{}", s.text); - }*/ - // println!("{}", seg); - // - - /*let mut frier = mdfrier::MdFrier::new().unwrap(); - let lines = frier.parse( - 60, - std::fs::read_to_string(x).unwrap().as_str(), - &mdfrier::DefaultMapper, - ); - let text: String = lines - .iter() - .flat_map(|l| l.spans.iter().map(|s| s.content.as_str())) - .collect();*/ - - //println!("{}", text); - - //let dm = tree_sitter_md::MarkdownParser::default(); - //tree_sitter_md::MarkdownCursor::type_id - //dm.parse(std::fs::read(x).unwrap(), old_tree); - /* - /*let mut md_parser = mdriver::StreamingParser::with_width( - "Solarized (dark)", - mdriver::ImageProtocol::None, - 60, - );*/*/ - /*let mut md_parser = mdriver::StreamingParser::new(); - let mdd = mdriver::StreamingParser::new() - .feed(std::fs::read_to_string(x).unwrap_or_default().as_str()); - //let mdd = md_parser - // .format_inline(std::fs::read_to_string(x).unwrap_or_default().as_str()); - - let mddd = md_parser.feed(mdd.as_str()); - let mdddd = md_parser.wrap_text(mddd.as_str(), " ", ""); - - println!("{}", mdddd);*/ - let source = std::fs::read_to_string(x).unwrap(); - /*let theme = mq_markdown::ColorTheme { - heading:"", - code:"", - code_inline:"", - emphasis:"", - strong:"", - link:"", - link_url:"", - image:"", - blockquote_marker:"", - delete:"", - horizontal_rule:"", - html:"", - frontmatter:"", - list_marker:"", - table_separator:"", - math:"", - };*/ - /*let theme = ColorTheme { - heading: ("\u{1b}[1m\u{1b}[36m", "\u{1b}[0m"), - code: ("\u{1b}[32m", "\u{1b}[0m"), - code_inline: ("\u{1b}[32m", "\u{1b}[0m"), - emphasis: ("\u{1b}[3m\u{1b}[33m", "\u{1b}[0m"), - strong: ("\u{1b}[1m", "\u{1b}[0m"), - link: ("\u{1b}[4m\u{1b}[34m", "\u{1b}[0m"), - link_url: ("\u{1b}[34m", "\u{1b}[0m"), - image: ("\u{1b}[35m", "\u{1b}[0m"), - blockquote_marker: ("\u{1b}[2m", "\u{1b}[0m"), - delete: ("\u{1b}[31m\u{1b}[2m", "\u{1b}[0m"), - horizontal_rule: ("\u{1b}[2m", "\u{1b}[0m"), - html: ("\u{1b}[2m", "\u{1b}[0m"), - frontmatter: ("\u{1b}[2m", "\u{1b}[0m"), - list_marker: ("\u{1b}[33m", "\u{1b}[0m"), - table_separator: ("\u{1b}[2m", "\u{1b}[0m"), - math: ("\u{1b}[32m", "\u{1b}[0m"), - };*/ - //println!("{:?}", ColorTheme::COLORED); - //mq_markdown::ColorTheme::from(value) - - //Markdown::to_colored_string_with_theme(&self, theme) let mut mq: mq_markdown::Markdown = source.parse().unwrap(); let render_opts = RenderOptions { list_style: ListStyle::Dash, @@ -150,33 +59,11 @@ fn renderer(path: FullPath, user_agent: String) -> Box { }; mq.set_options(render_opts); let theme = ColorTheme::parse_colors("heading=34:code=31"); - //mq.to_html(); mq.to_colored_string_with_theme(&theme); - /*for n in &mut mq.nodes { - if n.is_heading(Some(1)) { - //println!("{:#?}", n.node_values()); - n.set_attr("value", "test_value"); - //n. - }; - }*/ - /*let new_mq: Vec = mq - .nodes - .clone() - .iter_mut() - .map(|n| { - if n.ite .is_heading(Some(1)) { - n.set_attr("value", "test_value"); - }; - n.to_owned() - }) - .collect(); - let new_q = Markdown::new(new_mq); - mq.nodes.remove(1);*/ let render_conf = RenderConfig { header_full_width_highlight: false, }; - //mq_view::SyntaxHighlighter::new().highlight("code", Markdown); let styled_mq = mq_view::render_markdown_to_string(&mq).unwrap(); let mut writer: Vec = Vec::new(); @@ -187,20 +74,6 @@ fn renderer(path: FullPath, user_agent: String) -> Box { println!("{}", render_string); - //MARKLESS IS GREAT - /* - let test = markless::document::Document::parse( - std::fs::read_to_string(x).unwrap().as_str(), - ) - .unwrap(); - for l in test.visible_lines(0, test.line_count()) { - println!("{}", l.as_str()); - } - */ - // - - //println!("{:#?}", test.line_at(1)); - let md = mdriver::StreamingParser::new().feed( termimad::text(std::fs::read_to_string(x).unwrap_or_default().as_str()) .to_string() @@ -214,114 +87,18 @@ fn renderer(path: FullPath, user_agent: String) -> Box { .padding(0, 2, 0, 2) .align_horizontal(lipgloss::position::CENTER); border_style.render(render_string.as_str()) - //let mut table = Table::new("{:<}"); - /*let md_two = rich_rs::Text::from_markup( - std::fs::read_to_string(x).unwrap_or_default().as_str(), - false, - ) - .unwrap_or_default(); - format!("{}", md_two.to_markup())*/ - //blo_cli::styles::border(&md, BorderStyle::Rounded, None) - /*ansi_align_with_options( - md.as_str(), - &AlignOptions::new(ansi_align::Alignment::Center).with_pad("-"), - ) - .to_string()*/ - //println!() - /*boxen::options::DimensionConstraints {} - let boxen_opts = boxen::builder() - .border_style(boxen::BorderStyle::Round) - .title(x.file_stem().unwrap().to_str().unwrap_or_default()) - .width(60) - //.height(0) - .padding(1) - .fullscreen(boxen::FullscreenMode::Custom(|_, _| (70, 1000))) - .text_alignment(boxen::TextAlignment::Center) - .build(); - /*boxen::options::DimensionConstraints { - max_width: Some(40), - max_height: None, - }*/ - boxen("test", Some(boxen_opts)).unwrap()*/ - //builder("test") - /* ( - termimad::text(std::fs::read_to_string(x).unwrap_or_default().as_str()) - .to_string(), - ) - .unwrap()*/ - //.split("\n") - //.map(|y| format!("{}", y)) - //.collect::>() //::>() - /*for line in - termimad::text(std::fs::read_to_string(x).unwrap_or_default().as_str()) - .to_string() - .split("\n") - { - MixedTextContent::new(line) - }*/ - /* MixedTextContent::new( - termimad::text(std::fs::read_to_string(x).unwrap_or_default().as_str()) - .to_string(), - )*/ }) .collect(); for c in &page_markdowns { println!("{}\n", c); } - //beautify::Colors::border() - //let line = ratatui::text::Line::from("text test!"); - // let writer = Vec::new().clone(); - // let be = ratatui::backend::CrosstermBackend::new(writer.clone()); - // let mut term = ratatui::Terminal::new(be).unwrap(); - //term.draw(|f: &mut Frame| f.render_widget(line, f.area())); - //let bytes = writer; - /*ratatui::run(|t| { - // loop { - t.draw(|f| f.render_widget("line", f.area())); - // } - });*/ - - // .draw(|f| f.render_widget(line, f.area())) - // .unwrap(); - // ratatui::run(|term| term.draw(|f| f.render_widget(line, f.area())).unwrap()); - // let string = String::from_utf8(writer.clone()).unwrap(); - // println!("maybe: {}", string); - //todo!(); - //ratatui::widgets::Block::new() - //println!("{:#?}", page_markdowns); - /*let test_text = tui::text::Text::from(); - let test_block = tui::widgets::Paragraph::new("test");*/ - /*let md_element = element! { - View ( - border_style: BorderStyle::Round, - border_color: Color::Blue, - //width: 30, - display: Display::Flex, - ) { - MixedText(contents: page_markdowns) - } - } - .to_string();*/ let page_md_collected = format!("{}\n", page_markdowns.join("\n")); - /* let test = iocraft::prelude::element! { - View( - border_style: BorderStyle::Round, - border_color: Color::Blue, - ) { - Text(content: "Hello, world!") - } - } - .to_string();*/ - //let term = - // format!("{}\n{}", time, termimad::text(page_md_collected.as_str())).to_string(); Box::new(warp::reply::with_status( page_md_collected, - // page_md_collected, warp::http::StatusCode::OK, )) - //println!("{}", page_md_collected) } else { println!("displaying html formatting"); let page_md_packed: Vec = page_contents @@ -348,52 +125,9 @@ fn renderer(path: FullPath, user_agent: String) -> Box { let mut values = std::collections::HashMap::new(); values.insert("time", time.as_str()); values.insert("body", page_md_collected.as_str()); - /*let html = format!(std::fs::read_to_string( - "./assets/template.html", - time, - page_md_collected - ));*/ let html = template.fill_in(&values); - //println!("{}", html.to_string()); Box::new(warp::reply::html(html.to_string())) - //todo!() } - //} - //todo!(); - /*if true { - if user_agent.starts_with("curl/") { - println!("displaying curl formatting"); - let term = format!( - "{}\n{}", - time, - termimad::text( - std::fs::read_to_string("./readme.md") - .unwrap_or_default() - .as_str(), - ) - ) - .to_string(); - Box::new(warp::reply::with_status(term, warp::http::StatusCode::OK)) - } else { - println!("displaying html formatting"); - let md = std::fs::read_to_string("./readme.md").unwrap_or_default(); - let html = format!( - " - - - title! - - - {} - {} - -", - time, - markdown::to_html_with_options(md.as_str(), &markdown::Options::gfm()) - .unwrap_or_default() - ); - Box::new(warp::reply::html(html)) - }*/ } else { println!("could not find path!"); Box::new(warp::reply::with_status(