DEV Community

Cover image for Meta Programming
Antonio-Bennett
Antonio-Bennett

Posted on • Updated on

Meta Programming

Hey Again! It's been a while since my last blog :)

As usual the previous related blog is right here

Task 1

For this assignment we had to familiarize ourselves with Docusaurus which is created by Facebo- *Cough* Meta. The basic setup can be found here via github pages. It was super easy to setup! I did have a hiccup with github not doing password auth anymore when I tried running the built in deploy script for github pages and the fix was too annoying so I just built and copied the files to my github pages repo.

Task 2

The second task was to also implement a feature of docusaurus. I chose to implement the markdown parsing feature. Although rssg technically had this feature, it was very limited. Only supporting level 1 headers and inline code. To do this we were allowed to use 3rd party libraries, specifically crates in rust.

I chose to use comrak. It is one of the most developed and well known markdown to html crates and is very easy to use. The main logic of my code is very simple and is done as such

    if ext == "md" {
        let file: Vec<&str> = vec_lines.into_iter().skip(3).collect();
        let file = file.join("\n");
        let file = markdown_to_html(&file, &ComrakOptions::default());
        html.write_all(file.as_bytes())
            .expect("Could not write markdown");
        return;
    }
Enter fullscreen mode Exit fullscreen mode

It simply takes each applicable line of the file and converts it to html. That simple. The full commit can be found here

Thanks for reading again and I hope I'm not boring you guys to death yet! :)

Top comments (0)