Add into_urllink() translater helper
This commit is contained in:
parent
107e62a426
commit
12369ddadf
2 changed files with 23 additions and 1 deletions
|
@ -1,6 +1,7 @@
|
||||||
generate_error_module!(
|
generate_error_module!(
|
||||||
generate_error_types!(MarkdownError, MarkdownErrorKind,
|
generate_error_types!(MarkdownError, MarkdownErrorKind,
|
||||||
MarkdownRenderError => "Markdown render error"
|
MarkdownRenderError => "Markdown render error",
|
||||||
|
LinkParsingError => "Link parsing error"
|
||||||
);
|
);
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,12 @@
|
||||||
|
use error::MarkdownErrorKind as MEK;
|
||||||
use result::Result;
|
use result::Result;
|
||||||
|
|
||||||
use hoedown::renderer::Render;
|
use hoedown::renderer::Render;
|
||||||
use hoedown::Buffer;
|
use hoedown::Buffer;
|
||||||
use hoedown::Markdown;
|
use hoedown::Markdown;
|
||||||
|
use url::Url;
|
||||||
|
|
||||||
|
use libimagerror::into::IntoError;
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
pub struct Link {
|
pub struct Link {
|
||||||
|
@ -10,6 +14,23 @@ pub struct Link {
|
||||||
pub link: String,
|
pub link: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Link {
|
||||||
|
|
||||||
|
/// Translate a `Link` into a `UrlLink`
|
||||||
|
fn into_urllink(self) -> Result<UrlLink> {
|
||||||
|
Url::parse(&self.link[..])
|
||||||
|
.map(move |link| UrlLink { title: self.title, link: link, })
|
||||||
|
.map_err(Box::new)
|
||||||
|
.map_err(|e| MEK::LinkParsingError.into_error_with_cause(e))
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct UrlLink {
|
||||||
|
pub title: String,
|
||||||
|
pub link: Url,
|
||||||
|
}
|
||||||
|
|
||||||
struct LinkExtractor {
|
struct LinkExtractor {
|
||||||
links: Vec<Link>,
|
links: Vec<Link>,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue