Tholp's bespoke website generator

fix blocks

Tholp1 0bb5d81b 94b0f56f

Changed files
+49 -23
src
+1 -2
src/macros/insert.rs
···
let mut search_from_root = arg.starts_with("//");
let mut ok = false;
-
if search_from_root
-
{
+
if search_from_root {
arg.drain(0..2); //remove "//"
}
+9 -2
src/macros/mod.rs
···
pub mod clear;
pub mod insert;
pub mod simple_blocks;
+
pub mod template;
use super::types::Macro;
use clear::macro_clear;
use insert::macro_insert;
use simple_blocks::{macro_comment, macro_null, macro_repeat};
+
use template::macro_template;
-
pub static MACRO_LIST: [Macro<'_>; 5] = [
+
pub static MACRO_LIST: [Macro<'_>; 6] = [
// Unscoped
Macro {
symbol: "insert", // Inserts another file
···
has_scope: true,
},
Macro {
-
symbol: "preformatted",
+
symbol: "section",
expand: macro_null,
+
has_scope: true,
+
},
+
Macro {
+
symbol: "template",
+
expand: macro_template,
has_scope: true,
},
];
+27 -16
src/main.rs
···
mod types;
use macros::MACRO_LIST;
-
use markdown::{to_html_with_options, CompileOptions, Options};
+
use markdown::{to_html_with_options, CompileOptions, Options, ParseOptions};
use projectparse::{parse_project, FileIndexing, ProjectContext};
use std::{
env,
···
};
use types::{InputFile, Macro, Token};
-
static DELIMITERS: [char; 12] = [' ', '\n', '\t', '(', ')', '{', '}', '[', ']', '\\', '\'', '\"'];
+
static DELIMITERS: [char; 12] = [
+
' ', '\n', '\t', '(', ')', '{', '}', '[', ']', '\\', '\'', '\"',
+
];
fn main() {
let mut project_folder = PathBuf::from(env::current_dir().unwrap().as_path());
···
while file.working_index < file.tokens.len() {
//look for macros or blocks
-
println!(">\"{}\"<", file.tokens[file.working_index].contents);
+
//println!(">\"{}\"<", file.tokens[file.working_index].contents);
if file.tokens[file.working_index].contents == "\\" {
file.working_index += 2;
···
collect_arguments(&file.tokens[file.working_index..]);
let expansion: Vec<Token>;
let block_tokcount: usize;
-
if ephemeral {
-
expansion = Vec::new();
-
block_tokcount = 0;
-
} else {
-
if m.has_scope {
-
let block: Vec<Token>;
-
(block, block_tokcount) = collect_block(
-
&file.tokens[(file.working_index + args_tokcount)..],
-
);
-
println!("{}", block_tokcount);
+
+
if m.has_scope {
+
println!("is scoped.");
+
let block: Vec<Token>;
+
(block, block_tokcount) =
+
collect_block(&file.tokens[(file.working_index + args_tokcount)..]);
+
+
if ephemeral {
+
expansion = Vec::new();
+
} else {
expansion = (m.expand)(
file,
file.tokens[file.working_index].origin_file,
context,
&args,
-
&block[..],
+
&block[3..block.len() - 3],
);
+
}
+
} else {
+
block_tokcount = 0;
+
+
if ephemeral {
+
expansion = Vec::new();
} else {
-
block_tokcount = 0;
expansion = (m.expand)(
file,
file.tokens[file.working_index].origin_file,
···
compile: CompileOptions {
allow_dangerous_html: true,
allow_dangerous_protocol: true,
+
gfm_tagfilter: false,
+
// gfm_footnote_clobber_prefix:
+
gfm_task_list_item_checkable: true,
+
allow_any_img_src: true,
..CompileOptions::gfm()
},
-
..Options::gfm()
+
..Options::default()
},
)
.unwrap();
+1 -1
src/projectparse.rs
···
impl FileIndexing for ProjectContext {
fn index_of_file(&mut self, f: &PathBuf) -> usize {
-
let mut cannonical = f.canonicalize().unwrap();
+
let cannonical = f.canonicalize().unwrap();
let mut index = 0;
for p in &self.filemap {
if cannonical == *p {
+11 -2
src/stringtools.rs
···
use core::fmt;
-
use std::{ascii::escape_default, fmt::Arguments, ops::Index, process::exit, thread::sleep};
+
use std::{ascii::escape_default, error, fmt::Arguments, ops::Index, process::exit, thread::sleep};
use super::DELIMITERS;
use crate::types::Token;
···
if tok.contents != "{"
// Expected block start, got garbage
{
+
// println!("Expected block start, got {}",tok.contents);
+
// for t in &block
+
// {
+
// print!("{} ", t.contents);
+
// }
+
// exit(1);
return (Vec::new(), 0);
}
}
···
scope_count -= 1;
entering_bracket_count = 0;
}
+
if scope_count == 0 {
+
break;
+
}
} else {
-
entering_bracket_count = 0;
+
exiting_bracket_count = 0;
}
if tok.contents == "\\" {
escaped = true;