fixed img figure wrapping

master
Kenton Hamaluik 5 years ago
parent c6b0bdd7ad
commit d858a51a34

60
Cargo.lock generated

@ -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"

@ -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"

@ -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")

@ -12,7 +12,7 @@
<meta property="og:url" content="https://hamaluik.github.io/mkbook//01-introduction/index.html" />
<meta property="book:author" content="Kenton Hamaluik" />
<meta property="book:release_date" content="2019-12-02T20:05:16.402897505+00:00" />
<meta property="book:release_date" content="2019-12-03T17:46:22.953768196+00:00" />
</head>
<body>
@ -41,6 +41,8 @@
<li><a href="../02-markdown/04-katex-formulas.html">KaTeX (Math) Formulas</a></li>
<li><a href="../02-markdown/05-images.html">Images</a></li>
</ol>
</li>

@ -12,7 +12,7 @@
<meta property="og:url" content="https://hamaluik.github.io/mkbook//02-markdown/01-commonmark.html" />
<meta property="book:author" content="Kenton Hamaluik" />
<meta property="book:release_date" content="2019-12-02T20:05:16.402897505+00:00" />
<meta property="book:release_date" content="2019-12-03T17:46:22.953768196+00:00" />
</head>
<body>
@ -41,6 +41,8 @@
<li><a href="../02-markdown/04-katex-formulas.html">KaTeX (Math) Formulas</a></li>
<li><a href="../02-markdown/05-images.html">Images</a></li>
</ol>
</li>
@ -134,8 +136,7 @@
<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;">
<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**

@ -12,7 +12,7 @@
<meta property="og:url" content="https://hamaluik.github.io/mkbook//02-markdown/02-syntax-highlighting.html" />
<meta property="book:author" content="Kenton Hamaluik" />
<meta property="book:release_date" content="2019-12-02T20:05:16.402897505+00:00" />
<meta property="book:release_date" content="2019-12-03T17:46:22.953768196+00:00" />
</head>
<body>
@ -41,6 +41,8 @@
<li><a href="../02-markdown/04-katex-formulas.html">KaTeX (Math) Formulas</a></li>
<li><a href="../02-markdown/05-images.html">Images</a></li>
</ol>
</li>

@ -12,7 +12,7 @@
<meta property="og:url" content="https://hamaluik.github.io/mkbook//02-markdown/03-plantuml-diagrams.html" />
<meta property="book:author" content="Kenton Hamaluik" />
<meta property="book:release_date" content="2019-12-02T20:05:16.402897505+00:00" />
<meta property="book:release_date" content="2019-12-03T17:46:22.953768196+00:00" />
</head>
<body>
@ -41,6 +41,8 @@
<li><a href="../02-markdown/04-katex-formulas.html">KaTeX (Math) Formulas</a></li>
<li><a href="../02-markdown/05-images.html">Images</a></li>
</ol>
</li>

@ -12,7 +12,7 @@
<meta property="og:url" content="https://hamaluik.github.io/mkbook//02-markdown/04-katex-formulas.html" />
<meta property="book:author" content="Kenton Hamaluik" />
<meta property="book:release_date" content="2019-12-02T20:05:16.402897505+00:00" />
<meta property="book:release_date" content="2019-12-03T17:46:22.953768196+00:00" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.11.1/dist/katex.min.css" integrity="sha384-zB1R0rpPzHqg7Kpt0Aljp8JPLqbXI3bhnPWROx27a9N0Ll6ZP/+DiW/UqRcLbRjq" crossorigin="anonymous">
</head>
<body>
@ -41,6 +41,8 @@
<li><a href="../02-markdown/04-katex-formulas.html" class = "current">KaTeX (Math) Formulas</a></li>
<li><a href="../02-markdown/05-images.html">Images</a></li>
</ol>
</li>
@ -94,7 +96,7 @@
<span class="placeholder"></span>
<a href="../03-frontmatter&#x2f;index.html" alt="Front Matter">
<a href="../02-markdown&#x2f;05-images.html" alt="Images">
<span class="icon">
<svg class="icon-arrow-right">
<use xlink:href="../icons.svg#icon-arrow-right">
@ -133,8 +135,8 @@ M834 80h400000v40h-400000z'/></svg></span></span></span><span class="vlist-s">
<div class="next-chapter">
<a href="../03-frontmatter&#x2f;index.html">
<span>Next chapter: “Front Matter</span>
<a href="../02-markdown&#x2f;05-images.html">
<span>Next chapter: “Images</span>
<span class="icon">
<svg class="icon-arrow-right">
<use xlink:href="../icons.svg#icon-arrow-right">

