diff options
| author | Federico Igne <git@federicoigne.com> | 2022-04-24 11:02:22 +0100 |
|---|---|---|
| committer | Federico Igne <git@federicoigne.com> | 2022-05-27 00:44:00 +0100 |
| commit | 912030d629ee39be2be25991ed1c8bd08b678c01 (patch) | |
| tree | 3f8915b60d65176e0eb38836a175ed1f42a06ca2 | |
| parent | f5df9e6e301e5dd76b1b93ee01ad4035c9db90b0 (diff) | |
| download | pangler-912030d629ee39be2be25991ed1c8bd08b678c01.tar.gz pangler-912030d629ee39be2be25991ed1c8bd08b678c01.zip | |
feat: add simple codeblock indentation
| -rw-r--r-- | src/main.rs | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/src/main.rs b/src/main.rs index 13824df..67cea60 100644 --- a/src/main.rs +++ b/src/main.rs | |||
| @@ -10,10 +10,17 @@ type Blocks<'a> = HashMap<&'a str,&'a str>; | |||
| 10 | 10 | ||
| 11 | fn build(blocks: &Blocks, entry: &str) -> String { | 11 | fn build(blocks: &Blocks, entry: &str) -> String { |
| 12 | lazy_static! { | 12 | lazy_static! { |
| 13 | static ref RE: Regex = Regex::new(r"<<([^>\s]+)>>").unwrap(); | 13 | static ref RE: Regex = Regex::new(r"([ \t]*)<<([^>\s]+)>>").unwrap(); |
| 14 | } | 14 | } |
| 15 | if let Some(entry) = blocks.get(entry).clone() { | 15 | if let Some(entry) = blocks.get(entry).clone() { |
| 16 | RE.replace_all(entry, |caps: &Captures| blocks.get(&caps[1]).expect("Block not present")).to_string() | 16 | RE.replace_all(entry, |caps: &Captures| |
| 17 | blocks.get(&caps[2]) | ||
| 18 | .expect("Block not present") | ||
| 19 | .lines() | ||
| 20 | .map(|l| format!("{}{}", &caps[1], l) ) | ||
| 21 | .collect::<Vec<_>>() | ||
| 22 | .join("\n") | ||
| 23 | ).to_string() | ||
| 17 | } else { | 24 | } else { |
| 18 | String::from("") | 25 | String::from("") |
| 19 | } | 26 | } |
| @@ -32,16 +39,17 @@ fn main() -> Result<()> { | |||
| 32 | let mut blocks: Blocks = HashMap::new(); | 39 | let mut blocks: Blocks = HashMap::new(); |
| 33 | pandoc.blocks.iter().for_each(|block| | 40 | pandoc.blocks.iter().for_each(|block| |
| 34 | if let Block::CodeBlock(attr, code) = block { | 41 | if let Block::CodeBlock(attr, code) = block { |
| 42 | dbg!(block); | ||
| 35 | if attr.0.len() > 0 { | 43 | if attr.0.len() > 0 { |
| 36 | blocks.insert(&attr.0, &code); | 44 | blocks.insert(&attr.0, &code); |
| 37 | } /*else { | 45 | } else { |
| 38 | println!("The following code has no ID:"); | 46 | // println!("The following code has no ID:"); |
| 39 | code.lines().for_each(|l| println!(" {}", l)); | 47 | // code.lines().for_each(|l| println!(" {}", l)); |
| 40 | }*/ | 48 | } |
| 41 | } | 49 | } |
| 42 | ); | 50 | ); |
| 43 | let program = build(&blocks, "main.rs"); | 51 | let program = build(dbg!(&blocks), "main.rs"); |
| 44 | println!("{}", program); | 52 | //println!("{}", program); |
| 45 | pandoc | 53 | pandoc |
| 46 | })); | 54 | })); |
| 47 | pandoc.execute().unwrap(); | 55 | pandoc.execute().unwrap(); |
