Skip to content

Commit

Permalink
Merge main into only-new-async
Browse files Browse the repository at this point in the history
  • Loading branch information
chriskrycho committed May 16, 2024
2 parents 7c3a85f + 5e9051f commit 72b2c65
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 11 deletions.
41 changes: 33 additions & 8 deletions packages/mdbook-trpl-note/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ impl Preprocessor for TrplNote {
"simple-note-preprocessor"
}

fn run(&self, _ctx: &PreprocessorContext, mut book: Book) -> Result<mdbook::book::Book> {
fn run(
&self,
_ctx: &PreprocessorContext,
mut book: Book,
) -> Result<mdbook::book::Book> {
book.for_each_mut(|item| {
if let BookItem::Chapter(ref mut chapter) = item {
chapter.content = rewrite(&chapter.content);
Expand Down Expand Up @@ -75,7 +79,9 @@ pub fn rewrite(text: &str) -> String {
events.extend([
SoftBreak,
SoftBreak,
Html(r#"<section class="note" aria-role="note">"#.into()),
Html(
r#"<section class="note" aria-role="note">"#.into(),
),
SoftBreak,
SoftBreak,
Start(Tag::Paragraph),
Expand All @@ -89,7 +95,10 @@ pub fn rewrite(text: &str) -> String {
}
}

(StartingBlockquote(_blockquote_events), heading @ Start(Tag::Heading { .. })) => {
(
StartingBlockquote(_blockquote_events),
heading @ Start(Tag::Heading { .. }),
) => {
events.extend([
SoftBreak,
SoftBreak,
Expand All @@ -101,14 +110,18 @@ pub fn rewrite(text: &str) -> String {
state = InNote;
}

(StartingBlockquote(ref mut events), Start(Tag::Paragraph)) => {
events.push(Start(Tag::Paragraph));
(StartingBlockquote(ref mut events), Start(tag)) => {
events.push(Start(tag));
}

(InNote, End(TagEnd::BlockQuote)) => {
// As with the start of the block HTML, the closing HTML must be
// separated from the Markdown text by two newlines.
events.extend([SoftBreak, SoftBreak, Html("</section>".into())]);
events.extend([
SoftBreak,
SoftBreak,
Html("</section>".into()),
]);
state = Default;
}

Expand Down Expand Up @@ -258,7 +271,8 @@ mod tests {

#[test]
fn h1_then_blockquote() {
let text = "> # Header\n > And then some note content.\n\n> This is quoted.";
let text =
"> # Header\n > And then some note content.\n\n> This is quoted.";
let processed = rewrite(text);
assert_eq!(
render_markdown(&processed),
Expand All @@ -268,14 +282,25 @@ mod tests {

#[test]
fn blockquote_then_h1_note() {
let text = "> This is quoted.\n\n> # Header\n > And then some note content.";
let text =
"> This is quoted.\n\n> # Header\n > And then some note content.";
let processed = rewrite(text);
assert_eq!(
render_markdown(&processed),
"<blockquote>\n<p>This is quoted.</p>\n</blockquote>\n<section class=\"note\" aria-role=\"note\">\n<h1>Header</h1>\n<p>And then some note content.</p>\n</section>"
);
}

#[test]
fn blockquote_with_strong() {
let text = "> **Bold text in a paragraph.**";
let processed = rewrite(text);
assert_eq!(
render_markdown(&processed),
"<blockquote>\n<p><strong>Bold text in a paragraph.</strong></p>\n</blockquote>\n"
);
}

fn render_markdown(text: &str) -> String {
let parser = Parser::new(text);
let mut buf = String::new();
Expand Down
5 changes: 2 additions & 3 deletions src/ch01-03-hello-cargo.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ repository; you can override this behavior by using `cargo new --vcs=git`.
Open *Cargo.toml* in your text editor of choice. It should look similar to the
code in Listing 1-2.

<span class="filename">Filename: Cargo.toml</span>
<Listing number="1-2" file-name="Cargo.toml" caption="Contents of *Cargo.toml* generated by `cargo new`">

```toml
[package]
Expand All @@ -71,8 +71,7 @@ edition = "2021"
[dependencies]
```

<span class="caption">Listing 1-2: Contents of *Cargo.toml* generated by `cargo
new`</span>
</Listing>

This file is in the [*TOML*][toml]<!-- ignore --> (*Tom’s Obvious, Minimal
Language*) format, which is Cargo’s configuration format.
Expand Down

0 comments on commit 72b2c65

Please sign in to comment.