Skip to content

Commit

Permalink
Mimic 😛 mdBook implementation 🎁 (#79)
Browse files Browse the repository at this point in the history
* Mimic `mdBook` implementation 🎁

Switch from `lazy_static::lazy_static` to `once_cell::sync::lazy`
And, it includes the fix for #78

* Handle potential errors more gracefully

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* fmt!

---------

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
  • Loading branch information
CoralPink and coderabbitai[bot] authored Jan 20, 2024
1 parent 145a679 commit 5472993
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 40 deletions.
58 changes: 26 additions & 32 deletions rs/mdbook-footnote/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions rs/mdbook-footnote/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mdbook-footnote"
version = "1.0.3"
version = "1.1.0"
authors = ["David Drysdale <dmd@lurklurk.org>", "CoralPink"]
edition = "2021"
rust-version = "1.70"
Expand All @@ -9,10 +9,10 @@ license = "Apache-2.0"
[dependencies]
clap = "4.4"
mdbook = "0.4"
once_cell = "1.19"
regex = "1.10"
semver = "1.0"
serde_json = "1.0"
lazy_static = "1.4"
regex = "1.10"

[profile.release]
lto = "thin"
Expand Down
10 changes: 5 additions & 5 deletions rs/mdbook-footnote/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use lazy_static::lazy_static;
use mdbook::{book::Book, errors::Error};
use once_cell::sync::Lazy;
use regex::Regex;

lazy_static! {
static ref FOOTNOTE_RE: Regex =
Regex::new(r"(?s)\{\{footnote:\s*(?P<content>.*?)\}\}").unwrap();
}
static FOOTNOTE_RE: Lazy<Regex> = Lazy::new(|| {
Regex::new(r"(?s)\{\{footnote:\s*(?P<content>.*?)\}\}").expect("Invalid regex for FOOTNOTE_RE")
});

pub fn replacing(mut book: Book) -> Result<Book, Error> {
book.for_each_mut(|item| {
Expand Down Expand Up @@ -39,5 +38,6 @@ pub fn replacing(mut book: Book) -> Result<Book, Error> {
}
}
});

Ok(book)
}

0 comments on commit 5472993

Please sign in to comment.