Skip to content

Conversion process

Dzmitry Malyshau edited this page Jun 1, 2018 · 1 revision

The old notes were archived on Google Docs. Process of converting them consists of 2 steps:

  1. Download as "*.txt"
  2. Run over this little Rust program:
use std::fs::{create_dir_all, File};
use std::io::{stdin, BufRead, BufReader, Write};
use std::path::Path;

fn main() {
    let prefix = "Daily - ";
    let list_starts = [' ', '\t', '*' , '-'];
    let mut current = File::create("dummy.md").unwrap();
    let mut in_list = false;
    for line in BufReader::new(stdin()).lines() {
        let line = line.unwrap();
        // Note: the prefix may start *after* the special UTF byte order mark...
        if let Some(pos) = line.find(prefix) {
            let path = Path::new(&line[pos + prefix.len() ..])
                .with_extension("md");
            let _ = create_dir_all(path.parent().unwrap());
            current = File::create(path).unwrap();
            in_list = false;
        } else {
            if line.starts_with(&list_starts[..]) {
                in_list = true;
            } else if in_list {
                in_list = false;
                // insert an extra newline after the end of list
                writeln!(current).unwrap();
            }
            writeln!(current, "{}", line).unwrap();
        }
    }
}
Clone this wiki locally