Skip to content

Commit

Permalink
fix: escape quotes within link titles (#6)
Browse files Browse the repository at this point in the history
Before, link titles that contained quotes would be rendered without
their interior quotes escaped and preprocessing would turn
```md
[link](dest "\"weird title\"")
```
into
```md
[link](dest ""weird title"")
```
resulting in a broken link.

This was due to a bug in `pulldown-cmark-to-cmark` fixed in
Byron/pulldown-cmark-to-cmark#62 and released in
version 11.0.2, so this PR bumps the version requirement.
  • Loading branch information
max-heller authored Nov 25, 2023
1 parent aa79daf commit 0722b4f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ log = "0.4.0"
mdbook = { version = "0.4.21", default-features = false }
once_cell = "1.0.0"
pulldown-cmark = { version = "0.9.0", default-features = false }
pulldown-cmark-to-cmark = "11.0.1"
pulldown-cmark-to-cmark = "11.0.2"
regex = "1.0.0"
semver = "1.0.0"
serde = { version = "1.0.85", features = ["derive"] }
Expand Down
25 changes: 25 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -792,6 +792,31 @@ This is an example of a footnote[^note].
"###);
}

#[test]
fn link_title_containing_quotes() {
let book = MDBook::init()
.config(Config::latex())
.chapter(Chapter::new(
"",
r#"
[link][link-with-description]
[link-with-description]: chapter.md '"foo" (bar)'
"#,
"chapter.md",
))
.build();
insta::assert_display_snapshot!(book, @r###"
├─ log output
│ INFO mdbook::book: Running the pandoc backend
│ INFO mdbook_pandoc::render: Wrote output to book/latex/output.tex
├─ latex/output.tex
│ \href{chapter.md}{link}
├─ latex/src/chapter.md
│ [link](chapter.md "\"foo\" (bar)")
"###);
}

#[test]
fn raw_opts() {
let cfg = r#"
Expand Down

0 comments on commit 0722b4f

Please sign in to comment.