Skip to content

Commit

Permalink
refactor(parser): disable smart punctuation
Browse files Browse the repository at this point in the history
Related to #138
  • Loading branch information
hougesen committed Apr 1, 2024
1 parent cdd193f commit 7e15ca0
Showing 1 changed file with 42 additions and 1 deletion.
43 changes: 42 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ pub fn format_file(config: &MdsfConfig, path: &std::path::Path) -> Result<(), Md
return Ok(());
}

let parser = pulldown_cmark::Parser::new_ext(&input, pulldown_cmark::Options::all());
let mut parser_options = pulldown_cmark::Options::all();

parser_options.remove(pulldown_cmark::Options::ENABLE_SMART_PUNCTUATION);

let parser = pulldown_cmark::Parser::new_ext(&input, parser_options);

let mut output = String::with_capacity(input.len() + 128);

Expand Down Expand Up @@ -141,3 +145,40 @@ pub fn format_file(config: &MdsfConfig, path: &std::path::Path) -> Result<(), Md

Ok(())
}

#[cfg(test)]
mod tests {
use crate::{config::MdsfConfig, format_file, formatters::setup_snippet};

#[test]
fn it_should_not_modify_base_chars() {
let input_snippet = "```rust
fn add(
a:
i32, b: i32) -> i32 {
a + b
}
```";

let formatted_snippet = "```rust
fn add(a: i32, b: i32) -> i32 {
a + b
}
```";

let n = ["...", "\"mdsf\"", "'mdsf'", "`mdsf`"].join("\n");

let input = format!("{input_snippet}\n\n{n}");
let expected_output = format!("{formatted_snippet}\n\n{n}\n");

let file = setup_snippet(&input, ".md").expect("it to create a file");

let config = MdsfConfig::default();

format_file(&config, file.path()).expect("it to format the file without errors");

let output = std::fs::read_to_string(file.path()).expect("it to read the file");

assert_eq!(output, expected_output);
}
}

0 comments on commit 7e15ca0

Please sign in to comment.