Tholp's bespoke website generator
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Convert output to html

Tholp1 aa51ac10 fdd1aaef

+23 -14
+2 -1
.gitignore
··· 1 1 /target 2 - *.out 2 + *.skidout 3 + *.html 3 4 .vscode 4 5 Cargo.lock
+1 -1
Cargo.toml
··· 4 4 edition = "2021" 5 5 6 6 [dependencies] 7 - markdown = "0.3.0" 7 + markdown = "1.0.0-alpha.21"
+1
c.sk
··· 1 + 1 2 See?
+13 -8
src/main.rs
··· 15 15 }; 16 16 use stringtools::{collect_arguments, split_keep_delimiters, strings_to_tokens}; 17 17 use types::{InputFile, Macro, Token}; 18 + use markdown::{to_html_with_options, CompileOptions, Options}; 18 19 19 20 static DELIMITERS: [char; 7] = [' ', '\n', '\t', '(', ')', '{', '}']; 20 21 ··· 25 26 26 27 for file in args.iter() { 27 28 let mut new_file = types::InputFile::new(); 28 - new_file.filename_in = file.to_string(); 29 - new_file.filename_out = file.to_string() + ".out"; 29 + new_file.filename_input = file.to_string(); 30 + new_file.filename_skidout = file.to_string() + ".skidout"; 31 + new_file.filename_htmlout = file.to_string() + ".html"; 30 32 files.push(new_file); 31 33 } 32 34 println!("{:?}", args); ··· 36 38 } 37 39 38 40 fn process_file(file: &mut InputFile) { 39 - let contents = fs::read_to_string(&file.filename_in).expect("File unreadable or missing"); 41 + let contents = fs::read_to_string(&file.filename_input).expect("File unreadable or missing"); 40 42 //println!("{}\n {}", f.filename_out, contents); 41 43 42 - file.tokens = strings_to_tokens(split_keep_delimiters(contents), file.filename_in.clone()); 44 + file.tokens = strings_to_tokens(split_keep_delimiters(contents), file.filename_input.clone()); 43 45 44 46 let mut index = 0; 45 47 ··· 56 58 println!("Found a macro ({})", m.symbol); 57 59 let mut ephemeral = false; 58 60 if file.tokens[index].contents.starts_with('&') 59 - && file.tokens[index].origin_file != file.filename_in 61 + && file.tokens[index].origin_file != file.filename_input 60 62 { 61 63 println!("Skipping Ephermal macro from included file."); 62 64 ephemeral = true; ··· 87 89 index += 1; 88 90 } 89 91 //println!("{:?}", file.tokens); 90 - let mut full_output: String = "".to_string(); 92 + let mut skid_output: String = "".to_string(); 91 93 for t in &file.tokens { 92 - full_output += &t.contents; 94 + skid_output += &t.contents; 93 95 } 94 - fs::write(&file.filename_out, full_output).expect("Couldn't write to file"); 96 + fs::write(&file.filename_skidout, &skid_output).expect("Couldn't write skid to file"); 97 + 98 + let html_output = markdown::to_html_with_options(&skid_output, &Options::gfm()).unwrap(); 99 + fs::write(&file.filename_htmlout, &html_output).expect("Couldn't write html to file"); 95 100 }
+6 -4
src/types.rs
··· 20 20 } 21 21 22 22 pub struct InputFile { 23 - pub filename_in: String, 24 - pub filename_out: String, 23 + pub filename_input: String, 24 + pub filename_skidout: String, 25 + pub filename_htmlout: String, 25 26 pub tokens: Vec<Token>, 26 27 pub block_edges: Vec<BlockEdge>, 27 28 } ··· 36 37 impl InputFile { 37 38 pub fn new() -> InputFile { 38 39 InputFile { 39 - filename_in: "".to_string(), 40 - filename_out: "".to_string(), 40 + filename_input: "".to_string(), 41 + filename_skidout: "".to_string(), 42 + filename_htmlout: "".to_string(), 41 43 tokens: Vec::new(), 42 44 block_edges: Vec::new(), 43 45 }