From 9ac1373fe2c6f585af60b3552e3c6aead63dacb2 Mon Sep 17 00:00:00 2001 From: sgoudham Date: Sat, 30 Apr 2022 03:37:23 +0100 Subject: [PATCH] [v0.1.0] - Add ##Format & ##Example sections --- README.md | 102 +++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 93 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 6c942f8..fccdd35 100644 --- a/README.md +++ b/README.md @@ -13,8 +13,8 @@ TODO ## Author Notes -I'm still a beginner in terms of my Rust skills so I'm _definitely... probably_ sure that there are edge cases within -this preprocessor, and I'm sure that the code could be extra performant. +I'm still a beginner in terms of my Rust skills, so I'm _definitely... probably_ sure that there are edge cases within +this preprocessor. ## Installation @@ -30,7 +30,7 @@ $ cargo install mdbook-template [preprocessor.template] ``` -**You're good to go! Continue building your mdbook normally!** +**You're good to go :D Continue building your mdbook normally!** ```shell $ mdbook build @@ -38,9 +38,6 @@ $ mdbook build ## About -Being based on the `{{#include ... }}` feature of mdbook, mdbook-template allows you to use familiar syntax to include -files while passing in arguments to allow for dynamic generation of text. - Given the following directory structure ```text @@ -61,11 +58,29 @@ the same piece of markdown/code in every file and set a unique path back to the This is where `mdbook-template` can help. -Through the addition of a `footer.md`, you can define a common template that every page will be able to reference with a -relative path back to the images to ensure they are properly displayed. +Being based on the `{{#include ... }}` feature of mdbook, mdbook-template allows you to use familiar syntax to include +files while passing in arguments to allow for dynamic generation of text. + +## Format + +The format is as follows + +```text + 1 2 3 + {{#template }} +``` + +1. The identifier that this text should be replaced +2. The `relative path` to the template file +3. Any arguments that should be substituted within the template file. Arguments should be seperated by whitespace and + should be in the `key=value` format. + +Arguments to be replaced within the template files should be wrapped in `{}` ## Example +Given the following directory + ```text book.toml src @@ -81,7 +96,76 @@ src └── SUMMARY.md ``` -TODO +and the following content + +`templates/footer.md` + +```markdown +- - - - +Designed By Goudham +![ferris]({path}/ferris.png) +![ferris]({path}/corro.png) +``` + +`one.md` +```markdown +# One +Some Content... + +{{#template templates/footer.md path=images}} +``` + +`two.md` +```markdown +# Two +Some Content... + +{{#template templates/footer.md path=images}} +``` + +`two/three.md` +```markdown +# Three +Some Content... + +{{#template templates/footer.md path=../images}} +``` + +After running `mdbook build` with the mdbook-template preprocessor enabled, the files will have dynamic paths to the +images + +`one.md` +```markdown +# One +Some Content... + +- - - - +Designed By Goudham +![ferris](images/ferris.png) +![ferris](images/corro.png) +``` + +`two.md` +```markdown +# Two +Some Content... + +- - - - +Designed By Goudham +![ferris](images/ferris.png) +![ferris](images/corro.png) +``` + +`two/three.md` +```markdown +# Three +Some Content... + +- - - - +Designed By Goudham +![ferris](../images/ferris.png) +![ferris](../images/corro.png) +``` Further examples are included within the [](/examples) section which demonstrate a variety of usages.