Skip to content

Commit d124f44

Browse files
committed
feat: update to version 0.2.14, refactor include script, and add canvas app template
1 parent 1762fea commit d124f44

File tree

12 files changed

+187
-111
lines changed

12 files changed

+187
-111
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
book
22
target
3-
docs/src/assets/templates

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "mdbook-embedify"
3-
version = "0.2.13"
3+
version = "0.2.14"
44
edition = "2021"
55
license = "MIT"
66
readme = "README.md"

docs/assets/templates/canvas.html

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<style>
2+
.canvas-container {
3+
width: 100%;
4+
background: white;
5+
border-radius: 1rem;
6+
border: 1px solid #ccc;
7+
8+
background-size: 20px 20px;
9+
background-image: linear-gradient(to right, #eee 1px, transparent 1px),
10+
linear-gradient(to bottom, #eee 1px, transparent 1px);
11+
}
12+
</style>
13+
<div class="canvas-container">
14+
<canvas height="{% height=600 %}"></canvas>
15+
</div>
16+
<script>
17+
document.addEventListener("DOMContentLoaded", () => {
18+
const container = document.querySelector(".canvas-container");
19+
const canvas = container.querySelector("canvas");
20+
const ctx = canvas.getContext("2d");
21+
const resizeObserver = new ResizeObserver((entries) => {
22+
for (const entry of entries) canvas.width = entry.contentRect.width;
23+
});
24+
resizeObserver.observe(container);
25+
26+
let drawing = false;
27+
const lastPos = { x: 0, y: 0 };
28+
29+
canvas.addEventListener("mousedown", (e) => {
30+
drawing = true;
31+
lastPos.x = e.offsetX;
32+
lastPos.y = e.offsetY;
33+
});
34+
35+
canvas.addEventListener("mousemove", (e) => {
36+
if (!drawing) return;
37+
ctx.beginPath();
38+
ctx.moveTo(lastPos.x, lastPos.y);
39+
ctx.lineTo(e.offsetX, e.offsetY);
40+
ctx.stroke();
41+
lastPos.x = e.offsetX;
42+
lastPos.y = e.offsetY;
43+
});
44+
45+
canvas.addEventListener("mouseup", () => (drawing = false));
46+
canvas.addEventListener("mouseout", () => (drawing = false));
47+
});
48+
</script>

docs/book.toml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,16 @@ heading-split-level = 3
4242
copy-js = true
4343

4444
[preprocessor.embedify]
45-
command = "target/release/mdbook-embedify"
46-
custom-templates-folder = "src/assets/templates"
45+
custom-templates-folder = "assets/templates"
4746

4847
scroll-to-top.enable = true
4948

5049
footer.enable = true
5150
footer.message = "Copyright © 2025 • Created with ❤️ by [MR-Addict](https://github.com/MR-Addict)"
5251

5352
announcement-banner.enable = true
54-
announcement-banner.id = "0.2.13"
55-
announcement-banner.message = "*Version **0.2.13** now has relased, check it out [here](https://github.com/MR-Addict/mdbook-embedify/releases/tag/0.2.13).*"
53+
announcement-banner.id = "0.2.14"
54+
announcement-banner.message = "*Version **0.2.14** now has relased, check it out [here](https://github.com/MR-Addict/mdbook-embedify/releases/tag/0.2.14).*"
5655

5756
giscus.enable = true
5857
giscus.repo = "MR-Addict/mdbook-embedify"
@@ -63,3 +62,6 @@ giscus.reactions-enabled = "1"
6362
giscus.theme = "book"
6463
giscus.lang = "en"
6564
giscus.loading = "lazy"
65+
66+
# This is for the development environment
67+
command = "target/release/mdbook-embedify"

docs/src/global-embedding.md

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,6 @@ scroll-to-top.enable = true
1919

2020
Below is a full list of apps that support global configuration:
2121

22-
```toml
23-
[preprocessor.embedify]
24-
scroll-to-top.enable = true
25-
26-
footer.enable = true
27-
footer.message = "Copyright © 2025 • Created with ❤️ by [MR-Addict](https://github.com/MR-Addict)"
28-
29-
announcement-banner.enable = true
30-
announcement-banner.id = "0.2.13"
31-
announcement-banner.message = "*Version **0.2.13** now has relased, check it out [here](https://github.com/MR-Addict/mdbook-embedify/releases/tag/0.2.13).*"
32-
33-
giscus.enable = true
34-
giscus.repo = "MR-Addict/mdbook-embedify"
35-
giscus.repo-id = "R_XXXXXXXXXX"
36-
giscus.category = "General"
37-
giscus.category-id = "DIC_XXXXXXXXXXXXXXXX"
38-
giscus.reactions-enabled = "1"
39-
giscus.theme = "book"
40-
giscus.lang = "en"
41-
giscus.loading = "lazy"
42-
```
22+
{% embed include file="book.toml" range="44-64" %}
4323

4424
You can see more details about each app at its own page.

docs/src/local/announcement-banner.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Announcement banner allows you put important messages at the top of the page. It
1414
<!-- embed ignore begin -->
1515

1616
```text
17-
{% embed announcement-banner id="0.2.13" message="*Version **0.2.13** now has relased, check it out [here](https://github.com/MR-Addict/mdbook-embedify/releases/tag/0.2.13).*" %}
17+
{% embed announcement-banner id="0.2.14" message="*Version **0.2.14** now has relased, check it out [here](https://github.com/MR-Addict/mdbook-embedify/releases/tag/0.2.14).*" %}
1818
```
1919

2020
<!-- embed ignore end -->
@@ -23,10 +23,6 @@ This book's announcement banner is enabled, you can see it at the top of this pa
2323

2424
However, you may want to enable it for the whole book. You can do this by adding below options to `book.toml` file after `[preprocessor.embedify]` section:
2525

26-
```toml
27-
announcement-banner.enable = true
28-
announcement-banner.id = "0.2.13"
29-
announcement-banner.message = "*Version **0.2.13** now has relased, check it out [here](https://github.com/MR-Addict/mdbook-embedify/releases/tag/0.2.13).*"
30-
```
26+
{% embed include file="book.toml" range="52-54" %}
3127

3228
Note that announcement banner id must be **unique**, otherwise it won't be shown if there is another announcement banner with the same id when user closed it.

docs/src/local/footer.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,4 @@ This book's footer is enabled, you can see it at the bottom of this page.
2222

2323
However, you may want to enable it for the whole book. You can do this by adding below options to `book.toml` file after `[preprocessor.embedify]` section:
2424

25-
```toml
26-
footer.enable = true
27-
footer.message = "Copyright © 2025 • Created with ❤️ by [MR-Addict](https://github.com/MR-Addict)"
28-
```
25+
{% embed include file="book.toml" range="49-50" %}

docs/src/local/include.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,32 @@
66
77
The include app is for including source file and wrapped it as markdown code block.
88

9-
The language is automatically detected by the file name extension. You can override it by passing `lang` option. The file path should be relative to the execution directory.
9+
The language is automatically detected by the file name extension. You can override it by passing `lang` option. The file path should be relative to book root directory.
1010

1111
## Options
1212

13-
| Option | Description | Required | Default |
14-
| :----- | :------------------------------------------------------ | :------- | :------ |
15-
| file | File to include, relative to the exection directory | Yes | - - |
16-
| lang | This will override the automatically detected language | No | - - |
17-
| range | Range of lines to include, e.g. `1-10` or `1-` or `-10` | No | - - |
18-
| type | Include type, `insert` or `embed` | No | `embed` |
13+
| Option | Description | Required | Default |
14+
| :----- | :------------------------------------------------------ | :------- | :---------- |
15+
| file | File to include, relative to book root directory | Yes | - - |
16+
| lang | This will override the automatically detected language | No | - - |
17+
| range | Range of lines to include, e.g. `1-10` or `1-` or `-10` | No | - - |
18+
| type | Include type, cloud be `raw` or `codeblock` | No | `codeblock` |
1919

2020
> Attention 💥
2121
>
22-
> - When `range` is used, it will insert the specified lines.
23-
> - The `insert` type will insert the file content into the markdown file directly, while the `embed` type will wrap it as a code block.
22+
> - When `range` is used, it will insert the specified lines starts from 1.
23+
> - The `raw` type will insert the raw file content into the markdown file directly, while the `codeblock` type will wrap it as a code block.
2424
2525
## Example
2626

2727
<!-- embed ignore begin -->
2828

2929
```text
30-
{% embed include file="docs/src/SUMMARY.md" %}
30+
{% embed include file="src/SUMMARY.md" %}
3131
```
3232

3333
<!-- embed ignore end -->
3434

35-
This will include the [docs/src/SUMMARY.md](https://github.com/MR-Addict/mdbook-embedify/blob/main/docs/src/SUMMARY.md) file and wrap it as a code block which is the source code of this book's summary.
35+
This will include the [src/SUMMARY.md](https://github.com/MR-Addict/mdbook-embedify/blob/main/docs/src/SUMMARY.md) file and wrap it as a markdown code block which is the source code of this book's summary.
3636

37-
{% embed include file="docs/src/SUMMARY.md" %}
37+
{% embed include file="src/SUMMARY.md" %}

0 commit comments

Comments
 (0)