Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
xfbs committed Dec 28, 2023
1 parent 45acab5 commit 90f13a5
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 15 deletions.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion example/book.toml → book/book.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ authors = ["Patrick Elsen"]
language = "en"
multilingual = false
src = "src"
title = "mdbook-files demo"
title = "mdbook-files book"

[preprocessor.files]
command = "cargo run --"
Expand Down
3 changes: 2 additions & 1 deletion example/src/SUMMARY.md → book/src/SUMMARY.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Summary

- [Source](source.md)
- [Setup](setup.md)
- [Tests](source.md)
- [Subchapter](subchapter.md)
1 change: 1 addition & 0 deletions book/src/setup.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Setup
File renamed without changes.
4 changes: 3 additions & 1 deletion example/src/subchapter.md → book/src/subchapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ This is a subchapter.

```files
title = "This is a title"
files = ["example/book.toml"]
files = ["book/book.toml"]
```

## Subchapter
File renamed without changes.
27 changes: 15 additions & 12 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,25 @@ impl Config {
}});
</script>"#).into())));

events.push(Event::HardBreak);
Ok(events)
}

fn label(&self) -> &str {
"files"
}

fn map_chapter(&self, chapter: Chapter) -> Result<Chapter> {
let mut parser = Parser::new_ext(&chapter.content, Options::all());
fn map_chapter(&self, mut chapter: Chapter) -> Result<Chapter> {
chapter.content = self.map_markdown(&chapter.content)?;
chapter.sub_items = std::mem::take(&mut chapter.sub_items)
.into_iter()
.map(|item| self.map_book_item(item))
.collect::<Result<_, _>>()?;
Ok(chapter)
}

fn map_markdown(&self, markdown: &str) -> Result<String> {
let mut parser = Parser::new_ext(&markdown, Options::all());
let mut events = vec![];

loop {
Expand All @@ -171,16 +181,9 @@ impl Config {
}
}

let mut buf = String::with_capacity(chapter.content.len());
let output = cmark(events.iter(), &mut buf).map(|_| buf).unwrap();
let mut chapter = chapter;
chapter.content = output;

chapter.sub_items = std::mem::take(&mut chapter.sub_items)
.into_iter()
.map(|item| self.map_book_item(item))
.collect::<Result<_, _>>()?;
Ok(chapter)
let mut buf = String::with_capacity(markdown.len());
let output = cmark(events.iter(), &mut buf).map(|_| buf)?;
Ok(output)
}
}

Expand Down

0 comments on commit 90f13a5

Please sign in to comment.