Clean up. Remove unnecesary strings.

This commit is contained in:
jacob 2021-03-05 03:06:39 -09:00
parent 458fe33785
commit c3398b75b0
1 changed files with 29 additions and 28 deletions

View File

@ -31,13 +31,17 @@ pub fn handle_header(
if importance < 1 || importance > 6 {
return Err(String::from("Headers must have an importance of 1-6"));
}
state.gemtext.push_str(&format!(
"{}{} {}\n{}",
state.config.empty_lines_before_h_str,
HEADINGS[importance - 1],
header,
state.config.empty_lines_after_h_str
));
state
.gemtext
.push_str(&state.config.empty_lines_before_h_str);
state.gemtext.push_str(HEADINGS[importance - 1]);
state.gemtext.push(' ');
state.gemtext.push_str(header);
state.gemtext.push('\n');
state
.gemtext
.push_str(&state.config.empty_lines_after_h_str);
Ok("")
}
pub fn handle_paragraph_node(state: &mut State, node: &NodeRef) -> Result<&'static str, String> {
@ -49,20 +53,20 @@ pub fn handle_paragraph_node(state: &mut State, node: &NodeRef) -> Result<&'stat
&paragraph_text.borrow(),
state.config.empty_lines_after_p_str
));
Ok("")
} else {
return Err(String::from("Expected text in text paragraph"));
Err(String::from("Expected text in text paragraph"))
}
} else {
return Err(String::from("Expected text node in paragraph"));
Err(String::from("Expected text node in paragraph"))
}
Ok("")
}
pub fn handle_link_node(
state: &mut State,
element_data: &ElementData,
node: &NodeRef,
) -> Result<&'static str, String> {
let link = match element_data.attributes.borrow().get(local_name!("href")) {
match element_data.attributes.borrow().get(local_name!("href")) {
Some(link) => {
let mut link = link.to_owned();
if let Some(ref mydomain) = state.config.convert_mydomain_links_to_gmi {
@ -71,30 +75,27 @@ pub fn handle_link_node(
link.push_str("gmi");
}
}
link
state
.gemtext
.push_str(&state.config.empty_lines_before_a_str);
state.gemtext.push_str("=> ");
state.gemtext.push_str(&link);
}
None => return Err(String::from("Expected link in href on <a> element")),
};
let link_text = if let Some(text_node) = node.first_child() {
if let Some(link_text) = text_node.as_text() {
link_text.borrow().clone()
} else {
String::new()
}
} else {
String::new()
};
state.gemtext.push_str(&format!(
"{}=> {}",
state.config.empty_lines_before_a_str, link
));
if !link_text.is_empty() {
state.gemtext.push_str(&format!(" {}", link_text));
if let Some(text_node) = node.first_child() {
if let Some(link_text) = text_node.as_text() {
state.gemtext.push(' ');
state.gemtext.push_str(&link_text.borrow());
}
}
state.gemtext.push('\n');
state
.gemtext
.push_str(&format!("\n{}", state.config.empty_lines_after_a_str));
.push_str(&state.config.empty_lines_after_a_str);
Ok("")
}
pub fn handle_image_node(