-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: supports readonly and norepl options for codeblock
- Loading branch information
Showing
17 changed files
with
112 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
<div class="repl" data-id="{id}" data-lang="{lang}"> | ||
<div class="repl" data-id="{id}" data-readonly="{readonly}" data-lang="{lang}"> | ||
<iframe src="https://mr-addict.github.io/mdbook-repl/embed" allow="clipboard-write"></iframe> | ||
</div> | ||
|
||
{code} | ||
{codeblock} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Installation | ||
|
||
There two ways to install this preprocessor. | ||
|
||
You can install with **cargo** if you have [rust](https://www.rust-lang.org) installed: | ||
|
||
```sh | ||
cargo install mdbook-repl | ||
``` | ||
|
||
Or you can download the **binary** from [release page](https://github.com/MR-Addict/mdbook-repl/releases). Then you can put the binary in your **PATH**. | ||
|
||
You can check if the installation is successful by running: | ||
|
||
```sh | ||
mdbook-repl --version | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,63 @@ | ||
# Usage | ||
|
||
## Installation | ||
## Basics | ||
|
||
There two ways to install this preprocessor. | ||
|
||
You can install with **cargo** if you have [rust](https://www.rust-lang.org) installed: | ||
|
||
```sh | ||
cargo install mdbook-repl | ||
``` | ||
|
||
Or you can download the **binary** from [release page](https://github.com/MR-Addict/mdbook-repl/releases). Then you can put the binary in your **PATH**. | ||
|
||
You can check if the installation is successful by running: | ||
|
||
```sh | ||
mdbook-repl --version | ||
``` | ||
|
||
## Usage | ||
|
||
After you have installed the preprocessor, you can use it in your **mdbook** project. You need to add the following code to your **book.toml**, so that **mdbook** can use this preprocessor to preprocess your markdown files. | ||
After you installed the preprocessor, you can use it in your **mdbook** project. You need to add the following code to your **book.toml**, so that **mdbook** can use this preprocessor to preprocess your markdown files. | ||
|
||
```toml | ||
[preprocessor.mdbook-repl] | ||
[preprocessor.repl] | ||
``` | ||
|
||
After that, all your markdown files that contain python codeblock will be processed by this preprocessor. It's just like magic. | ||
|
||
For example, you can write a python codeblock in your markdown file: | ||
|
||
```python | ||
````markdown | ||
```python,norepl | ||
# Python codeblock | ||
|
||
print("Hello, world!") | ||
``` | ||
```` | ||
|
||
After you build your **mdbook**, the codeblock will be replaced by the output of the code. | ||
|
||
```python | ||
# Python codeblock | ||
|
||
print("Hello, world!") | ||
``` | ||
|
||
## Extensions | ||
|
||
This preprocessor only recongnizes specific extensions for sepecific language. For example, you can only use `python` or `py` codeblock for python code. | ||
This preprocessor only recongnizes specific extensions for sepecific language. For example, you can only use **python** or **py** codeblock for python code. | ||
|
||
## Options | ||
|
||
You can also specific some options for the codeblock. For example, you can specify the **readonly** for the codeblock, so that the codeblock will not be eidtable. | ||
|
||
<pre><code> | ||
```python, readonly | ||
print("This is a readonly python codeblock") | ||
``` | ||
</code></pre> | ||
|
||
Below is a list of supported extensions for each language: | ||
You can test below codeblock to see the result. | ||
|
||
| Language | Codeblock | | ||
| :------- | :------------- | | ||
| Python | `python`, `py` | | ||
```python, readonly | ||
print("This is a readonly python codeblock") | ||
``` | ||
|
||
And if you put **norepl** in the codeblock, the codeblock will not be rendered by this preprocessor. | ||
|
||
<pre><code> | ||
```python, norepl | ||
print("This is codeblock will not be rendered") | ||
``` | ||
</code></pre> | ||
|
||
You can test below codeblock to see the result. | ||
|
||
```python, norepl | ||
print("This is codeblock will not be rendered") | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters