Skip to content

Commit

Permalink
release: version 0.3.2
Browse files Browse the repository at this point in the history
  • Loading branch information
KaiserY committed Mar 10, 2024
1 parent d246f2d commit f4ca005
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mdbook-typst-pdf"
version = "0.3.1"
version = "0.3.2"
edition = "2021"
repository = "https://github.com/KaiserY/mdbook-typst-pdf"

Expand Down
1 change: 1 addition & 0 deletions src/assets/template.typ
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"Noto Sans Arabic",
"Noto Sans Hebrew",
"Noto Sans Devanagari",
"Noto Emoji",
),
)

Expand Down
32 changes: 19 additions & 13 deletions src/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,37 +73,34 @@ fn convert_book_item(
.and_then(|f| f.split('.').next())
.ok_or(anyhow!("label not found"))?;

if let Some(number) = &ch.number {
let invisible_heading = if let Some(number) = &ch.number {
if cfg.section_number {
writeln!(
book_item_str,
format!(
"#invisible-heading(level: {}, outlined: true)[#\"{} {}\"] <{}.html>",
number.len(),
number,
ch.name,
label,
)?;
)
} else {
writeln!(
book_item_str,
format!(
"#invisible-heading(level: {}, outlined: true)[{}] <{}.html>",
number.len(),
ch.name,
label,
)?;
label
)
}
} else {
writeln!(
book_item_str,
format!(
"#invisible-heading(level: 1, outlined: true)[{}] <{}.html>",
ch.name, label,
)?;
}
)
};

writeln!(
book_item_str,
"{}#pagebreak(weak: true)",
convert_content(ctx, &ch.content, label)?
convert_content(ctx, &ch.content, label, &invisible_heading)?
)?;
}

Expand All @@ -114,11 +111,14 @@ fn convert_content(
ctx: &RenderContext,
content: &str,
label: &str,
invisible_heading: &str,
) -> Result<String, anyhow::Error> {
let mut content_str = String::new();

let mut heading = String::new();

let mut writen_invisible_heading = false;

let options = Options::ENABLE_SMART_PUNCTUATION
| Options::ENABLE_STRIKETHROUGH
| Options::ENABLE_FOOTNOTES
Expand Down Expand Up @@ -153,6 +153,12 @@ fn convert_content(
label,
mdbook::utils::normalize_id(&heading)
)?;

if !writen_invisible_heading {
writeln!(content_str, "{}", invisible_heading)?;

writen_invisible_heading = true;
}
}
Event::Start(Tag::Emphasis) => write!(content_str, "_")?,
Event::End(TagEnd::Emphasis) => write!(content_str, "_")?,
Expand Down

0 comments on commit f4ca005

Please sign in to comment.