Skip to content

Commit

Permalink
fix shortcuts rendering
Browse files Browse the repository at this point in the history
fix #35
  • Loading branch information
aogier authored and Byron committed Dec 5, 2021
1 parent 68a9b6a commit 3bbc763
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ where
if inside_shortcut {
shortcuts.push((current_shortcut.clone(), uri.to_string(), title.to_string()));
inside_shortcut = false;
current_shortcut = String::new();
}
formatter.write_char(']')
}
Expand Down Expand Up @@ -515,9 +516,9 @@ where
}?
}
if !shortcuts.is_empty() {
formatter.write_str("\n\n")?;
formatter.write_str("\n")?;
for shortcut in shortcuts {
write!(formatter, "[{}", shortcut.0)?;
write!(formatter, "\n[{}", shortcut.0)?;
close_link(&shortcut.1, &shortcut.2, &mut formatter, LinkType::Shortcut)?
}
}
Expand Down
5 changes: 3 additions & 2 deletions tests/fixtures/common-mark.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Ask to <[email protected]>.

[1]: http://www.example.com/reference

## Images
## [Images]

Images as blocks:

Expand Down Expand Up @@ -204,4 +204,5 @@ foo
* | < > #
````

[Links]: http://www.example.com/shortcut
[Links]: http://www.example.com/shortcut
[Images]: http://www.example.com/another_shortcut
5 changes: 3 additions & 2 deletions tests/fixtures/snapshots/stupicat-output
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ sea [takimata sanctus](./showcase.md) est Lorem ipsum dolor sit amet.

Ask to <[email protected]>.

## Images
## [Images]

Images as blocks:

Expand Down Expand Up @@ -203,4 +203,5 @@ foo
* | < > #
````

[Links]: http://www.example.com/shortcut
[Links]: http://www.example.com/shortcut
[Images]: http://www.example.com/another_shortcut
14 changes: 14 additions & 0 deletions tests/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,20 @@ mod inline_elements {
)
}

#[test]
fn multiple_shortcut_links() {
assert_eq!(
fmts("[a](b)\n[c] [d]\n\n[c]: e\n[d]: f"),
(
"[a](b)\n[c] [d]\n\n[c]: e\n[d]: f".into(),
State {
newlines_before_start: 2,
..Default::default()
}
)
)
}

#[test]
fn various() {
assert_eq!(
Expand Down

0 comments on commit 3bbc763

Please sign in to comment.