<!DOCTYPE md> now required
This commit is contained in:
parent
67a5096267
commit
d55d70ec45
25
src/main.rs
25
src/main.rs
@ -21,7 +21,7 @@ fn parse_markdown(page_content: String) -> (String, Vec<String>) {
|
|||||||
let mut parsed_page_content: String = "".to_string();
|
let mut parsed_page_content: String = "".to_string();
|
||||||
let mut hyperlink_number_counter: u64 = 0;
|
let mut hyperlink_number_counter: u64 = 0;
|
||||||
let mut links: Vec<String> = Vec::new();
|
let mut links: Vec<String> = Vec::new();
|
||||||
let (screen_width, screen_height) = termion::terminal_size().unwrap(); // So the horizontal line (<hr/>) spans the whole console
|
let (screen_width, _screen_height) = termion::terminal_size().unwrap(); // So the horizontal line (<hr/>) spans the whole console
|
||||||
|
|
||||||
for line in page_content.lines() {
|
for line in page_content.lines() {
|
||||||
let mut parsed_line: String = line.to_string();
|
let mut parsed_line: String = line.to_string();
|
||||||
@ -140,7 +140,7 @@ fn parse_markdown(page_content: String) -> (String, Vec<String>) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn fetch_page(host: &String, port: u16, path: &String) -> String {
|
fn fetch_page(host: &String, port: u16, path: &String) -> String {
|
||||||
let full_url_formatted = format!("{}:{}/{}", host, port, path);
|
let full_url_formatted = format!("{}:{}{}", host, port, path);
|
||||||
|
|
||||||
// Call curl using Com, mand
|
// Call curl using Com, mand
|
||||||
let output = Command::new("curl")
|
let output = Command::new("curl")
|
||||||
@ -163,14 +163,19 @@ fn render_page(host: String, port: u16, path: String) -> Vec<String> {
|
|||||||
clear_screen();
|
clear_screen();
|
||||||
let mut content = fetch_page(&host, port, &path);
|
let mut content = fetch_page(&host, port, &path);
|
||||||
let mut links = Vec::new();
|
let mut links = Vec::new();
|
||||||
let (screen_width, screen_height) = termion::terminal_size().unwrap();
|
let (screen_width, _screen_height) = termion::terminal_size().unwrap();
|
||||||
|
|
||||||
(content, links) = parse_markdown(content);
|
if &content[..13] == "<!DOCTYPE md>" {
|
||||||
|
(content, links) = parse_markdown((&content[13..]).to_string());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
content += &format!("{}", &"Warning: This page is invalid markdown, it should contain <!DOCTYPE md> at the very start of the file, showing raw text".yellow());
|
||||||
|
}
|
||||||
|
|
||||||
for _i in 0..screen_width {
|
for _i in 0..screen_width {
|
||||||
print!("—");
|
print!("—");
|
||||||
}
|
}
|
||||||
print!("{}:{}/{}\n", host, port, path);
|
print!("{}:{}{}\n", host, port, path);
|
||||||
for _i in 0..screen_width {
|
for _i in 0..screen_width {
|
||||||
print!("—");
|
print!("—");
|
||||||
}
|
}
|
||||||
@ -230,7 +235,7 @@ fn parse_url(user_input: String, previous_host: &String) -> Result<Url, u8> {
|
|||||||
else if let Some(caps) = path_change.captures(&user_input) {
|
else if let Some(caps) = path_change.captures(&user_input) {
|
||||||
url.hostname = previous_host.to_string();
|
url.hostname = previous_host.to_string();
|
||||||
url.port = 3477;
|
url.port = 3477;
|
||||||
url.path = caps[1].to_string();
|
url.path = format!("/{}", caps[1].to_string());
|
||||||
url.protocol = "mttp".to_string();
|
url.protocol = "mttp".to_string();
|
||||||
Ok(url)
|
Ok(url)
|
||||||
}
|
}
|
||||||
@ -297,10 +302,10 @@ fn main() {
|
|||||||
if load_page {
|
if load_page {
|
||||||
links = Vec::new();
|
links = Vec::new();
|
||||||
links = render_page(history[historical_position].hostname.clone(), history[historical_position].port.clone(), history[historical_position].path.clone());
|
links = render_page(history[historical_position].hostname.clone(), history[historical_position].port.clone(), history[historical_position].path.clone());
|
||||||
println!("Enter reference number to follow, h for help, or q to quit\n{}",historical_position);
|
println!("Enter reference number to follow, h for help, or q to quit");
|
||||||
for i in 0..history.len() {
|
//for i in 0..history.len() {
|
||||||
println!("{}://{}:{}/{}",history[i].protocol,history[i].hostname, history[i].port, history[i].path);
|
// println!("{}://{}:{}/{}",history[i].protocol,history[i].hostname, history[i].port, history[i].path);
|
||||||
}
|
//}
|
||||||
}
|
}
|
||||||
load_page = false;
|
load_page = false;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user