Skip to content

Commit

Permalink
Merge pull request #126 from Manishearth/normalize
Browse files Browse the repository at this point in the history
Pass non normalized reference down
  • Loading branch information
raphlinus authored Feb 19, 2018
2 parents 0108f2e + 70c0956 commit 5b7c90c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
9 changes: 5 additions & 4 deletions src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,9 @@ pub struct RawParser<'a> {
last_line_was_empty: bool,

/// In case we have a broken link/image reference, we can call this callback
/// with the reference name and use the link/title pair returned instead
broken_link_callback: Option<&'a Fn(&str) -> Option<(String, String)>>,
/// with the reference name (both normalized and not normalized) and use
/// the link/title pair returned instead
broken_link_callback: Option<&'a Fn(&str, &str) -> Option<(String, String)>>,

// state for code fences
fence_char: u8,
Expand Down Expand Up @@ -151,7 +152,7 @@ const MAX_LINK_NEST: usize = 10;
impl<'a> RawParser<'a> {
pub fn new_with_links_and_callback(text: &'a str, opts: Options,
links: HashMap<String, (Cow<'a, str>, Cow<'a, str>)>,
callback: Option<&'a Fn(&str) -> Option<(String, String)>>)
callback: Option<&'a Fn(&str, &str) -> Option<(String, String)>>)
-> RawParser<'a> {
let mut ret = RawParser {
text: text,
Expand Down Expand Up @@ -1313,7 +1314,7 @@ impl<'a> RawParser<'a> {
Some(&(ref dest, ref title)) => (dest.clone(), title.clone()),
None => {
if let Some(ref callback) = self.broken_link_callback {
if let Some(val) = callback(&reference) {
if let Some(val) = callback(&reference, &data[ref_beg..ref_end]) {
(val.0.into(), val.1.into())
} else {
return None;
Expand Down
2 changes: 1 addition & 1 deletion src/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl<'a> Parser<'a> {
/// and the returned pair will be used as the link name and title if not
/// None.
pub fn new_with_broken_link_callback(text: &'a str, mut opts: Options,
callback: Option<&'a Fn(&str) -> Option<(String, String)>>)
callback: Option<&'a Fn(&str, &str) -> Option<(String, String)>>)
-> Parser<'a> {
opts.remove(OPTION_FIRST_PASS);
// first pass, collecting info
Expand Down
2 changes: 1 addition & 1 deletion tests/html.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ fn html_test_broken_callback() {

let mut s = String::new();

let callback = |reference: &str| -> Option<(String, String)> {
let callback = |reference: &str, _normalized: &str| -> Option<(String, String)> {
if reference == "foo" || reference == "baz" {
Some(("https://replaced.example.org".into(), "some title".into()))
} else {
Expand Down

0 comments on commit 5b7c90c

Please sign in to comment.