@ -0,0 +1,137 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>The mkbook Book | Images</title>
<link rel="stylesheet" href="../style.css" type="text/css" media="all" />
<link rel="shortcut icon" href="../favicon.ico" />
<meta property="og:title" content="The mkbook Book" />
<meta property="og:site_name" content="The mkbook Book" />
<meta property="og:type" content="book" />
<meta property="og:url" content="https://hamaluik.github.io/mkbook//02-markdown/05-images.html" />
<meta property="book:author" content="Kenton Hamaluik" />
<meta property="book:release_date" content="2019-12-03T17:46:22.953768196+00:00" />
</head>
<body>
<nav class="big">
<header>
<h1><a href="../index.html">The mkbook Book</a></h1>
<h2>by Kenton Hamaluik</h2>
</header>
<ol>
<li>
<a href="../01-introduction/index.html">Introduction</a>
</li>
<li>
<a href="../02-markdown/index.html">Markdown</a>
<ol>
<li><a href="../02-markdown/01-commonmark.html">CommonMark</a></li>
<li><a href="../02-markdown/02-syntax-highlighting.html">Syntax Highlighting</a></li>
<li><a href="../02-markdown/03-plantuml-diagrams.html">PlantUML Diagrams</a></li>
<li><a href="../02-markdown/04-katex-formulas.html">KaTeX (Math) Formulas</a></li>
<li><a href="../02-markdown/05-images.html" class = "current">Images</a></li>
</ol>
</li>
<li>
<a href="../03-frontmatter/index.html">Front Matter</a>
</li>
<li>
<a href="../04-structure/index.html">Structure</a>
</li>
<li>
<a href="../05-customization/index.html">Customization</a>
</li>
<li>
<a href="../06-how-it-works/index.html">How it Works</a>
</li>
</ol>
</nav>
<nav class="small">
<span>
<a href="../index.html" alt="Table of Contents">
<span class="icon">
<svg class="icon-list-ol">
<use xlink:href="../icons.svg#icon-list-ol">
</svg>
</span>
</a>
<a href="../02-markdown&#x2f;04-katex-formulas.html" alt="KaTeX (Math) Formulas">
<span class="icon">
<svg class="icon-arrow-left">
<use xlink:href="../icons.svg#icon-arrow-left">
</svg>
</span>
</a>
</span>
<span class="title">Images</span>
<span>
<span class="placeholder"></span>
<a href="../03-frontmatter&#x2f;index.html" alt="Front Matter">
<span class="icon">
<svg class="icon-arrow-right">
<use xlink:href="../icons.svg#icon-arrow-right">
</svg>
</span>
</a>
</span>
</nav>
<article>
<p>To include an image, use the standard markdown format:</p>
<pre style="background-color:#2d2d2d;">
<span style="color:#f99157;">![title](url)
</span></pre>
<p>This will wrap the image in a <code>figure</code> with an associated <code>figcaption</code> containing the title of the image, as so:</p>
<pre style="background-color:#2d2d2d;">
<span style="color:#f99157;">![a bear](https://placebear.com/g/512/256 </span><span style="color:#d3d0c8;">&quot;</span><span style="color:#f2777a;">A majestic bear</span><span style="color:#d3d0c8;">&quot;</span><span style="color:#f99157;">)
</span></pre>
<p>will render as:</p>
<figure><img src="https://placebear.com/g/512/256" alt="a bear" title="A majestic bear"><figcaption>A majestic bear</figcaption></figure>
<div class="next-chapter">
<a href="../03-frontmatter&#x2f;index.html">
<span>Next chapter: “Front Matter”</span>
<span class="icon">
<svg class="icon-arrow-right">
<use xlink:href="../icons.svg#icon-arrow-right">
</svg>
</span>
</a>
</div>
<footer><p>&copy; 2019 Kenton Hamaluik</p></footer>
</article>
</body>
</html>

@ -12,7 +12,7 @@
<meta property="og:url" content="https://hamaluik.github.io/mkbook//02-markdown/index.html" />
<meta property="book:author" content="Kenton Hamaluik" />
<meta property="book:release_date" content="2019-12-02T20:05:16.402897505+00:00" />
<meta property="book:release_date" content="2019-12-03T17:46:22.953768196+00:00" />
</head>
<body>
@ -41,6 +41,8 @@
<li><a href="../02-markdown/04-katex-formulas.html">KaTeX (Math) Formulas</a></li>
<li><a href="../02-markdown/05-images.html">Images</a></li>
</ol>
</li>

@ -12,7 +12,7 @@
<meta property="og:url" content="https://hamaluik.github.io/mkbook//03-frontmatter/index.html" />
<meta property="book:author" content="Kenton Hamaluik" />
<meta property="book:release_date" content="2019-12-02T20:05:16.402897505+00:00" />
<meta property="book:release_date" content="2019-12-03T17:46:22.953768196+00:00" />
</head>
<body>
@ -41,6 +41,8 @@
<li><a href="../02-markdown/04-katex-formulas.html">KaTeX (Math) Formulas</a></li>
<li><a href="../02-markdown/05-images.html">Images</a></li>
</ol>
</li>
@ -78,7 +80,7 @@
</a>
<a href="../02-markdown&#x2f;04-katex-formulas.html" alt="KaTeX (Math) Formulas">
<a href="../02-markdown&#x2f;05-images.html" alt="Images">
<span class="icon">
<svg class="icon-arrow-left">

@ -12,7 +12,7 @@
<meta property="og:url" content="https://hamaluik.github.io/mkbook//04-structure/index.html" />
<meta property="book:author" content="Kenton Hamaluik" />
<meta property="book:release_date" content="2019-12-02T20:05:16.402897505+00:00" />
<meta property="book:release_date" content="2019-12-03T17:46:22.953768196+00:00" />
</head>
<body>
@ -41,6 +41,8 @@
<li><a href="../02-markdown/04-katex-formulas.html">KaTeX (Math) Formulas</a></li>
<li><a href="../02-markdown/05-images.html">Images</a></li>
</ol>
</li>

@ -12,7 +12,7 @@
<meta property="og:url" content="https://hamaluik.github.io/mkbook//05-customization/index.html" />
<meta property="book:author" content="Kenton Hamaluik" />
<meta property="book:release_date" content="2019-12-02T20:05:16.402897505+00:00" />
<meta property="book:release_date" content="2019-12-03T17:46:22.953768196+00:00" />
</head>
<body>
@ -41,6 +41,8 @@
<li><a href="../02-markdown/04-katex-formulas.html">KaTeX (Math) Formulas</a></li>
<li><a href="../02-markdown/05-images.html">Images</a></li>
</ol>
</li>

@ -12,7 +12,7 @@
<meta property="og:url" content="https://hamaluik.github.io/mkbook//06-how-it-works/index.html" />
<meta property="book:author" content="Kenton Hamaluik" />
<meta property="book:release_date" content="2019-12-02T20:05:16.402897505+00:00" />
<meta property="book:release_date" content="2019-12-03T17:46:22.953768196+00:00" />
</head>
<body>
@ -41,6 +41,8 @@
<li><a href="../02-markdown/04-katex-formulas.html">KaTeX (Math) Formulas</a></li>
<li><a href="../02-markdown/05-images.html">Images</a></li>
</ol>
</li>

@ -14,14 +14,14 @@
&lt;p&gt;This tool aims to work somewhat similarly to &lt;em&gt;mdbook&lt;&#x2f;em&gt;, but is generally intended to be a more minimal alternative that is customized more towards my needs and desires than anything else.&lt;&#x2f;p&gt;
" />
<meta property="book:author" content="Kenton Hamaluik" />
<meta property="book:release_date" content="2019-12-02T20:05:16.402897505+00:00" />
<meta property="book:release_date" content="2019-12-03T17:46:22.953768196+00:00" />
</head>
<body class="toc">
<header>
<h1>The mkbook Book</h1>
<h2>by Kenton Hamaluik</h2>
<time datetime="2019-12-02T20:05:16.402897505+00:00">Dec 2, 2019</time>
<time datetime="2019-12-03T17:46:22.953768196+00:00">Dec 3, 2019</time>
</header>
<article>
<p><em>mkbook</em> is my simpler alternative to <a href="https://crates.io/crates/mdbook">mdbook</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>
@ -50,6 +50,8 @@
<li><a href="02-markdown/04-katex-formulas.html">KaTeX (Math) Formulas</a></li>
<li><a href="02-markdown/05-images.html">Images</a></li>
</ol>
</li>

File diff suppressed because one or more lines are too long

@ -190,14 +190,14 @@ fn format_code(lang: &str, src: &str) -> Result<FormatResponse, Box<dyn std::err
})
}
fn wrap_image_in_figure(link: &comrak::nodes::NodeLink) -> Result<String, Box<dyn std::error::Error>> {
fn wrap_image_in_figure(link: &comrak::nodes::NodeLink, alt: &str) -> Result<String, Box<dyn std::error::Error>> {
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#"<figure><img src="{}" alt="{}"><figcaption>{}</figcaption></figure>"#, url, title, title))
Ok(format!(r#"<figure><img src="{}" alt="{}" title="{}"><figcaption>{}</figcaption></figure>"#, url, alt, title, title))
}
else {
Ok(format!(r#"<figure><img src="{}"></figure>"#, url))
Ok(format!(r#"<figure><img src="{}" alt="{}"></figure>"#, url, alt))
}
}
@ -256,20 +256,38 @@ fn format_markdown(src: &str) -> Result<FormatResponse, Box<dyn std::error::Erro
let mut use_katex_css = false;
iter_nodes(root, &mut |node| {
let value = &mut node.data.borrow_mut().value;
if let NodeValue::CodeBlock(ref block) = value {
let lang = String::from_utf8(block.info.clone()).expect("code lang is utf-8");
let source = String::from_utf8(block.literal.clone()).expect("source code is utf-8");
let FormatResponse { output, include_katex_css } = format_code(&lang, &source)?;
if include_katex_css {
use_katex_css = true;
}
let highlighted: Vec<u8> = 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<u8> = 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<u8> = 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<u8> = 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) -> Result<FormatResponse, Box<dyn std::error::Erro
})
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn can_generate_figures() {
let src = r#"![bear](https://placebear.com/g/512/256 "A majestic bear")"#;
let result = format_markdown(src).expect("can format");
assert_eq!(result.output, r#"<figure><img src="https://placebear.com/g/512/256" alt="bear" title="A majestic bear"><figcaption>A majestic bear</figcaption></figure>"#);
}
}
#[derive(Template)]
#[template(path = "index.html")]
struct IndexTemplate<'a, 'b, 'c> {

@ -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;

Loading…
Cancel
Save