strip blank lines from HTML
This commit is contained in:
parent
0a943bbfa5
commit
cbddf42043
4 changed files with 24 additions and 2 deletions
|
@ -1,10 +1,14 @@
|
||||||
use config::Config;
|
use config::Config;
|
||||||
|
use std::char;
|
||||||
|
|
||||||
use renderers::html_cleanup::html_cleanup;
|
use renderers::html_cleanup::html_cleanup;
|
||||||
|
use renderers::strip_blank::strip_blank;
|
||||||
|
|
||||||
pub fn render(config: Config, input: String) -> Result<String, String> {
|
pub fn render(config: Config, input: String) -> Result<String, String> {
|
||||||
let mut rendered_input = input;
|
let mut rendered_input = input;
|
||||||
for renderer in vec![html_cleanup] {
|
let renderers: Vec<fn(Config, String) -> Result<String, String>> =
|
||||||
|
vec![html_cleanup, strip_blank];
|
||||||
|
for renderer in renderers {
|
||||||
rendered_input = try!(renderer(config.clone(), rendered_input));
|
rendered_input = try!(renderer(config.clone(), rendered_input));
|
||||||
}
|
}
|
||||||
return Ok(rendered_input);
|
return Ok(rendered_input);
|
||||||
|
|
|
@ -10,4 +10,3 @@ pub fn html_cleanup(config: Config, input: String) -> Result<String, String> {
|
||||||
let html = get_html(root);
|
let html = get_html(root);
|
||||||
return Ok(html);
|
return Ok(html);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,3 +3,4 @@ use config::Config;
|
||||||
mod helpers;
|
mod helpers;
|
||||||
|
|
||||||
pub mod html_cleanup;
|
pub mod html_cleanup;
|
||||||
|
pub mod strip_blank;
|
||||||
|
|
18
src/renderers/strip_blank.rs
Normal file
18
src/renderers/strip_blank.rs
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
use std::char;
|
||||||
|
use config::Config;
|
||||||
|
|
||||||
|
fn remove_blank_lines(line: &&str) -> bool {
|
||||||
|
if line.is_empty() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
let whitespace_chars: Vec<&str> = line.matches(char::is_whitespace).collect();
|
||||||
|
if whitespace_chars.len() == line.len() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn strip_blank(config: Config, input: String) -> Result<String, String> {
|
||||||
|
let split: Vec<&str> = input.lines().filter(remove_blank_lines).collect();
|
||||||
|
return Ok(split.join("\n"));
|
||||||
|
}
|
Reference in a new issue