wrote some more pages of the mkbook book

This commit is contained in:
Kenton Hamaluik 2019-11-28 00:28:48 -07:00
parent 6672eecfe9
commit 2aedd7aa8a
13 changed files with 224 additions and 16 deletions

View File

@ -1,7 +1,7 @@
# mkbook
**mkbook** is my simpler alternative to [mdbook](https://crates.io/crates/mdbook) which is a great tool, but for which I really dislike some of the decisions they took, such as relying on javascript, etc.
**mkbook** is my simpler alternative to [mdbook](https://crates.io/crates/mdbook) which is a great tool, but for which I really dislike some of the decisions they took, such as relying on javascript for highlighting and navigation, and including a lot of bells and whistles such as javascript-based search.
This tool aims to work somewhat similarly to _mkbook_, but is generally intended to be a more minimal alternative that is customized more towards my needs and desires than anything else.
This tool aims to work somewhat similarly to _mdbook_, but is generally intended to be a more minimal alternative that is customized more towards my needs and desires than anything else.
Still very WIP, but it can convert `.md` files into fancy-looking `.html` files, demo it by building the `mkbook` book by running: `cargo run -- build -i docs-src -o docs` and then serving the `docs` directory. Alternatively, view these generated docs [here](https://hamaluik.github.io/mkbook/01-introduction.html).

View File

@ -2,3 +2,50 @@
title = "Introduction"
---
_mkbook_ is my simpler alternative to [_mdbook_](https://crates.io/crates/mdbook) which is a great tool, but for which I really dislike some of the decisions they took, such as relying on javascript for highlighting and navigation, and including a lot of bells and whistles such as javascript-based search.
This tool aims to work somewhat similarly to _mdbook_, but is generally intended to be a more minimal alternative that is customized more towards my needs and desires than anything else.
_mkbook_ may be installed using _Cargo_ (`cargo install --force --path .` in the _mkbook_ repo directory), and after that it presents a command-line interface:
```
$ mkbook
mkbook 0.1.0
Kenton Hamaluik <kenton@hamaluik.ca>
USAGE:
mkbook [SUBCOMMAND]
FLAGS:
-h, --help
Prints help information
-V, --version
Prints version information
SUBCOMMANDS:
build build the book
help Prints this message or the help of the given subcommand(s)
init initialize a mkbook directory tree
```
Currently, only the `build` subcommand does anything (it builds your book!), but this functionality is still WIP:
```
$ mkbook build --help
mkbook-build
build the book
USAGE:
mkbook build [OPTIONS]
FLAGS:
-h, --help Prints help information
-V, --version Prints version information
OPTIONS:
-i, --in <in> an optional directory to take the book sources from [default: src]
-o, --out <out> an optional directory to render the contents into [default: book]
```

View File

@ -2,3 +2,45 @@
title = "Markdown"
---
_mkbook_ nominally utilizes [CommonMark](https://commonmark.org/) with some [GFM](https://github.github.com/gfm/) extensions through the use of the [comrak](https://crates.io/crates/comrak) crate. In using _comrak_, a specific set of options are used, which are listed here:
```rust
let options: ComrakOptions = ComrakOptions {
hardbreaks: false,
smart: true,
github_pre_lang: false,
default_info_string: None,
unsafe_: true,
ext_strikethrough: true,
ext_tagfilter: false,
ext_table: true,
ext_autolink: true,
ext_tasklist: true,
ext_superscript: true,
ext_header_ids: Some("header".to_owned()),
ext_footnotes: true,
ext_description_lists: true,
..ComrakOptions::default()
};
```
Mostly, know that the following extensions are enabled:
* [Strikethrough](https://github.github.com/gfm/#strikethrough-extension-)
* [Tables](https://github.github.com/gfm/#tables-extension-)
* [Autolinks](https://github.github.com/gfm/#autolinks-extension-)
* [Task Lists](https://github.github.com/gfm/#task-list-items-extension-)
* Superscripts (`e = mc^2^.` → `e = mc<sup>2</sup>.`)
* [Footnotes](https://kramdown.gettalong.org/syntax.html#footnotes)
* Description Lists:
```md
First term
: Details for the **first term**
Second term
: Details for the **second term**
More details in second paragraph.
```

View File

@ -2,8 +2,6 @@
title = "Front Matter"
---
# Front Matter
Each `.md` file can optionally contain a header with metadata describing the document. If the header isn't present, default values will be used which may look ugly.
To insert a header into a `.md` file, insert three dashes (`---`), followed by a new-line, followed by the front matter contents, followed by a newline, then another three dashes and a new-line. The metadata is in the [TOML](https://github.com/toml-lang/toml) format, so for example the front-matter (and first line) for this file looks like:
@ -13,8 +11,6 @@ To insert a header into a `.md` file, insert three dashes (`---`), followed by a
title = "Front Matter"
---
# Front Matter
Each `.md` file can optionally contain a header with metadata describing the document. If the header isn't present, default values will be used which may look ugly.
```

View File

@ -2,3 +2,24 @@
title = "Structure"
---
_mkbook_ currently only supports two types of assets to use in rendering: assets (images, etc), and documents (markdown files).
## Assets
```rust
unimplemented!()
```
## Documents
For now, _mkbook_ only works on a flat list of markdown files, with the intent of each markdown file being its own chapter. Subdirectories and files that don't end in a `.md` extension are completely ignored. The order of the book is based on the alphabetical order of the file names (actually it's based on Rust's [implementation of `PartialOrd` for str](https://doc.rust-lang.org/std/cmp/trait.PartialOrd.html#impl-PartialOrd%3Cstr%3E)). Thus, it is recommended to lay out your book chapters with manual numbering of the file names, as such:
```
src/
├── 00-foreword.md
├── 01-introduction.md
├── 02-my-first-chapter.md
└── etc...
```
An index and navigation will be automatically generated from these files, taking the information for each file from it's front-matter.

View File

@ -36,6 +36,48 @@
</a>
</nav>
<article></article>
<article><p><em>mkbook</em> is my simpler alternative to <a href="https://crates.io/crates/mdbook"><em>mdbook</em></a> which is a great tool, but for which I really dislike some of the decisions they took, such as relying on javascript for highlighting and navigation, and including a lot of bells and whistles such as javascript-based search.</p>
<p>This tool aims to work somewhat similarly to <em>mdbook</em>, but is generally intended to be a more minimal alternative that is customized more towards my needs and desires than anything else.</p>
<p><em>mkbook</em> may be installed using <em>Cargo</em> (<code>cargo install --force --path .</code> in the <em>mkbook</em> repo directory), and after that it presents a command-line interface:</p>
<pre style="background-color:#2d2d2d;">
<span style="color:#d3d0c8;">$ mkbook
</span><span style="color:#d3d0c8;">mkbook 0.1.0
</span><span style="color:#d3d0c8;">Kenton Hamaluik &lt;kenton@hamaluik.ca&gt;
</span><span style="color:#d3d0c8;">
</span><span style="color:#d3d0c8;">
</span><span style="color:#d3d0c8;">USAGE:
</span><span style="color:#d3d0c8;"> mkbook [SUBCOMMAND]
</span><span style="color:#d3d0c8;">
</span><span style="color:#d3d0c8;">FLAGS:
</span><span style="color:#d3d0c8;"> -h, --help
</span><span style="color:#d3d0c8;"> Prints help information
</span><span style="color:#d3d0c8;">
</span><span style="color:#d3d0c8;"> -V, --version
</span><span style="color:#d3d0c8;"> Prints version information
</span><span style="color:#d3d0c8;">
</span><span style="color:#d3d0c8;">
</span><span style="color:#d3d0c8;">SUBCOMMANDS:
</span><span style="color:#d3d0c8;"> build build the book
</span><span style="color:#d3d0c8;"> help Prints this message or the help of the given subcommand(s)
</span><span style="color:#d3d0c8;"> init initialize a mkbook directory tree
</span></pre>
<p>Currently, only the <code>build</code> subcommand does anything (it builds your book!), but this functionality is still WIP:</p>
<pre style="background-color:#2d2d2d;">
<span style="color:#d3d0c8;">$ mkbook build --help
</span><span style="color:#d3d0c8;">mkbook-build
</span><span style="color:#d3d0c8;">build the book
</span><span style="color:#d3d0c8;">
</span><span style="color:#d3d0c8;">USAGE:
</span><span style="color:#d3d0c8;"> mkbook build [OPTIONS]
</span><span style="color:#d3d0c8;">
</span><span style="color:#d3d0c8;">FLAGS:
</span><span style="color:#d3d0c8;"> -h, --help Prints help information
</span><span style="color:#d3d0c8;"> -V, --version Prints version information
</span><span style="color:#d3d0c8;">
</span><span style="color:#d3d0c8;">OPTIONS:
</span><span style="color:#d3d0c8;"> -i, --in &lt;in&gt; an optional directory to take the book sources from [default: src]
</span><span style="color:#d3d0c8;"> -o, --out &lt;out&gt; an optional directory to render the contents into [default: book]
</span></pre>
</article>
</body>
</html>

View File

@ -42,6 +42,48 @@
</a>
</nav>
<article></article>
<article><p><em>mkbook</em> nominally utilizes <a href="https://commonmark.org/">CommonMark</a> with some <a href="https://github.github.com/gfm/">GFM</a> extensions through the use of the <a href="https://crates.io/crates/comrak">comrak</a> crate. In using <em>comrak</em>, a specific set of options are used, which are listed here:</p>
<pre style="background-color:#2d2d2d;">
<span style="color:#cc99cc;">let</span><span style="color:#d3d0c8;"> options: ComrakOptions = ComrakOptions {
</span><span style="color:#d3d0c8;"> hardbreaks: </span><span style="color:#f99157;">false</span><span style="color:#d3d0c8;">,
</span><span style="color:#d3d0c8;"> smart: </span><span style="color:#f99157;">true</span><span style="color:#d3d0c8;">,
</span><span style="color:#d3d0c8;"> github_pre_lang: </span><span style="color:#f99157;">false</span><span style="color:#d3d0c8;">,
</span><span style="color:#d3d0c8;"> default_info_string: None,
</span><span style="color:#d3d0c8;"> unsafe_: </span><span style="color:#f99157;">true</span><span style="color:#d3d0c8;">,
</span><span style="color:#d3d0c8;"> ext_strikethrough: </span><span style="color:#f99157;">true</span><span style="color:#d3d0c8;">,
</span><span style="color:#d3d0c8;"> ext_tagfilter: </span><span style="color:#f99157;">false</span><span style="color:#d3d0c8;">,
</span><span style="color:#d3d0c8;"> ext_table: </span><span style="color:#f99157;">true</span><span style="color:#d3d0c8;">,
</span><span style="color:#d3d0c8;"> ext_autolink: </span><span style="color:#f99157;">true</span><span style="color:#d3d0c8;">,
</span><span style="color:#d3d0c8;"> ext_tasklist: </span><span style="color:#f99157;">true</span><span style="color:#d3d0c8;">,
</span><span style="color:#d3d0c8;"> ext_superscript: </span><span style="color:#f99157;">true</span><span style="color:#d3d0c8;">,
</span><span style="color:#d3d0c8;"> ext_header_ids: Some(&quot;</span><span style="color:#99cc99;">header</span><span style="color:#d3d0c8;">&quot;.</span><span style="color:#66cccc;">to_owned</span><span style="color:#d3d0c8;">()),
</span><span style="color:#d3d0c8;"> ext_footnotes: </span><span style="color:#f99157;">true</span><span style="color:#d3d0c8;">,
</span><span style="color:#d3d0c8;"> ext_description_lists: </span><span style="color:#f99157;">true</span><span style="color:#d3d0c8;">,
</span><span style="color:#d3d0c8;"> ..ComrakOptions::default()
</span><span style="color:#d3d0c8;">};
</span></pre>
<p>Mostly, know that the following extensions are enabled:</p>
<ul>
<li><a href="https://github.github.com/gfm/#strikethrough-extension-">Strikethrough</a></li>
<li><a href="https://github.github.com/gfm/#tables-extension-">Tables</a></li>
<li><a href="https://github.github.com/gfm/#autolinks-extension-">Autolinks</a></li>
<li><a href="https://github.github.com/gfm/#task-list-items-extension-">Task Lists</a></li>
<li>Superscripts (<code>e = mc^2^.</code><code>e = mc&lt;sup&gt;2&lt;/sup&gt;.</code>)</li>
<li><a href="https://kramdown.gettalong.org/syntax.html#footnotes">Footnotes</a></li>
<li>Description Lists:
<pre style="background-color:#2d2d2d;">
<span style="color:#d3d0c8;">First term
</span><span style="color:#d3d0c8;">
</span><span style="color:#d3d0c8;">: Details for the </span><span style="font-weight:bold;color:#ffcc66;">**first term**
</span><span style="color:#d3d0c8;">
</span><span style="color:#d3d0c8;">Second term
</span><span style="color:#d3d0c8;">
</span><span style="color:#d3d0c8;">: Details for the </span><span style="font-weight:bold;color:#ffcc66;">**second term**
</span><span style="color:#d3d0c8;">
</span><span style="color:#d3d0c8;"> More details in second paragraph.
</span></pre>
</li>
</ul>
</article>
</body>
</html>

View File

@ -42,16 +42,13 @@
</a>
</nav>
<article><h1><a href="#front-matter" aria-hidden="true" class="anchor" id="headerfront-matter"></a>Front Matter</h1>
<p>Each <code>.md</code> file can optionally contain a header with metadata describing the document. If the header isnt present, default values will be used which may look ugly.</p>
<article><p>Each <code>.md</code> file can optionally contain a header with metadata describing the document. If the header isnt present, default values will be used which may look ugly.</p>
<p>To insert a header into a <code>.md</code> file, insert three dashes (<code>---</code>), followed by a new-line, followed by the front matter contents, followed by a newline, then another three dashes and a new-line. The metadata is in the <a href="https://github.com/toml-lang/toml">TOML</a> format, so for example the front-matter (and first line) for this file looks like:</p>
<pre style="background-color:#2d2d2d;">
<span style="background-color:#515151;color:#d3d0c8;">---
</span><span style="color:#d3d0c8;">title = &quot;Front Matter&quot;
</span><span style="color:#6699cc;">---
</span><span style="color:#d3d0c8;">
</span><span style="color:#6699cc;"># Front Matter
</span><span style="color:#d3d0c8;">
</span><span style="color:#d3d0c8;">Each </span><span style="color:#99cc99;">`.md`</span><span style="color:#d3d0c8;"> file can optionally contain a header with metadata describing the document. If the header isn&#39;t present, default values will be used which may look ugly.
</span></pre>
<h2><a href="#supported-keys" aria-hidden="true" class="anchor" id="headersupported-keys"></a>Supported Keys</h2>

View File

@ -36,6 +36,21 @@
<span class="placeholder"></span>
</nav>
<article></article>
<article><p><em>mkbook</em> currently only supports two types of assets to use in rendering: assets (images, etc), and documents (markdown files).</p>
<h2><a href="#assets" aria-hidden="true" class="anchor" id="headerassets"></a>Assets</h2>
<pre style="background-color:#2d2d2d;">
<span style="color:#d3d0c8;">unimplemented!()
</span></pre>
<h2><a href="#documents" aria-hidden="true" class="anchor" id="headerdocuments"></a>Documents</h2>
<p>For now, <em>mkbook</em> only works on a flat list of markdown files, with the intent of each markdown file being its own chapter. Subdirectories and files that dont end in a <code>.md</code> extension are completely ignored. The order of the book is based on the alphabetical order of the file names (actually its based on Rusts <a href="https://doc.rust-lang.org/std/cmp/trait.PartialOrd.html#impl-PartialOrd%3Cstr%3E">implementation of <code>PartialOrd</code> for str</a>). Thus, it is recommended to lay out your book chapters with manual numbering of the file names, as such:</p>
<pre style="background-color:#2d2d2d;">
<span style="color:#d3d0c8;">src/
</span><span style="color:#d3d0c8;">├── 00-foreword.md
</span><span style="color:#d3d0c8;">├── 01-introduction.md
</span><span style="color:#d3d0c8;">├── 02-my-first-chapter.md
</span><span style="color:#d3d0c8;">└── etc...
</span></pre>
<p>An index and navigation will be automatically generated from these files, taking the information for each file from its front-matter.</p>
</article>
</body>
</html>

View File

@ -1 +1 @@
@import url("https://fonts.googleapis.com/css?family=Crimson+Pro|Poppins:700|Source+Code+Pro&display=swap");body{margin:0;line-height:1.5;font-size:14pt;color:#222222;background:#eeeeee;padding:0;font-family:"Crimson Pro","Georgia",Georgia,"Times New Roman",Times,serif}h1,h2,h3{margin-top:0;line-height:1.2;font-family:"Poppins","Franklin Gothic Medium","Arial Narrow",Arial,sans-serif}a{color:#222222;text-decoration:underline}a:hover{color:#8a2888;text-decoration:none}figure{display:block;text-align:center;overflow-x:auto}figure img,figure video{max-width:100%}figure figcaption{display:block;font-size:0.75em;text-align:center}code{margin:0 2px;padding:0 2px;border:1px solid #4c566a;border-radius:3px;word-break:break-all;font-family:"Source Code Pro","Courier New",Courier,monospace;font-size:0.75em}pre{overflow-x:auto;font-family:"Source Code Pro","Courier New",Courier,monospace;padding:0}dl{display:grid;grid-template-columns:auto 1fr}dl dt{font-weight:700;margin:0;padding:0.5em;border-right:1px solid #dddddd}dl dd{margin:0;padding:0.5em}dl dt p,dl dd p{margin:0}html,body{width:100%;min-height:100vh}body{display:grid;grid-template-columns:auto 1fr;grid-template-rows:1fr;justify-items:stretch;align-items:stretch}body nav.big{background:#2c2c38;padding:1em;display:flex;flex-direction:column}body nav.big a{width:100%;font-size:1.5em;text-decoration:none;font-family:"Poppins","Franklin Gothic Medium","Arial Narrow",Arial,sans-serif;margin:0 0 0.25em 0;color:#5babd1}body nav.big a:hover{color:#cf5ccd}body nav.big a.current{color:#cf5ccd}body nav.big a.current:hover{color:#fefefe}body nav.small{display:none;width:100%;align-items:center;justify-content:space-between;background:#2c2c38;padding:0}body nav.small>*{margin:0.5em}body nav.small a{text-decoration:none;font-family:"Poppins","Franklin Gothic Medium","Arial Narrow",Arial,sans-serif;color:#5babd1}body nav.small a:hover{color:#cf5ccd}body nav.small span.title{text-decoration:none;font-family:"Poppins","Franklin Gothic Medium","Arial Narrow",Arial,sans-serif;color:#fefefe}body nav.small span.placeholder{width:1em;height:1em}body article{padding:1em 2em 0 2em;max-width:38em;min-width:0;min-height:0}body article>*{max-width:100%}@media screen and (max-width: 768px){body{grid-template-columns:1fr;grid-template-rows:auto 1fr}body nav.big{display:none}body nav.small{display:flex}body article{padding:1em 0.5em 0 0.5em}}span.icon{display:flex;align-items:center}[class^="icon-"],[class*=" icon-"]{display:inline-block;width:1em;height:1em;stroke-width:0;stroke:currentColor;fill:currentColor}.icon-arrow-left{width:0.875em}.icon-arrow-right{width:0.875em}@media (prefers-color-scheme: dark){body{background-color:#222222;color:#eeeeee}a{color:#eeeeee}a:hover{color:#5babd1}nav{background:#18181d}img{filter:grayscale(30%)}}@media print{body{background:#ffffff;color:#000000}a{color:#000000;text-decoration:underline}h2,h3{break-after:avoid-page}figure{break-inside:avoid}p{orphans:2;widows:2}*{overflow:hidden}nav{display:none}body{display:block}}
@import url("https://fonts.googleapis.com/css?family=Crimson+Pro|Poppins:700|Source+Code+Pro&display=swap");body{margin:0;line-height:1.5;font-size:14pt;color:#222222;background:#eeeeee;padding:0;font-family:"Crimson Pro","Georgia",Georgia,"Times New Roman",Times,serif}h1,h2,h3{margin-top:0;line-height:1.2;font-family:"Poppins","Franklin Gothic Medium","Arial Narrow",Arial,sans-serif}a{color:#222222;text-decoration:underline}a:hover{color:#8a2888;text-decoration:none}figure{display:block;text-align:center;overflow-x:auto}figure img,figure video{max-width:100%}figure figcaption{display:block;font-size:0.75em;text-align:center}code{margin:0 2px;padding:0 2px;border:1px solid #4c566a;border-radius:3px;word-break:break-all;font-family:"Source Code Pro","Courier New",Courier,monospace;font-size:0.75em}pre{overflow-x:auto;font-family:"Source Code Pro","Courier New",Courier,monospace;padding:0.5em}dl{display:grid;grid-template-columns:auto 1fr}dl dt{font-weight:700;margin:0;padding:0.5em;border-right:1px solid #dddddd}dl dd{margin:0;padding:0.5em}dl dt p,dl dd p{margin:0}html,body{width:100%;min-height:100vh}body{display:grid;grid-template-columns:auto 1fr;grid-template-rows:1fr;justify-items:stretch;align-items:stretch}body nav.big{background:#2c2c38;padding:1em;display:flex;flex-direction:column}body nav.big a{width:100%;font-size:1.5em;text-decoration:none;font-family:"Poppins","Franklin Gothic Medium","Arial Narrow",Arial,sans-serif;margin:0 0 0.25em 0;color:#5babd1}body nav.big a:hover{color:#cf5ccd}body nav.big a.current{color:#cf5ccd}body nav.big a.current:hover{color:#fefefe}body nav.small{display:none;width:100%;align-items:center;justify-content:space-between;background:#2c2c38;padding:0}body nav.small>*{margin:0.5em}body nav.small a{text-decoration:none;font-family:"Poppins","Franklin Gothic Medium","Arial Narrow",Arial,sans-serif;color:#5babd1}body nav.small a:hover{color:#cf5ccd}body nav.small span.title{text-decoration:none;font-family:"Poppins","Franklin Gothic Medium","Arial Narrow",Arial,sans-serif;color:#fefefe}body nav.small span.placeholder{width:1em;height:1em}body article{padding:1em 2em 0 2em;max-width:38em;min-width:0;min-height:0}body article>*{max-width:100%}@media screen and (max-width: 768px){body{grid-template-columns:1fr;grid-template-rows:auto 1fr}body nav.big{display:none}body nav.small{display:flex}body article{padding:1em 0.5em 0 0.5em}}span.icon{display:flex;align-items:center}[class^="icon-"],[class*=" icon-"]{display:inline-block;width:1em;height:1em;stroke-width:0;stroke:currentColor;fill:currentColor}.icon-arrow-left{width:0.875em}.icon-arrow-right{width:0.875em}@media (prefers-color-scheme: dark){body{background-color:#222222;color:#eeeeee}a{color:#eeeeee}a:hover{color:#5babd1}nav{background:#18181d}img{filter:grayscale(30%)}dl dt{border-right:1px solid #333333}}@media print{body{background:#ffffff;color:#000000}a{color:#000000;text-decoration:underline}h2,h3{break-after:avoid-page}figure{break-inside:avoid}p{orphans:2;widows:2}*{overflow:hidden}nav{display:none}body{display:block}}

View File

@ -73,7 +73,7 @@ fn format_markdown(src: &str) -> Result<String, Box<dyn std::error::Error>> {
let options: ComrakOptions = ComrakOptions {
hardbreaks: false,
smart: true,
github_pre_lang: true,
github_pre_lang: false,
default_info_string: None,
unsafe_: true,
ext_strikethrough: true,

View File

@ -56,7 +56,7 @@ code {
pre {
overflow-x: auto;
font-family: $font-mono;
padding: 0;
padding: 0.5em;
}
dl {

View File

@ -19,4 +19,10 @@
img {
filter: grayscale(30%);
}
dl {
dt {
border-right: 1px solid #333333;
}
}
}