diff --git a/src/format/assets/style.css b/src/format/assets/style.css new file mode 100644 index 0000000..8c595e9 --- /dev/null +++ b/src/format/assets/style.css @@ -0,0 +1,37 @@ +body { + background-color: #DDD; +} + +.content { + font-family: "Noto Sans", SansSerif, sans-serif; + width: 100vh; + max-width: 100%; + padding: 2rem; + margin: auto; + background-color: #FFF; + box-shadow: 1em 1em 1em gray; +} + +img { + max-width: 100%; + max-height: 100vh; + height: auto; +} + +blockquote { + border-left: 0.3em solid gray; + border-radius: 0.2em; + padding-left: 0.5em; +} + +.figure { + width: 100%; + display: block; + text-align: center; +} + +.figure .imageDescription { + display: block; + color: #444; + font-style: italic; +} \ No newline at end of file diff --git a/src/format/html.rs b/src/format/html.rs index 26ac1e6..96fa293 100644 --- a/src/format/html.rs +++ b/src/format/html.rs @@ -1,5 +1,15 @@ use crate::elements::*; +macro_rules! combine_with_lb { + ($a:expr, $b:expr) => { + if $a.len() > 0 { + format!("{}
{}", $a, $b.to_html()) + } else { + $b.to_html() + } + }; +} + pub trait ToHtml { fn to_html(&self) -> String; } @@ -50,7 +60,11 @@ impl ToHtml for Document { .iter() .fold("".to_string(), |a, b| format!("{}{}", a, b.to_html())); if self.is_root { - format!("{}", inner) + let style = std::include_str!("assets/style.css"); + format!( + "
{}
", + style, inner + ) } else { format!( "
{}
", @@ -92,7 +106,7 @@ impl ToHtml for Paragraph { let inner = self .elements .iter() - .fold("".to_string(), |a, b| format!("{}
{}", a, b.to_html())); + .fold("".to_string(), |a, b| combine_with_lb!(a, b)); format!("

{}

", inner) } } @@ -173,7 +187,7 @@ impl ToHtml for Quote { let text = self .text .iter() - .fold("".to_string(), |a, b| format!("{}
{}", a, b.to_html())); + .fold("".to_string(), |a, b| combine_with_lb!(a, b)); if let Some(meta) = self.metadata.clone() { format!( "
{}
- {}
", @@ -203,12 +217,12 @@ impl ToHtml for Image { fn to_html(&self) -> String { if let Some(description) = self.url.description.clone() { format!( - "
\ - \ - {1}\ - \ - -
", + "
\ + \ + {1}\ + \ + \ +
", self.url.url.clone(), description ) diff --git a/src/main.rs b/src/main.rs index 4852b5d..9f4ef43 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,6 +6,7 @@ use termion::style; use std::path::PathBuf; use structopt::StructOpt; +use termion::color::{Fg, Red}; #[derive(StructOpt, Debug)] struct Opt { @@ -19,6 +20,24 @@ struct Opt { fn main() { let opt: Opt = Opt::from_args(); + if !opt.input.exists() { + println!( + "{}The input file {} could not be found{}", + Fg(Red), + opt.input.to_str().unwrap(), + style::Reset + ); + return; + } + if !opt.output.exists() { + println!( + "{} The output file {} could not be found{}", + Fg(Red), + opt.output.to_str().unwrap(), + style::Reset + ); + return; + } let start = Instant::now(); let mut parser = Parser::new_from_file(opt.input.to_str().unwrap().to_string()).unwrap(); let document = parser.parse(); diff --git a/src/parser.rs b/src/parser.rs index 75d533e..f6e2672 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -352,6 +352,7 @@ impl Parser { header.size = size; self.section_nesting = size; let mut section = Section::new(header); + self.seek_whitespace(); while let Ok(block) = self.parse_block() { section.add_element(block); @@ -417,7 +418,9 @@ impl Parser { && self.check_seek_inline_whitespace() { if let Ok(text) = self.parse_text() { - quote.add_text(text); + if text.subtext.len() > 0 { + quote.add_text(text); + } } else { break; }