From d858a51a34abb325e1d925309d2a315b0f023349 Mon Sep 17 00:00:00 2001 From: Kenton Hamaluik Date: Tue, 3 Dec 2019 10:47:25 -0700 Subject: [PATCH] fixed img figure wrapping --- Cargo.lock | 60 ++++++++ Cargo.toml | 1 + docs-src/02-markdown/05-images.md | 19 +++ docs/01-introduction/index.html | 4 +- docs/02-markdown/01-commonmark.html | 7 +- docs/02-markdown/02-syntax-highlighting.html | 4 +- docs/02-markdown/03-plantuml-diagrams.html | 4 +- docs/02-markdown/04-katex-formulas.html | 10 +- docs/02-markdown/05-images.html | 137 +++++++++++++++++++ docs/02-markdown/index.html | 4 +- docs/03-frontmatter/index.html | 6 +- docs/04-structure/index.html | 4 +- docs/05-customization/index.html | 4 +- docs/06-how-it-works/index.html | 4 +- docs/index.html | 6 +- docs/style.css | 2 +- src/main.rs | 64 ++++++--- style/base.scss | 12 +- 18 files changed, 310 insertions(+), 42 deletions(-) create mode 100644 docs-src/02-markdown/05-images.md create mode 100644 docs/02-markdown/05-images.html diff --git a/Cargo.lock b/Cargo.lock index 15c3e87..845e356 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -159,6 +159,14 @@ dependencies = [ "byte-tools 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "bstr" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "memchr 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "byte-tools" version = "0.3.1" @@ -272,6 +280,23 @@ dependencies = [ "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "crossbeam-channel" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "crossbeam-utils 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "crossbeam-utils" +version = "0.6.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "digest" version = "0.8.1" @@ -409,6 +434,18 @@ name = "glob" version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "globset" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "aho-corasick 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)", + "bstr 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", + "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", + "regex 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "hermit-abi" version = "0.1.3" @@ -445,6 +482,23 @@ dependencies = [ "unicode-normalization 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "ignore" +version = "0.4.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "crossbeam-channel 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", + "globset 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", + "memchr 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "regex 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "same-file 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", + "thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "walkdir 2.2.9 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi-util 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "inotify" version = "0.6.1" @@ -603,6 +657,7 @@ dependencies = [ "clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)", "comrak 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", "fern 0.5.9 (registry+https://github.com/rust-lang/crates.io-index)", + "ignore 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "notify 4.0.14 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1274,6 +1329,7 @@ dependencies = [ "checksum bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" "checksum block-buffer 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c0940dc441f31689269e10ac70eb1002a3a1d3ad1390e030043662eb7fe4688b" "checksum block-padding 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "fa79dedbb091f449f1f39e53edf88d5dbe95f895dae6135a8d7b881fb5af73f5" +"checksum bstr 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "8d6c2c5b58ab920a4f5aeaaca34b4488074e8cc7596af94e6f8c6ff247c60245" "checksum byte-tools 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e3b5ca7a04898ad4bcd41c90c5285445ff5b791899bb1b0abdd2a2aa791211d7" "checksum byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a7c3dd8985a7111efc5c80b44e23ecdd8c007de8ade3b96595387e812b957cf5" "checksum bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)" = "206fdffcfa2df7cbe15601ef46c813fce0965eb3286db6b56c583b814b51c81c" @@ -1287,6 +1343,8 @@ dependencies = [ "checksum colored 1.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "433e7ac7d511768127ed85b0c4947f47a254131e37864b2dc13f52aa32cd37e5" "checksum comrak 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "ea4c29f52463abf5c7a3ae33dd9b404e2031af82f547cfe65bfac17ba785ea2e" "checksum crc32fast 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ba125de2af0df55319f41944744ad91c71113bf74a4646efff39afe1f6842db1" +"checksum crossbeam-channel 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "c8ec7fcd21571dc78f96cc96243cab8d8f035247c3efd16c687be154c3fa9efa" +"checksum crossbeam-utils 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)" = "04973fa96e96579258a5091af6003abde64af786b860f18622b82e026cca60e6" "checksum digest 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f3d0c8c8752312f9713efd397ff63acb9f85585afbf179282e720e7704954dd5" "checksum entities 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b5320ae4c3782150d900b79807611a59a99fc9a1d61d686faafc24b93fc8d7ca" "checksum env_logger 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "aafcde04e90a5226a6443b7aabdb016ba2f8307c847d524724bd9b346dd1a2d3" @@ -1304,11 +1362,13 @@ dependencies = [ "checksum generic-array 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c68f0274ae0e023facc3c97b2e00f076be70e254bc851d972503b328db79b2ec" "checksum getrandom 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "e7db7ca94ed4cd01190ceee0d8a8052f08a247aa1b469a7f68c6a3b71afcf407" "checksum glob 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" +"checksum globset 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "925aa2cac82d8834e2b2a4415b6f6879757fb5c0928fc445ae76461a12eed8f2" "checksum hermit-abi 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "307c3c9f937f38e3534b1d6447ecf090cafcc9744e4a6360e8b037b2cf5af120" "checksum httparse 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "cd179ae861f0c2e53da70d892f5f3029f9594be0c41dc5269cd371691b1dc2f9" "checksum humansize 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b6cab2627acfc432780848602f3f558f7e9dd427352224b0d9324025796d2a5e" "checksum humantime 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "df004cfca50ef23c36850aaaa59ad52cc70d0e90243c3c7737a4dd32dc7a3c4f" "checksum idna 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "02e2673c30ee86b5b96a9cb52ad15718aa1f966f5ab9ad54a8b95d5ca33120a9" +"checksum ignore 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)" = "0ec16832258409d571aaef8273f3c3cc5b060d784e159d1a0f3b0017308f84a7" "checksum inotify 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "40b54539f3910d6f84fbf9a643efd6e3aa6e4f001426c0329576128255994718" "checksum inotify-sys 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "e74a1aa87c59aeff6ef2cc2fa62d41bc43f54952f55652656b18a02fd5e356c0" "checksum iovec 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "b2b3ea6ff95e175473f8ffe6a7eb7c00d054240321b84c57051175fe3c1e075e" diff --git a/Cargo.toml b/Cargo.toml index c56989a..38c50e6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,6 +32,7 @@ notify = "4.0" ws = "0.9" fern = { version = "0.5", features = ["colored"] } log = { version = "0.4", features = ["max_level_debug", "release_max_level_info", "std", "serde"] } +ignore = "0.4" [build-dependencies] sass-rs = "0.2" diff --git a/docs-src/02-markdown/05-images.md b/docs-src/02-markdown/05-images.md new file mode 100644 index 0000000..bc798d6 --- /dev/null +++ b/docs-src/02-markdown/05-images.md @@ -0,0 +1,19 @@ +--- +title = "Images" +--- + +To include an image, use the standard markdown format: + +```md +![title](url) +``` + +This will wrap the image in a `figure` with an associated `figcaption` containing the title of the image, as so: + +```md +![a bear](https://placebear.com/g/512/256 "A majestic bear") +``` + +will render as: + +![a bear](https://placebear.com/g/512/256 "A majestic bear") diff --git a/docs/01-introduction/index.html b/docs/01-introduction/index.html index a7aee1d..b08db20 100644 --- a/docs/01-introduction/index.html +++ b/docs/01-introduction/index.html @@ -12,7 +12,7 @@ - + @@ -41,6 +41,8 @@
  • KaTeX (Math) Formulas
  • +
  • Images
  • + diff --git a/docs/02-markdown/01-commonmark.html b/docs/02-markdown/01-commonmark.html index 46c53a7..028761c 100644 --- a/docs/02-markdown/01-commonmark.html +++ b/docs/02-markdown/01-commonmark.html @@ -12,7 +12,7 @@ - + @@ -41,6 +41,8 @@
  • KaTeX (Math) Formulas
  • +
  • Images
  • + @@ -134,8 +136,7 @@
  • Task Lists
  • Superscripts (e = mc^2^.e = mc<sup>2</sup>.)
  • Footnotes
  • -
  • Description Lists: -
    +
  • Description Lists:
     First term
     
     : Details for the **first term**
    diff --git a/docs/02-markdown/02-syntax-highlighting.html b/docs/02-markdown/02-syntax-highlighting.html
    index 2e34fdf..2f6ebdf 100644
    --- a/docs/02-markdown/02-syntax-highlighting.html
    +++ b/docs/02-markdown/02-syntax-highlighting.html
    @@ -12,7 +12,7 @@
             
             
             
    -        
    +        
             
         
         
    @@ -41,6 +41,8 @@
                             
                             
  • KaTeX (Math) Formulas
  • +
  • Images
  • +
  • diff --git a/docs/02-markdown/03-plantuml-diagrams.html b/docs/02-markdown/03-plantuml-diagrams.html index 1fee3d2..815c2b9 100644 --- a/docs/02-markdown/03-plantuml-diagrams.html +++ b/docs/02-markdown/03-plantuml-diagrams.html @@ -12,7 +12,7 @@ - + @@ -41,6 +41,8 @@
  • KaTeX (Math) Formulas
  • +
  • Images
  • +
  • diff --git a/docs/02-markdown/04-katex-formulas.html b/docs/02-markdown/04-katex-formulas.html index 0905232..49ac006 100644 --- a/docs/02-markdown/04-katex-formulas.html +++ b/docs/02-markdown/04-katex-formulas.html @@ -12,7 +12,7 @@ - + @@ -41,6 +41,8 @@
  • KaTeX (Math) Formulas
  • +
  • Images
  • + @@ -94,7 +96,7 @@ - + @@ -133,8 +135,8 @@ M834 80h400000v40h-400000z'/>
    - - Next chapter: “Front Matter” + + Next chapter: “Images” diff --git a/docs/02-markdown/05-images.html b/docs/02-markdown/05-images.html new file mode 100644 index 0000000..81b3aa5 --- /dev/null +++ b/docs/02-markdown/05-images.html @@ -0,0 +1,137 @@ + + + + + + The mkbook Book | Images + + + + + + + + + + + + + + +
    +

    To include an image, use the standard markdown format:

    +
    +![title](url)
    +
    +

    This will wrap the image in a figure with an associated figcaption containing the title of the image, as so:

    +
    +![a bear](https://placebear.com/g/512/256 "A majestic bear")
    +
    +

    will render as:

    +
    a bear
    A majestic bear
    + + + + +

    © 2019 Kenton Hamaluik

    +
    + + + \ No newline at end of file diff --git a/docs/02-markdown/index.html b/docs/02-markdown/index.html index 7196600..15676e6 100644 --- a/docs/02-markdown/index.html +++ b/docs/02-markdown/index.html @@ -12,7 +12,7 @@ - + @@ -41,6 +41,8 @@
  • KaTeX (Math) Formulas
  • +
  • Images
  • + diff --git a/docs/03-frontmatter/index.html b/docs/03-frontmatter/index.html index 95e3c44..aa3caa2 100644 --- a/docs/03-frontmatter/index.html +++ b/docs/03-frontmatter/index.html @@ -12,7 +12,7 @@ - + @@ -41,6 +41,8 @@
  • KaTeX (Math) Formulas
  • +
  • Images
  • + @@ -78,7 +80,7 @@ - + diff --git a/docs/04-structure/index.html b/docs/04-structure/index.html index ad38217..6820d6c 100644 --- a/docs/04-structure/index.html +++ b/docs/04-structure/index.html @@ -12,7 +12,7 @@ - + @@ -41,6 +41,8 @@
  • KaTeX (Math) Formulas
  • +
  • Images
  • + diff --git a/docs/05-customization/index.html b/docs/05-customization/index.html index 3da53ed..70f17dc 100644 --- a/docs/05-customization/index.html +++ b/docs/05-customization/index.html @@ -12,7 +12,7 @@ - + @@ -41,6 +41,8 @@
  • KaTeX (Math) Formulas
  • +
  • Images
  • + diff --git a/docs/06-how-it-works/index.html b/docs/06-how-it-works/index.html index 59df8d3..90a61ed 100644 --- a/docs/06-how-it-works/index.html +++ b/docs/06-how-it-works/index.html @@ -12,7 +12,7 @@ - + @@ -41,6 +41,8 @@
  • KaTeX (Math) Formulas
  • +
  • Images
  • + diff --git a/docs/index.html b/docs/index.html index a801989..f712539 100644 --- a/docs/index.html +++ b/docs/index.html @@ -14,14 +14,14 @@ <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> " /> - +

    The mkbook Book

    by Kenton Hamaluik

    - +

    mkbook is my simpler alternative to 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.

    @@ -50,6 +50,8 @@
  • KaTeX (Math) Formulas
  • +
  • Images
  • + diff --git a/docs/style.css b/docs/style.css index 4e770d6..c86e4a4 100644 --- a/docs/style.css +++ b/docs/style.css @@ -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 svg,figure video{max-width:100%}figure figcaption{display:block;font-size:0.75rem;text-align:center}code,kbd{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.75rem}kbd{color:#222222;background:#eeeeee;box-shadow:0px 2px 4px rgba(0,0,0,0.5)}pre{overflow-x:auto;font-family:"Source Code Pro","Courier New",Courier,monospace;padding:0.5rem}dl{display:grid;grid-template-columns:auto auto}dl dt{font-weight:700;margin:0;padding:0 0.5rem 0.25rem;border-right:1px solid #dddddd;text-align:right}dl dd{margin:0;padding:0 0.5rem 0.25rem}dl dt p,dl dd p{margin:0}p{margin-top:0}footer{color:#444444}footer p{margin-right:0.5rem}table{margin:0 auto;border-collapse:collapse;border-spacing:0.5rem}table th{border-bottom:1px solid #eee}table th,table td{vertical-align:top}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:0.5rem 1rem 1rem;max-width:15rem;display:flex;flex-direction:column}body nav.big header{margin:0 0 1rem;display:flex;flex-direction:column;align-items:stretch;border-bottom:2px solid #888888}body nav.big header h1{font-size:1.5rem;font-weight:700;font-family:"Poppins","Franklin Gothic Medium","Arial Narrow",Arial,sans-serif;margin-bottom:0;text-align:left;color:#eeeeee}body nav.big header h1 a{color:#eeeeee;text-decoration:none}body nav.big header h1 a:hover{color:#cf5ccd}body nav.big header h2{font-size:1rem;font-weight:600;font-family:"Poppins","Franklin Gothic Medium","Arial Narrow",Arial,sans-serif;margin-bottom:0;text-align:right;color:#eeeeee}body nav.big ol{margin:0 2rem;padding:0}body nav.big ol li{width:100%;font-size:1.25rem;font-family:"Poppins","Franklin Gothic Medium","Arial Narrow",Arial,sans-serif;color:#eeeeee}body nav.big ol li a{text-decoration:none;margin:0 0 0.25rem 0;color:#5babd1}body nav.big ol li a:hover{color:#cf5ccd}body nav.big ol li a.current{color:#cf5ccd}body nav.big ol li a.current:hover{color:#fefefe}body nav.big ol li ol{margin:0 0 0 1rem}body nav.small{display:none;width:100%;align-items:center;justify-content:space-between;background:#2c2c38;padding:0}body nav.small>*{margin:0.5rem}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{display:inline-flex;align-items:center}body nav.small span>*{margin-right:0.5rem}body nav.small span>*:last-child{margin-right:0}body nav.small span.title{text-decoration:none;font-family:"Poppins","Franklin Gothic Medium","Arial Narrow",Arial,sans-serif;color:#fefefe;justify-self:center}body nav.small span.placeholder{width:1em;height:1em}body>*{min-width:0;min-height:0}body article{max-width:38rem;padding:0.5rem 2rem 0 2rem}body article>*{max-width:100%}body .next-chapter{width:100%}body .next-chapter a{display:flex;align-items:center;justify-content:flex-end;margin-right:0.5rem;font-size:1.2rem;text-decoration:none;font-family:"Poppins","Franklin Gothic Medium","Arial Narrow",Arial,sans-serif;color:#5babd1}body .next-chapter a:hover{color:#cf5ccd}body .next-chapter a span:first-child{margin-right:0.5rem}body footer{width:100%;text-align:right;display:flex;flex-direction:column;align-items:flex-end;justify-content:flex-end}@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:1rem 0.5rem 0 0.5rem}}body.toc{display:flex;flex-direction:column;justify-content:flex-start;align-items:center}body.toc>*{width:36rem}body.toc header{margin-top:1rem;display:flex;flex-direction:column;align-items:center}body.toc header h1{font-size:3rem;font-weight:700;font-family:"Poppins","Franklin Gothic Medium","Arial Narrow",Arial,sans-serif;margin-bottom:0}body.toc header h2{font-size:1rem;font-weight:600;font-family:"Poppins","Franklin Gothic Medium","Arial Narrow",Arial,sans-serif;margin-bottom:0}body.toc header time{font-size:1rem;font-weight:400;font-family:"Crimson Pro","Georgia",Georgia,"Times New Roman",Times,serif}body.toc nav{background:none;display:flex;flex-direction:column;align-items:stretch}body.toc nav h1{text-align:left;font-size:2.5rem;font-weight:600;margin-bottom:0}body.toc nav ol li{font-size:1.5rem;font-family:"Poppins","Franklin Gothic Medium","Arial Narrow",Arial,sans-serif}body.toc nav ol li a{text-decoration:none;margin:0 0 0.25rem 0;color:#5babd1}body.toc nav ol li a:hover{color:#cf5ccd}body.toc nav>ol{margin-left:0.5rem;margin-right:0.5rem}body.toc article,body.toc nav{padding:0}body.toc article>*,body.toc nav>*{margin-left:0.5rem;margin-right:0.5rem}body.toc footer{flex:1}@media screen and (max-width: 768px){body.toc>*{width:100%}body.toc header h1,body.toc header h2,body.toc header time{text-align:center}body.toc nav h1{font-size:1.75rem}}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}.icon-arrow-up{width:0.875em}.icon-list-ol{width:1em}@media print{body{background:#ffffff;color:#000000}body:not(.toc) nav{display:none}a{color:#000000;text-decoration:underline}h2,h3{break-after:avoid-page}figure{break-inside:avoid}p{orphans:2;widows:2}*{overflow:hidden}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}img,svg,video{max-width:100%}figure{display:block;text-align:center;overflow-x:auto;margin:0 0 1em}figure figcaption{display:block;font-size:0.75rem;text-align:center}code,kbd{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.75rem}kbd{color:#222222;background:#eeeeee;box-shadow:0px 2px 4px rgba(0,0,0,0.5)}pre{overflow-x:auto;font-family:"Source Code Pro","Courier New",Courier,monospace;padding:0.5rem}dl{display:grid;grid-template-columns:auto auto}dl dt{font-weight:700;margin:0;padding:0 0.5rem 0.25rem;border-right:1px solid #dddddd;text-align:right}dl dd{margin:0;padding:0 0.5rem 0.25rem}dl dt p,dl dd p{margin:0}p{margin-top:0}footer{color:#444444}footer p{margin-right:0.5rem}table{margin:0 auto;border-collapse:collapse;border-spacing:0.5rem}table th{border-bottom:1px solid #eee}table th,table td{vertical-align:top}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:0.5rem 1rem 1rem;max-width:15rem;display:flex;flex-direction:column}body nav.big header{margin:0 0 1rem;display:flex;flex-direction:column;align-items:stretch;border-bottom:2px solid #888888}body nav.big header h1{font-size:1.5rem;font-weight:700;font-family:"Poppins","Franklin Gothic Medium","Arial Narrow",Arial,sans-serif;margin-bottom:0;text-align:left;color:#eeeeee}body nav.big header h1 a{color:#eeeeee;text-decoration:none}body nav.big header h1 a:hover{color:#cf5ccd}body nav.big header h2{font-size:1rem;font-weight:600;font-family:"Poppins","Franklin Gothic Medium","Arial Narrow",Arial,sans-serif;margin-bottom:0;text-align:right;color:#eeeeee}body nav.big ol{margin:0 2rem;padding:0}body nav.big ol li{width:100%;font-size:1.25rem;font-family:"Poppins","Franklin Gothic Medium","Arial Narrow",Arial,sans-serif;color:#eeeeee}body nav.big ol li a{text-decoration:none;margin:0 0 0.25rem 0;color:#5babd1}body nav.big ol li a:hover{color:#cf5ccd}body nav.big ol li a.current{color:#cf5ccd}body nav.big ol li a.current:hover{color:#fefefe}body nav.big ol li ol{margin:0 0 0 1rem}body nav.small{display:none;width:100%;align-items:center;justify-content:space-between;background:#2c2c38;padding:0}body nav.small>*{margin:0.5rem}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{display:inline-flex;align-items:center}body nav.small span>*{margin-right:0.5rem}body nav.small span>*:last-child{margin-right:0}body nav.small span.title{text-decoration:none;font-family:"Poppins","Franklin Gothic Medium","Arial Narrow",Arial,sans-serif;color:#fefefe;justify-self:center}body nav.small span.placeholder{width:1em;height:1em}body>*{min-width:0;min-height:0}body article{max-width:38rem;padding:0.5rem 2rem 0 2rem}body article>*{max-width:100%}body .next-chapter{width:100%}body .next-chapter a{display:flex;align-items:center;justify-content:flex-end;margin-right:0.5rem;font-size:1.2rem;text-decoration:none;font-family:"Poppins","Franklin Gothic Medium","Arial Narrow",Arial,sans-serif;color:#5babd1}body .next-chapter a:hover{color:#cf5ccd}body .next-chapter a span:first-child{margin-right:0.5rem}body footer{width:100%;text-align:right;display:flex;flex-direction:column;align-items:flex-end;justify-content:flex-end}@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:1rem 0.5rem 0 0.5rem}}body.toc{display:flex;flex-direction:column;justify-content:flex-start;align-items:center}body.toc>*{width:36rem}body.toc header{margin-top:1rem;display:flex;flex-direction:column;align-items:center}body.toc header h1{font-size:3rem;font-weight:700;font-family:"Poppins","Franklin Gothic Medium","Arial Narrow",Arial,sans-serif;margin-bottom:0}body.toc header h2{font-size:1rem;font-weight:600;font-family:"Poppins","Franklin Gothic Medium","Arial Narrow",Arial,sans-serif;margin-bottom:0}body.toc header time{font-size:1rem;font-weight:400;font-family:"Crimson Pro","Georgia",Georgia,"Times New Roman",Times,serif}body.toc nav{background:none;display:flex;flex-direction:column;align-items:stretch}body.toc nav h1{text-align:left;font-size:2.5rem;font-weight:600;margin-bottom:0}body.toc nav ol li{font-size:1.5rem;font-family:"Poppins","Franklin Gothic Medium","Arial Narrow",Arial,sans-serif}body.toc nav ol li a{text-decoration:none;margin:0 0 0.25rem 0;color:#5babd1}body.toc nav ol li a:hover{color:#cf5ccd}body.toc nav>ol{margin-left:0.5rem;margin-right:0.5rem}body.toc article,body.toc nav{padding:0}body.toc article>*,body.toc nav>*{margin-left:0.5rem;margin-right:0.5rem}body.toc footer{flex:1}@media screen and (max-width: 768px){body.toc>*{width:100%}body.toc header h1,body.toc header h2,body.toc header time{text-align:center}body.toc nav h1{font-size:1.75rem}}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}.icon-arrow-up{width:0.875em}.icon-list-ol{width:1em}@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}footer{color:#cccccc}}@media print{body{background:#ffffff;color:#000000}body:not(.toc) nav{display:none}a{color:#000000;text-decoration:underline}h2,h3{break-after:avoid-page}figure{break-inside:avoid}p{orphans:2;widows:2}*{overflow:hidden}body{display:block}} diff --git a/src/main.rs b/src/main.rs index 1af0649..faa01ee 100644 --- a/src/main.rs +++ b/src/main.rs @@ -190,14 +190,14 @@ fn format_code(lang: &str, src: &str) -> Result Result> { +fn wrap_image_in_figure(link: &comrak::nodes::NodeLink, alt: &str) -> Result> { let title = String::from_utf8_lossy(link.title.as_ref()); let url = String::from_utf8_lossy(link.url.as_ref()); if title.len() > 0 { - Ok(format!(r#"
    {}
    {}
    "#, url, title, title)) + Ok(format!(r#"
    {}
    {}
    "#, url, alt, title, title)) } else { - Ok(format!(r#"
    "#, url)) + Ok(format!(r#"
    {}
    "#, url, alt)) } } @@ -256,20 +256,38 @@ fn format_markdown(src: &str) -> Result = Vec::from(output.into_bytes()); - *value = NodeValue::HtmlInline(highlighted); - } - else if let NodeValue::Image(ref link) = value { - let html = wrap_image_in_figure(link)?; - let literal: Vec = Vec::from(html.into_bytes()); - *value = NodeValue::HtmlInline(literal); + match value { + NodeValue::CodeBlock(ref block) => { + let lang = String::from_utf8_lossy(block.info.as_ref()); + let source = String::from_utf8_lossy(block.literal.as_ref()); + let FormatResponse { output, include_katex_css } = format_code(&lang, &source)?; + if include_katex_css { + use_katex_css = true; + } + let highlighted: Vec = Vec::from(output.into_bytes()); + *value = NodeValue::HtmlInline(highlighted); + }, + NodeValue::Paragraph => { + if node.children().count() == 1 { + let first_child = &node.first_child().unwrap(); + let first_value = &first_child.data.borrow().value; + if let NodeValue::Image(link) = first_value { + if first_child.children().count() == 1 { + let second_child = &first_child.first_child().unwrap(); + let second_value = &second_child.data.borrow().value; + if let NodeValue::Text(t) = second_value { + let alt = String::from_utf8_lossy(&t); + let figure = wrap_image_in_figure(&link, &alt)?; + let figure: Vec = Vec::from(figure.into_bytes()); + second_child.detach(); + first_child.detach(); + *value = NodeValue::HtmlInline(figure); + } + } + } + } + }, + _ => {} } Ok(()) })?; @@ -283,6 +301,18 @@ fn format_markdown(src: &str) -> Resultbear
    A majestic bear
    "#); + } +} + #[derive(Template)] #[template(path = "index.html")] struct IndexTemplate<'a, 'b, 'c> { diff --git a/style/base.scss b/style/base.scss index e6a9557..252eaa7 100644 --- a/style/base.scss +++ b/style/base.scss @@ -26,18 +26,18 @@ a { } } +img, +svg, +video { + max-width: 100%; +} + figure { display: block; text-align: center; overflow-x: auto; margin: 0 0 1em; - img, - svg, - video { - max-width: 100%; - } - figcaption { display: block; font-size: 0.75rem;