Crates.io | mdbook-obsidian |
lib.rs | mdbook-obsidian |
version | 0.1.0 |
source | src |
created_at | 2024-02-05 16:00:53.886861 |
updated_at | 2024-02-05 16:00:53.886861 |
description | mdBook preprocessor to render Obsidian specific syntax |
homepage | |
repository | https://github.com/GeckoEidechse/mdbook-obsidian |
max_upload_size | |
id | 1127711 |
size | 87,457 |
mdBook preprocessor to render Obsidian specific syntax in mdBook.
To see the list of existing and supported syntax, see this GitHub issue.
⚠️ WIP ⚠️
This mdBook preprocessor is very much work-in-progress and currently only supports a small subset of the total Obsidian specific syntax. Contributions to expand the supported syntax are more than welcome <3
If you'd like to take over maintainership or ownership of this crate, please get in touch via an issue in the GitHub repo of this crate.
First, install the preprocessor:
cargo install mdbook-obsidian
Then, add the preprocessor to your book.toml
:
[book]
authors = ["Jill Doe"]
language = "en"
multilingual = false
src = "src"
title = "My awesome Book"
# ADD THIS
[preprocessor.obsidian]
The way this preprocessor works is primarily by using regexes to search for specific patterns like
> [!CALLOUT_TYPE]
> CALLOUT_BODY
and then replacing it with the corresponding HTML code like
<style>
/* a bunch of CSS */
</style>
<div class="mdbook-obsidian-callouts mdbook-obsidian-callouts-{kind}">
<p class="mdbook-obsidian-callouts-title">
<span class="mdbook-obsidian-callouts-icon"></span>
CALLOUT_TYPE
</p>
CALLOUT_BODY
</div>
The currently supported syntax is tracked in this GitHub issue
To add support for some currently unsupported syntax, expand the existing existing main render loop in lib.rs
/// Apply to all chapters
fn handle_chapter(chapter: &mut Chapter) -> Result<(), Error> {
chapter.content = callouts::render(&chapter.content)?;
// Add your additional syntax parsing here
Ok(())
}
with a function that calls the corresponding parsing logic.
In your parsing logic, use regex or any other methods to scan for the specific pattern of the syntax you want to support and replace it with the corresponding HTML code.