Add into_urllink() translater helper

This commit is contained in:
Matthias Beyer 2016-05-29 11:48:37 +02:00
parent 107e62a426
commit 12369ddadf
2 changed files with 23 additions and 1 deletions

View file

@ -1,6 +1,7 @@
generate_error_module!(
generate_error_types!(MarkdownError, MarkdownErrorKind,
MarkdownRenderError => "Markdown render error"
MarkdownRenderError => "Markdown render error",
LinkParsingError => "Link parsing error"
);
);

View file

@ -1,8 +1,12 @@
use error::MarkdownErrorKind as MEK;
use result::Result;
use hoedown::renderer::Render;
use hoedown::Buffer;
use hoedown::Markdown;
use url::Url;
use libimagerror::into::IntoError;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Link {
@ -10,6 +14,23 @@ pub struct Link {
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 {
links: Vec<Link>,
}