-
Notifications
You must be signed in to change notification settings - Fork 45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Context-sensitive relative URL rewrite #97
Conversation
src/lib.rs
Outdated
link_rel: Option<&'a str>, | ||
allowed_classes: HashMap<&'a str, HashSet<&'a str>>, | ||
strip_comments: bool, | ||
id_prefix: Option<&'a str>, | ||
} | ||
|
||
type UrlFilterCallback = for<'a> Fn(&str, &str, &'a str) -> Option<Cow<'a, str>> + Send + Sync + 'static; | ||
|
||
impl<'a> fmt::Debug for Builder<'a> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better idea: write a wrapper type around Box<UrlFilterCallback>
that implements Debug
itself, so that the main Builder
class can stick to the derived implementation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately that won't work due to orphan rules (it's an alias, not a real type).
src/lib.rs
Outdated
} | ||
let replace_with = if let Some(new) = filter_map(&*name.local, &*attr.name.local, &*attr.value) { | ||
if *new != *attr.value { | ||
Some(format_tendril!("{}", new)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tendril::from_str()
is faster.
src/lib.rs
Outdated
link_rel: Option<&'a str>, | ||
allowed_classes: HashMap<&'a str, HashSet<&'a str>>, | ||
strip_comments: bool, | ||
id_prefix: Option<&'a str>, | ||
} | ||
|
||
type UrlFilterCallback = for<'a> Fn(&str, &str, &'a str) -> Option<Cow<'a, str>> + Send + Sync + 'static; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use a trait, like RelativeUrlEvaluate
, so that our users can write their own structs to act as callbacks?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bors r+
That looks good to me!
97: Context-sensitive relative URL rewrite r=notriddle a=kornelski Similar to #96, but with a critical difference that this is a preprocessing step, before relative URLs are resolved. This allows different relative URLs for images than links. I've named it `url_filter_map`, after a similar iterator filter in std. I've opted for storing callback directly rather than via trait, but this required a custom `Debug`, since `derive` couldn't skip the callback. Co-authored-by: Kornel <kornel@geekhood.net>
Build succeeded |
Similar to #96, but with a critical difference that this is a preprocessing step, before relative URLs are resolved. This allows different relative URLs for images than links.
I've named it
url_filter_map
, after a similar iterator filter in std.I've opted for storing callback directly rather than via trait, but this required a custom
Debug
, sincederive
couldn't skip the callback.