diff --git a/src/renderer/html_handlebars/hbs_renderer.rs b/src/renderer/html_handlebars/hbs_renderer.rs index 8d687603..acd06ef0 100644 --- a/src/renderer/html_handlebars/hbs_renderer.rs +++ b/src/renderer/html_handlebars/hbs_renderer.rs @@ -72,6 +72,7 @@ impl Renderer for HtmlHandlebars { try!(f.read_to_string(&mut content)); // Render markdown using the pulldown-cmark crate + helpers::playpen::render_playpen(&mut content); content = utils::render_markdown(&content); print_content.push_str(&content); diff --git a/src/renderer/html_handlebars/helpers/mod.rs b/src/renderer/html_handlebars/helpers/mod.rs index 62fc6149..2fc287c2 100644 --- a/src/renderer/html_handlebars/helpers/mod.rs +++ b/src/renderer/html_handlebars/helpers/mod.rs @@ -1,2 +1,3 @@ pub mod navigation; pub mod toc; +pub mod playpen; diff --git a/src/renderer/html_handlebars/helpers/playpen.rs b/src/renderer/html_handlebars/helpers/playpen.rs new file mode 100644 index 00000000..adc63978 --- /dev/null +++ b/src/renderer/html_handlebars/helpers/playpen.rs @@ -0,0 +1,53 @@ +use std::path::{Path, PathBuf}; + +pub fn render_playpen(s: &mut str) { + + for playpen in find_playpens(s) { + println!("Playpen{{ {}, {}, {:?}, {} }}", playpen.start_index, playpen.end_index, playpen.rust_file, playpen.editable); + } + +} + +struct Playpen{ + start_index: u32, + end_index: u32, + rust_file: PathBuf, + editable: bool +} + +fn find_playpens(s: &str) -> Vec { + let mut playpens = vec![]; + for (i, _) in s.match_indices("{{#playpen") { + println!("[*]: find_playpen"); + + // DON'T forget the "+ i" else you have an index out of bounds error !! + let end_i = if let Some(n) = s[i..].find("}}") { n } else { continue } + i + 2; + + println!("s[{}..{}] = {}", i, end_i, s[i..end_i].to_string()); + + // If there is nothing between "{{#playpen" and "}}" skip + if end_i-2 - (i+10) < 1 { continue } + if s[i+10..end_i-2].trim().len() == 0 { continue } + + println!("{}", s[i+10..end_i-2].to_string()); + + // Split on whitespaces + let params: Vec<&str> = s[i+10..end_i-2].split_whitespace().collect(); + let mut editable = false; + + if params.len() > 1 { + editable = if let Some(_) = params[1].find("editable") {true} else {false}; + } + + playpens.push( + Playpen{ + start_index: i as u32, + end_index: end_i as u32, + rust_file: PathBuf::from(params[0]), + editable: editable, + } + ) + } + + playpens +}