Skip to content

Commit

Permalink
handle surrounding spaces in inline code
Browse files Browse the repository at this point in the history
The fix is just to accept the upstream fix, via a dependency update.
Also update / fix tests as necessary.

This resolves #171.
  • Loading branch information
yshavit authored Aug 14, 2024
1 parent 74c9a52 commit fadeb56
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 16 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 @@ -10,7 +10,7 @@ repository = "https://github.com/yshavit/mdq"

[dependencies]
clap = { version = "4.5.7", features = ["derive"] }
markdown = "1.0.0-alpha.19"
markdown = "1.0.0-alpha.20"
paste = "1.0"
regex = "1.10.4"
serde = { version = "1", features = ["derive"] }
Expand Down
30 changes: 18 additions & 12 deletions src/fmt_md_inlines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,13 +377,11 @@ mod tests {
}

#[test]
#[ignore] // #171
fn round_trip_one_backtick_at_start() {
round_trip_inline("`hello");
}

#[test]
#[ignore] // #171
fn round_trip_one_backtick_at_end() {
round_trip_inline("hello `");
}
Expand All @@ -394,38 +392,46 @@ mod tests {
}

#[test]
#[ignore] // #171
fn round_trip_three_backticks_at_end() {
round_trip_inline("hello `");
}

#[test]
#[ignore] // #171
fn round_trip_three_backticks_at_start() {
round_trip_inline("`hello");
}

#[test]
fn round_trip_surrounding_whitespace() {
round_trip_inline(" hello ");
round_trip_inline_to(" hello ", "hello");
}

#[test]
fn round_trip_backtick_and_surrounding_whitespace() {
round_trip_inline(" hello`world ");
round_trip_inline_to(" hello`world ", "hello`world");
}

fn round_trip_inline_to(orig: &str, expect: &str) {
round_trip(
&Inline::Text(Text {
variant: TextVariant::Code,
value: orig.to_string(),
}),
&Inline::Text(Text {
variant: TextVariant::Code,
value: expect.to_string(),
}),
);
}

fn round_trip_inline(inline_str: &str) {
round_trip(&Inline::Text(Text {
variant: TextVariant::Code,
value: inline_str.to_string(),
}));
round_trip_inline_to(inline_str, inline_str);
}
}

/// Not a pure unit test; semi-integ. Checks that writing an inline to markdown and then parsing
/// that markdown results in the original inline.
fn round_trip(orig: &Inline) {
fn round_trip(orig: &Inline, expect: &Inline) {
let mut output = Output::new(String::new());
let mut writer = MdInlinesWriter::new(MdInlinesWriterOptions {
link_format: LinkTransform::Keep,
Expand All @@ -438,6 +444,6 @@ mod tests {

unwrap!(&md_tree[0], MdElem::Paragraph(p));
let parsed = get_only(&p.body);
assert_eq!(parsed, orig);
assert_eq!(parsed, expect);
}
}
2 changes: 1 addition & 1 deletion src/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -985,7 +985,7 @@ mod tests {

unwrap!(&root.children[0], Node::Paragraph(p));
check!(&p.children[0], Node::InlineMath(_), lookups => MdElem::Inline(inline) = {
assert_eq!(inline, Inline::Text (Text{ variant: TextVariant::Math, value: r#" 0 \ne 1 "#.to_string() }));
assert_eq!(inline, Inline::Text (Text{ variant: TextVariant::Math, value: r#"0 \ne 1"#.to_string() }));
});
}

Expand Down

0 comments on commit fadeb56

Please sign in to comment.